Python Piwik

Easy integrate  Piwik in your python project. Latest release: 0.5.

Source

 Source available on GitHub.

git clone git://github.com/francois2metz/Python-piwik.git

Install

Using  PyPi

pip install piwik

API

Basic usage:

from piwik import PiwikAPI

piwik = PiwikAPI("http://piwik.org/demo/", "anonymous")
print piwik.getAllSites()

Django extension

Python piwik also contain an django application that can be easily integrated on your Django project.

Add piwik.django to your installed apps settings, add middleware piwik.django.middleware.PiwikMiddleware, and add PIWIK_URL and PIWIK_TOKEN.

  • PIWIK_URL is Url of you Piwik installation with / at end
  • PIWIK_TOKEN found token on your piwik installation -> API -> token_auth also available Settings -> Users
INSTALLED_APPS = (
    ...,
    'django.contrib.sites', # piwik django dependency
    'piwik.django',
    ...,
)
MIDDLEWARE_CLASSES = (
    ...,
    'piwik.django.middleware.PiwikMiddleware',
    ...,
)
PIWIK_TOKEN = 'your token'
PIWIK_URL = 'http://piwik.example.org/'

Go to your admin site and rely piwik sites with django site.

For add piwik tag on you website, simply use RequestContext.

def index(request):
    return render_to_response("index.html", RequestContext(request, {}))

Add this in your template:

{% autoescape off %}
{{ piwik_tag }}
{% endautoescape %} 

Screenshots

Screenshot : all sites

Contribute

License

Python piwik is released under BSD License.

Attachments