The Python interface to fetch data from Mixpanel.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
mixpanel_query Bump version to 0.1.9 auth improvement Apr 3, 2017
.gitignore Initial commit. Core functionality to make queries against MixPanel's… Aug 3, 2014
CHANGES
LICENSE Create License Aug 31, 2016
MANIFEST.in Initial commit. Core functionality to make queries against MixPanel's… Aug 3, 2014
README.md Bump version to 0.1.9 auth improvement Apr 3, 2017
__init__.py Initial commit. Core functionality to make queries against MixPanel's… Aug 3, 2014
setup.py Bumps version to `0.1.6` => Python 2, 3 support Jun 22, 2015

README.md

mixpanel-query-py

The Python interface to fetch data from Mixpanel via Mixpanel's Data Query API. Note, this differs from the official Python binding which only provides an interface to send data to Mixpanel.

Installation

To install mixpanel-query-py, simply:

$ pip install mixpanel-query-py

or alternatively (you really should be using pip though):

$ easy_install mixpanel-query-py

or from source:

$ git clone git@github.com:cooncesean/mixpanel-query-py.git
$ cd mixpanel-query-py
$ python setup.py install

Usage

You will need a Mixpanel account and your API_KEY + API_SECRET to access your project's data via their API; which can be found in "Account" > "Projects".

from mixpanel_query.client import MixpanelQueryClient
from your_project.conf import MIXPANEL_API_KEY, MIXPANEL_API_SECRET

# Instantiate the client
query_client = MixpanelQueryClient(MIXPANEL_API_KEY, MIXPANEL_API_SECRET)

# Query your project's data
data = query_client.get_events_unique(['Some Event Name'], 'hour', 24)
print data
{
    'data': {
        'series': ['2010-05-29', '2010-05-30', '2010-05-31'],
        'values': {
            'account-page': {'2010-05-30': 1},
            'splash features': {
                '2010-05-29': 6,
                '2010-05-30': 4,
                '2010-05-31': 5,  # Date + unique event counts
            }
        }
    },
    'legend_size': 2
}

Authentication

By default the MixpanelQueryClient will use signature-based authentication when issuing requests to Mixpanel. If you would like to use the secret-based authentication method, you can do so like this:

from mixpanel_query.client import MixpanelQueryClient
from mixpanel_query.auth import SecretAuth, SignatureAuth
from your_project.conf import MIXPANEL_API_KEY, MIXPANEL_API_SECRET

# Instantiate a secret-based auth client
secret_auth_client = MixpanelQueryClient(MIXPANEL_API_KEY, MIXPANEL_API_SECRET, auth_class=SecretAuth)

# Instantiate a signature-based auth client explicitly
sig_auth_client = MixpanelQueryClient(MIXPANEL_API_KEY, MIXPANEL_API_SECRET, auth_class=SignatureAuth)

View the api reference for details on accessing different endpoints.

API Reference

Mixpanels' full API reference is documented here.

Python Support

This library now supports both by Python >2.7.6 as well as <Python 3.4.3 with recent additions added by @robin900.