Python
The OpenPanel Python SDK allows you to track user behavior in your Python applications. This guide provides instructions for installing and using the Python SDK in your project.
Installation
Install dependencies
Initialize
Import and initialize the OpenPanel SDK with your credentials:
Configuration Options
Common options
apiUrl
- The url of the openpanel API or your self-hosted instanceclientId
- The client id of your applicationclientSecret
- The client secret of your application (only required for server-side events)filter
- A function that will be called before sending an event. If it returns false, the event will not be sentdisabled
- If true, the library will not send any eventswaitForProfile
- If true, the library will wait for the profile to be set before sending events
Additional Python-specific options:
filter
- A function that will be called before tracking an event. If it returns false the event will not be trackeddisabled
- Set toTrue
to disable all event trackingglobal_properties
- Dictionary of properties that will be sent with every event
Filter Function Example
Usage
Tracking Events
To track an event, use the track
method:
Identifying Users
To identify a user, use the identify
method:
Setting Global Properties
To set properties that will be sent with every event:
Creating Aliases
To create an alias for a user:
Incrementing Properties
To increment a numeric property on a user profile:
Decrementing Properties
To decrement a numeric property on a user profile:
Clearing User Data
To clear the current user's data:
Advanced Usage
Thread Safety
The OpenPanel SDK is thread-safe. You can safely use a single instance across multiple threads in your application.
Error Handling
The SDK includes built-in error handling and will not raise exceptions during normal operation. However, you can wrap SDK calls in try-except blocks for additional safety:
Disabling Tracking
You can temporarily disable all tracking: