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.
You can install the OpenPanel Python SDK using pip:
pip install openpanel
First, import the SDK and initialize it with your client ID:
from openpanel import OpenPanel
op = OpenPanel(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
When initializing the SDK, you can provide several options:
client_id
(required): Your OpenPanel client ID.client_secret
(optional): Your OpenPanel client secret.api_url
(optional): Custom API URL if you're not using the default OpenPanel API.filter
(optional): A function to filter events before sending.disabled
(optional): Set toTrue
to disable event sending.
To track an event:
op.track("button_clicked", {"button_id": "submit_form"})
To identify a user:
op.identify("user123", {
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"customAttribute": "value"
})
To set properties that will be sent with every event:
op.set_global_properties({
"app_version": "1.0.2",
"environment": "production"
})
To create an alias for a user:
op.alias("user123", "john_doe")
To increment a numeric property on a user profile:
op.increment("user123", "login_count", 1)
To decrement a numeric property on a user profile:
op.decrement("user123", "credits", 5)
To clear the current user's data:
op.clear()
You can set up custom event filtering:
def my_filter(payload):
# Your custom filtering logic here
return True # or False to filter out the event
op = OpenPanel(client_id="YOUR_CLIENT_ID", filter=my_filter)
You can temporarily disable tracking:
op = OpenPanel(client_id="YOUR_CLIENT_ID", disabled=True)
The OpenPanel SDK is designed to be thread-safe. You can call its methods from any thread without additional synchronization.
For any issues or feature requests, please file an issue on our GitHub repository.