How to build a pretty Excel timesheet using Toggl API and Python

Thu 13 March 2014

Since some months I’m using Toggl to track my work time, and I find it awesome! Toggl features a very powerful reporting system to have your timesheets filtered in many ways and exported in csv or pdf format, but I did not found the way to have an Excel timesheet as I like it.

But wait! Toggl features a very nice public API to access your time entries (and many more), so I wrote a simple Python script using the wonderful Requests and Xlsxwriter libraries.

First of all you need your Toggl API token, you can find it in your Toggl profile. Then you need your workspace id of interest. You can use a script like this to obtain it:

import requests

_api_token = 'api_token_taken_from_your_toggl_profile'

r = requests.get('',
                 auth=(_api_token, 'api_token'))
print r.json()

This will print something like this:

 'rounding_minutes': 0,
 'premium': False,
 'name': 'my workspace',
 'admin': True,
 'rounding': 1,
 'at': '2014-01-07T14:38:34+00:00',
 'default_hourly_rate': 40,
 'only_admins_see_team_dashboard': False,
 'only_admins_see_billable_rates': False,
 'projects_billable_by_default': True,
 'logo_url': '',
 'only_admins_may_create_projects': False,
 'id': 123456,
 'default_currency': 'EUR'

In my case I’ve just one workspace, but you can have many. Your workspace id (surprisingly) is in the ‘id’ property of the JSON object, 123456 in this example.

Now that you have your API token and your workspace id, here is the script:

You can call it like this:

./ Google 2014-03-01 2014-03-31

Where Google is the name of the client you want to produce the timesheet for (you work for Google as a freelance, don’t you?) and the other parameters are the date range you want to extract times from. This will produce a nice Excel timesheet named Google_2014-03-01_2014-03-31.xlsx in the current directory, with a content similar to this:

A timesheet example
A timesheet example

In bold you have your projects with the total time spent on the project, then you have all time entries related to the project. Enjoy!