Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Batch
✓ from mparticle import Batch
MParticle
✓ from mparticle import MParticle
Event
✓ from mparticle import Event
UserIdentities
✓ from mparticle.models import UserIdentities
✗ from mparticle import UserIdentities
UserIdentities is a model in the separate models module, not directly in mparticle top-level
Initialize mParticle client with API credentials and log a custom event.
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)
Debug
Known issues
deprecatedThe SDK uses v2 of the mParticle Events API, but some endpoints may be removed in future versions.fixWatch for API version updates in the official changelog.
affects: >=0.10.0,<0.17.0
breakingUserIdentities moved from top-level to mparticle.models in v0.11.0.fixImport from mparticle.models instead of mparticle.
affects: >=0.11.0
gotchaBatch uploads require setting the batch endpoint correctly; default config may not batch as expected.fixUse mp.upload() with a Batch object to send batched events.
affects: all
deprecatedPython 3.5 minimum since v0.13.0; Python 2.7 support dropped.affects: >=0.13.0
Errors
Common errors & fixes
AttributeError: module 'mparticle' has no attribute 'UserIdentities'
UserIdentities is in the models submodule, not top-level.
fixUse 'from mparticle.models import UserIdentities' instead.
mparticle.exceptions.MParticleError: 401 Unauthorized
Invalid API key or secret.
fixVerify your mParticle API credentials and ensure environment variables are set correctly.
TypeError: log_event() missing 1 required positional argument: 'event'
Passing event object as keyword argument incorrectly.
fixCall 'mp.log_event(event)' with the event as a positional argument.
Upgrade
Version history
0.16.1latest on PyPI · released Jun 20, 2023
Audit
Dependencies
requestsrequiredHTTP client for API calls
sixrequiredPython 2/3 compatibility
python-dateutilrequiredDate/time parsing