SDKs overview
WakaTime provides Software Development Kits (SDKs) and libraries designed to facilitate interaction with its API, which records and reports coding activity. These tools enable developers to integrate WakaTime's time-tracking capabilities into various applications, analyze data programmatically, and build custom dashboards or reports. The primary function of WakaTime's system is to automatically track time spent coding in Integrated Development Environments (IDEs) by using plugins that send data to the WakaTime API WakaTime developer API documentation. The SDKs and libraries extend this functionality, offering structured methods to access and manipulate the collected data.
The WakaTime API is RESTful, allowing for data retrieval related to coding activity, summaries, and user statistics. Developers can use the SDKs to query these endpoints for raw data, processed metrics, and aggregated insights into coding habits. This enables use cases such as personalized productivity analysis, team performance monitoring, and integration with other developer tools or project management systems. The official SDKs support several popular programming languages, providing a standardized interface for common API operations. Community-contributed libraries further expand this ecosystem, offering support for additional languages or specialized integrations.
Official SDKs by language
WakaTime maintains official SDKs for several programming languages, providing tested and supported interfaces for interacting with its API. These SDKs are designed to simplify the process of sending and retrieving coding activity data, abstracting away the complexities of HTTP requests and JSON parsing. Each SDK typically includes functions for authenticating with the API, fetching various data types (e.g., daily summaries, project-specific metrics, language usage), and managing API responses. The table below lists the officially supported SDKs and their common installation methods.
| Language | Package/Repository | Install Command (Example) | Maturity |
|---|---|---|---|
| Python | wakatime |
pip install wakatime |
Stable |
| Go | github.com/wakatime/wakatime-cli |
go get github.com/wakatime/wakatime-cli |
Stable |
| Node.js | wakatime (npm) |
npm install wakatime |
Stable |
| .NET | WakaTime.Shared (NuGet) |
dotnet add package WakaTime.Shared |
Stable |
| Java | wakatime-cli (Maven/Gradle) |
(See documentation for build tool specifics) | Stable |
| PHP | wakatime/php-wakatime |
composer require wakatime/php-wakatime |
Stable |
| Ruby | wakatime (RubyGems) |
gem install wakatime |
Stable |
These SDKs are maintained by the WakaTime team and are the recommended approach for integrating with the WakaTime platform within their respective language ecosystems. They often include utilities for handling API keys, pagination, and error handling, streamlining the development process WakaTime help documentation.
Installation
Installation of WakaTime SDKs typically follows the standard package management practices of each programming language. The process involves using a command-line tool to fetch and install the library from a public repository. After installation, the SDK can be imported into a project and configured with an API key.
Python
pip install wakatime
This command installs the official Python WakaTime library, which can then be imported into Python scripts to interact with the API.
Go
go get github.com/wakatime/wakatime-cli
For Go projects, the go get command fetches the WakaTime CLI, which can also be used as a library within Go applications. This provides the core logic for sending data to WakaTime.
Node.js
npm install wakatime
The Node.js SDK is available via npm. Installing it enables JavaScript and TypeScript projects to utilize WakaTime's API functionalities.
.NET
dotnet add package WakaTime.Shared
For .NET applications, the SDK can be added as a NuGet package using the dotnet add package command. This integrates the necessary assemblies into the project.
Java
For Java, the WakaTime CLI can be used, or developers can integrate directly with the API. While a dedicated Java SDK is not explicitly listed as a standalone package, the Java ecosystem often leverages the CLI through process execution or direct API calls. Refer to the WakaTime API documentation for Java integration best practices.
PHP
composer require wakatime/php-wakatime
PHP developers can install the WakaTime library using Composer, the dependency manager for PHP. This command adds the WakaTime package to a PHP project.
Ruby
gem install wakatime
The RubyGems package manager is used to install the WakaTime gem for Ruby projects. Once installed, the gem provides an interface for Ruby applications to interact with the WakaTime API.
After installation, an API key is required to authenticate requests. This key can be found in the user's WakaTime account settings.
Quickstart example
This Python example demonstrates how to retrieve a user's coding activity summary for the last 7 days using the WakaTime API. It utilizes the requests library for making HTTP calls, which is a common pattern when an official SDK in a specific language might be less direct for certain API actions or when direct HTTP interaction is preferred. For a more complete interaction, the official Python SDK would be used.
import requests
import os
# Replace with your actual WakaTime API Key from https://wakatime.com/settings/api-key
API_KEY = os.getenv("WAKATIME_API_KEY", "YOUR_WAKATIME_API_KEY")
def get_last_7_days_summary(api_key):
url = "https://wakatime.com/api/v1/users/current/summaries"
headers = {
"Authorization": f"Basic {api_key}"
}
params = {
"start": "last_7_days", # This parameter is not officially supported for 'summaries' endpoint directly
# For actual date ranges, use 'start_date' and 'end_date' parameters
# However, for a quick demo, we'll illustrate a common intention.
}
# For a real-world scenario, you would calculate specific start and end dates
# For example:
from datetime import date, timedelta
today = date.today()
seven_days_ago = today - timedelta(days=7)
real_params = {
"start_date": seven_days_ago.isoformat(),
"end_date": today.isoformat()
}
try:
response = requests.get(url, headers=headers, params=real_params)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
data = response.json()
return data
except requests.exceptions.HTTPError as errh:
print (f"Http Error: {errh}")
except requests.exceptions.ConnectionError as errc:
print (f"Error Connecting: {errc}")
except requests.exceptions.Timeout as errt:
print (f"Timeout Error: {errt}")
except requests.exceptions.RequestException as err:
print (f"Something Else: {err}")
return None
if __name__ == "__main__":
if API_KEY == "YOUR_WAKATIME_API_KEY":
print("Please replace 'YOUR_WAKATIME_API_KEY' with your actual WakaTime API Key or set the WAKATIME_API_KEY environment variable.")
else:
summary_data = get_last_7_days_summary(API_KEY)
if summary_data:
print("WakaTime Summary for the last 7 days:")
for day in summary_data.get("data", []):
print(f" Date: {day.get('range', {}).get('date')}")
for language in day.get('languages', [])[:3]: # Show top 3 languages
print(f" - {language.get('name')}: {language.get('text')}")
print("\n")
else:
print("Failed to retrieve WakaTime summary.")
This example initializes a request to the /users/current/summaries endpoint using an API key for authentication. It then parses the JSON response to display coding activity by language for the specified period. Developers should replace the placeholder YOUR_WAKATIME_API_KEY with their actual API key, which can be base64 encoded for the Basic authentication header as required by WakaTime's API WakaTime API authentication details. For more advanced interactions, including sending data from custom editors or tools, consult the WakaTime plugin development guide.
Community libraries
Beyond the official SDKs, the WakaTime ecosystem benefits from various community-contributed libraries and integrations. These projects often extend WakaTime's reach to additional programming languages, frameworks, or niche development environments not directly supported by official offerings. Community libraries can range from simple API wrappers to full-fledged plugins for less common IDEs or text editors. While not officially maintained by WakaTime, these contributions demonstrate the flexibility of the API and the active developer community.
Examples of community contributions might include:
- Editor Plugins: Integrations for editors such as Sublime Text, Vim, Emacs, or custom build systems that send coding activity data to WakaTime. Many official plugins are open source and serve as a reference for community development WakaTime GitHub organization.
- Language-specific API Clients: Libraries in languages like Rust, Swift, or TypeScript that provide type-safe or idiomatic ways to interact with the WakaTime API.
- Reporting Tools: Scripts or applications that pull data from WakaTime and generate custom reports, visualizations, or integrate with other productivity dashboards. For instance, a common pattern involves using an API to fetch data and then visualizing it with tools like D3.js or other charting libraries, as described in general API data visualization practices Google Charts developer documentation.
- CLI Utilities: Command-line tools that offer quick access to WakaTime statistics without requiring a full IDE integration.
When considering community libraries, developers should evaluate their active maintenance, documentation quality, and community support. The WakaTime community forums and GitHub repositories are often good starting points for discovering and assessing these unofficial tools.