About five minutes, on the free plan, without a credit card.
1
Install the package
The SDK is published on PyPI under the name openpanel. It requires Python 3.7 or newer and pulls in requests as its only dependency.
pip install openpanel
2
Create the client
Always pass api_url. It is an optional argument that defaults to OpenPanel's own host, so if you leave it out your events go to the wrong place. client_secret is needed for server-side events. The optional disabled flag is handy for local development.
import os
from openpanel import OpenPanel
op = OpenPanel(
client_id="YOUR_CLIENT_ID",
client_secret=os.environ["PRIVYTICS_CLIENT_SECRET"],
api_url="https://api.privytics.com",
disabled=os.getenv("ENV") == "development",
)
3
Track an event
track() takes an event name and an optional dictionary of properties. Properties are merged with anything you have set through set_global_properties(). Delivery failures are logged to stdout rather than raised, so a tracking outage will never break a request.
op.set_global_properties({
"app_version": "1.4.0",
"environment": "production",
})
op.track("signup_completed")
op.track("purchase_completed", {
"plan": "pro",
"price": 99.99,
"currency": "EUR",
})
4
Attach events to a user in Django or Flask
identify() sends profile traits and also stores the profile id on the client instance, where every later track() call picks it up. That state is shared across threads, so in a web server one request's identify() can attribute another request's events. Call identify() deliberately, or keep a client per worker. increment() and decrement() take positional arguments and are unaffected, since you pass the profile id explicitly.
from flask import Flask, jsonify
app = Flask(__name__)
@app.post("/checkout")
def checkout():
user = get_current_user()
op.identify(str(user.id), {
"email": user.email,
"firstName": user.first_name,
})
op.track("checkout_started", {"cart_value": 49.0})
op.increment(str(user.id), "checkout_count", 1)
return jsonify(ok=True)