This is the official Mixpanel Python library. This library allows for server-side integration of Mixpanel.
To import, export, transform, or delete your Mixpanel data, please see our mixpanel-utils package.
The library can be installed using pip:
pip install mixpanel
Typical usage usually looks like this:
from mixpanel import Mixpanel
mp = Mixpanel(YOUR_TOKEN)
# tracks an event with certain properties
mp.track(DISTINCT_ID, 'button clicked', {'color' : 'blue', 'size': 'large'})
# sends an update to a user profile
mp.people_set(DISTINCT_ID, {'$first_name' : 'Ilya', 'favorite pizza': 'margherita'})
You can use an instance of the Mixpanel class for sending all of your events and people updates.
- Help Docs
- Full Documentation
- mixpanel-python-async; a third party tool for sending data asynchronously from the tracking python process.
For endpoints that require authentication (like import_data and merge), you have two options:
Legacy API Secret: Use your project's API secret as a string.:
mp.import_data(API_KEY, DISTINCT_ID, EVENT, TIMESTAMP, api_secret='your_api_secret')
Service Account: Use your service account credentials as a tuple of (username, password). This is the recommended method:
mp.import_data(API_KEY, DISTINCT_ID, EVENT, TIMESTAMP, api_secret=('username', 'password'))
Note that the API key parameter is deprecated and will be removed in a future release.