Welcome to wakapy¶
Welcome to the wakapy documentation, a Python 3.6+ library that facilitates your WakaTime data processing by bundling the data into a convenient OOP scheme.
Documentation Contents¶
Introduction¶
wakapy is a python library aiming for Python 3.6+ versions whose purpose is to provide easy Wakatime data manipulation to the developer.
Note
Wakapy basically loads the big json file containing all of your data provided for free by WakaTime and group every piece of data in convenient classes. The Wakatime json file is big, a 161 days file, where only 121 days actually contain relevant data is roughly 75k long (in my case).
Wakapy features:¶
1. Extensive data class containerization (Every bit of data from the json file is accessible with the library).
2. Extra functionalities added to ease the data manipulation.
3. Date slicing, in other words, you can get the data from a chosen range, similar to the Wakatime paid features
4. Some nice charts out of the box for the people who just want to get a quick insight of the data without putting too much effort on it
Installation and Set up¶
Downloading the library:¶
Using bare git:
$ git clone https://github.com/surister/wakapy.git
Using pip:
$ pip install wakapy
Using pipenv:
$ pipenv install wakapy
Downloading the Wakatime data:¶
- Log in Wakatime
- Settings
- Export my coding activities
Note
Keep the data in the original JSON format.
Basic examples¶
Example 1: Basic charting usage¶
from wakapy import User
user = User('/home/surister/data.json')
chart = user.pie_chart('lan')
# lan = languages. See the different options
# in Day.raw_containers
chart.show()
# Shows the chart.
chart.save('/home/surister/mychart.png')
# Saves the chart to the desired filepath.
output:

Example 2: Date slices in chart¶
from datetime import date
from wakapy import User
date1 = '2018-10-10'
date2 = date(year=2018, month=10, day=17)
# Dates can either be a str or a datetime.date object.
a = User('/home/surister/info.json')
a_slice = a.get_slice(date1, date2)
# Returns a Slice object containing
# the Days object between the two given dates
chart = a.pie_chart('proj', num=3, sliced=True)
# Num is the number of projets that will be displayed
# Sliced is set to True, so the chart will be created with
# sliced object created before.
chart.save('/home/surister/mychart.png')
output:

Example 3: Creating your own chart¶
from datetime import date
from wakapy import User
import matplotlib.pyplot as plt
import numpy as np
date1 = date(year=2019, month=1, day=10)
date2 = date(year=2019, month=1, day=20)
user = User('/home/surister/info.json')
user_slice = user.get_slice(date1, date2)
data = user.fetch_data('lan', True)
# You could use the fetch_data function
# or iterate yourself:
data2 = {}
for day in user_slice:
if not day.is_empty:
for container in day.container_dict['lan']:
if container.name not in data2.keys():
data2[container.name] = container.total_time
else:
data2[container.name] += container.total_time
# In this case the same data1 and data2 have the same values.
# Note that fetch_data returns an ordered dict
# while data2 would not be ordered.
fig, ax = plt.subplots()
keys = data.keys()
y_pos = np.arange(len(keys))
hours = list(map(lambda x: round(x / 3600, 2), data.values()))
# We convert the seconds into hours
ax.barh(y_pos, hours, align='center',
color='blue')
ax.set_yticks(y_pos)
ax.set_yticklabels(keys)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel(f'Time (h)')
ax.set_title(f'Languages by {user.username} between {date1}|{date2}')
plt.show()
output:

Note
These examples and images can also be found in the examples folder
Api reference¶
Note
- The data containers are divided in two sections:
- Containers: They contain data and have some functionalities and processing properties.
- Containers-bare: They do not have any special functionality other than being datacontainers.
Containers¶
Main classes, data containers with functionalities. |
JsonDict¶
User¶
-
class
wakapy.
User
(fp: str)¶ Represents a user containing all the data from source file
Parameters: fp ( str
) – The file path to the Wakatime json filebool
- True if user has premium features.
-
fetch_data
(to_fetch: str, sliced: bool) → dict¶ Parameters: Returns: dict
containing the data.Note
The fetched data is the total_time of each
Day
container.(s).This is an example of it:
# 'lan' - language data = {'python': 253, 'bash': 623}
-
get_slice
(date1=None, date2=None) → wakapy.user.Slice¶ Dates: Default NoneType
, can be eitherstr
with the following format: YYYY-MM-DD or adatetime.date
objectReturns: Slice
-
pie_chart
(to_fetch: str, num: int = 10, sliced=False) → wakapy.plot.PieChart¶ Creates a pie chart with the given parameters.
Parameters: Returns:
Day¶
-
class
wakapy.day.
Day
(_dict: dict)¶ Represents a day. It contains all the data regarding a specific day. Every date is unique.
Parameters: _dict ( dict
) – A dictionary containing all the data within a one day range.-
container_dict
¶ dict
shortcut reference to the class containers.- os: operative_systems
- lan: languages
- ent: entities
- edit: editors
- cat: categories
- proj: projects
-
operative_systems
¶ List[
Os
] List containing every Os object, representing every s that was used this date.
-
languages
¶ List[
Language
] List containing every Language object, representing every programming language that was used this date.
-
entities
¶ List[
Dependency
] List containing every Dependency object, representing every dependency that was used this date.
-
editors
¶ List[
Editor
] List containing every Editor object, representing every editor that was used this date.
-
categories
¶ List[
Category
] List containing every Category object, representing every category that was used this date.
-
Slice¶
-
class
wakapy.user.
Slice
(days, date_1=None, date_2=None)¶ Given two valid dates it’ll slice and save them. It always includes the given dates.
Parameters: - days (List[
Day
]) – The list of Day objects to slice by dates. - dates (Union[
str
,datetime.date
]) – date_1 has to be lower than date_2 and both have to follow the YYYY-MM-DD format.
Note
str given dates will be converted to
datetime.date
, so both dates can be given in any of those 2 formats independently. The slicing will be done automatically upon creating the class with two valid dates. This class can be iterated, yieldsDay
fromdays()
So this twos are equivalent:
myslice = Slice(dates_list, date1, date2) for day in myslice: print(day.date) for day in myslice.days: print(day.date)
-
date_1 see dates.
-
date_2 see dates.
- days (List[
Containers-bare¶
The following classes are the static data containers
Parent¶
Project¶
-
class
wakapy.containers.
Project
(_dict)¶ Represents a Project. It contains every container-bare plus three more.
This class adds overall more accuracy in the timings within a
Day
Parameters: _dict ( dict
) – Dictionary that contains all the data.-
operative_systems
¶ List[
Os
] list containing every Os object, representing every s that was used this date.
-
languages
¶ List[
Language
] list containing every Language object, representing every programming language that was used this date.
-
entities
¶ List[
Dependency
] list containing every Dependency object, representing every dependency that was used this date.
-
editors
¶ List[
Editor
] list containing every Editor object, representing every editor that was used this date.
-
categories
¶ List[
Category
] list containing every Category object, representing every category that was used this date.
-
dependencies
¶ List[
Dependency
] list containing every Dependency object, representing every dependency that was used this date.
-
Child Containers¶
The following classes are all child’s of Parent
-
class
wakapy.containers.
Os
(_dict)¶ Class representing a wakatime Operative System data within a one day range.
-
class
wakapy.containers.
Language
(_dict)¶ Class representing a wakatime Programming language data within a one day range.
-
class
wakapy.containers.
Entity
(_dict)¶ Class representing a wakatime Entity data within a one day range. A entity can be a module, dependency.. it may vary from plugin to plugin. It’s only present in
Project
-
class
wakapy.containers.
Dependency
(_dict)¶ Class representing a wakatime Entity data within a one day range. A entity can be a module, dependency.. it may vary from plugin to plugin.
-
class
wakapy.containers.
Category
(_dict)¶ Class representing a wakatime Category data within a one day range, usually ‘Coding’
-
class
wakapy.containers.
Editor
(_dict)¶ Class representing a wakatime Editor data within a one day range, it does not distinguish between editors and IDEs
Extra¶
PieChart¶
-
class
wakapy.plot.
PieChart
(_dict, num: int, dates=None)¶ Matplotlib pie chart that comes with the library for the people that just want a quick insight of their data.
Parameters: - _dict (
dict
) – The dictionary containing all the data that will be showed in the piechart. - num (
int
) – Number of max elements that will be shown in the chart - dates (
datetime.date
) – The dates if the data comes from a slice. Just for tagging purposes.
Note
You are suppose to access this by
pie_chart()
-
save
(fp: str) → None¶ Saves the figure in the given path.
matplotlib.pyplot.save(fp)
Parameters: fp – str
-
show
() → None¶ Shows the figure.
matplotlib.pyplot.show
- _dict (