Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Piwik API for Python
Python Makefile
Tree: 10e445e784

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



This is a Python implementation of the Piwik tracking and analytics APIs.

Full Documentation at


At the moment only Django is supported out of the box. If you use a different framework/library you'll have to use a fake request class that mimics Django's. This is easy, but that requirement will be dropped in the future:

from piwikapi.tracking import PiwikTracker
from piwikapi.tests.request import FakeRequest

headers = {
    'HTTP_USER_AGENT': 'Fancy Browser 17.4',
    'REMOTE_ADDR': '',
    'HTTP_REFERER': '',
    'SERVER_NAME': '',
    'PATH_INFO': '/path/to/page/',
    'QUERY_STRING': 'something=bar',
    'HTTPS': False,
request = FakeRequest(headers)
piwiktracker = PiwikTracker(PIWIK_SITE_ID, request)
piwiktracker.set_ip(headers['REMOTE_ADDR']) # Optional, to override the IP
piwiktracker.set_token_auth(PIWIK_TOKEN_AUTH)  # Optional, to override the IP
piwiktracker.do_track_page_view('My Page Title')

As you can see the interface is very bad at the moment. This was partially inherited from the PHP reference implementation, and rewriting the interface is the next step for this project.

With Django you can skip the FakeRequest and simply pass Django's HttpRequest object to the API.


The API code itself isn't very nice, and if I find enough time I'll rewrite it entirely. It is my intention to continue supporting my old API interface for a while and to raise deprecation warnings when necessary.

The testing method will change with the 0.3 release. The previous way of using a setup class won't be supported any more. The project was also moved into the Piwik project on github, but this shouldn't affect you unless you were checking out the code from the old repository.


  • Normal tracking
  • Custom variables
  • Ecommerce
  • Goals
  • Actions

Not supported yet

  • Custom variables through cookies
  • Attribution info through cookies
  • probably more
Something went wrong with that request. Please try again.