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

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:

 u'rounding_minutes': 0,
 u'premium': False,
 u'name': u"my workspace",
 u'admin': True,
 u'rounding': 1,
 u'at': u'2014-01-07T14:38:34+00:00',
 u'default_hourly_rate': 40,
 u'only_admins_see_team_dashboard': False,
 u'only_admins_see_billable_rates': False,
 u'projects_billable_by_default': True,
 u'logo_url': u'',
 u'only_admins_may_create_projects': False,
 u'id': 123456,
 u'default_currency': u'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:


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!


3 thoughts on “How to build a pretty Excel timesheet using Toggl API and Python

  1. Hi I am getting blank excel file,, I am using your script and just edited user token and workspace ID.

    Please help….!

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s