mParticle Python SDK
raw JSON → 0.16.1 verified Sat May 09 auth: no python
Python client for the mParticle customer data platform. Currently version 0.16.1. SDK supports event tracking, user management, and consent state. Maintenance cadence is irregular with occasional feature releases.
pip install mparticle Common errors
error AttributeError: module 'mparticle' has no attribute 'UserIdentities' ↓
cause UserIdentities is in the models submodule, not top-level.
fix
Use 'from mparticle.models import UserIdentities' instead.
error mparticle.exceptions.MParticleError: 401 Unauthorized ↓
cause Invalid API key or secret.
fix
Verify your mParticle API credentials and ensure environment variables are set correctly.
error TypeError: log_event() missing 1 required positional argument: 'event' ↓
cause Passing event object as keyword argument incorrectly.
fix
Call 'mp.log_event(event)' with the event as a positional argument.
Warnings
deprecated The SDK uses v2 of the mParticle Events API, but some endpoints may be removed in future versions. ↓
fix Watch for API version updates in the official changelog.
breaking UserIdentities moved from top-level to mparticle.models in v0.11.0. ↓
fix Import from mparticle.models instead of mparticle.
gotcha Batch uploads require setting the batch endpoint correctly; default config may not batch as expected. ↓
fix Use mp.upload() with a Batch object to send batched events.
deprecated Python 3.5 minimum since v0.13.0; Python 2.7 support dropped. ↓
fix Use Python 3.5+.
Imports
- Batch
from mparticle import Batch - MParticle
from mparticle import MParticle - Event
from mparticle import Event - UserIdentities wrong
from mparticle import UserIdentitiescorrectfrom mparticle.models import UserIdentities
Quickstart
from mparticle import MParticle
from mparticle import Event
from mparticle.models import UserIdentities
api_key = os.environ.get('MPARTICLE_API_KEY', '')
api_secret = os.environ.get('MPARTICLE_API_SECRET', '')
mp = MParticle(api_key, api_secret)
# Track a simple event
event = Event('Test Event', 'navigation')
mp.log_event(event)
# Track with user identity
user_ids = UserIdentities(customer_id='user123')
mp.log_event(event, user_identities=user_ids)