Python

Track events and identify users from a Python backend.

Use the Python SDK for backend events from Flask, FastAPI, Django, or workers. Like Node, it's stateless: pass the user's distinct_id on every call, or bind it once.

Install

pip install trodo-python

Python 3.8+.

Initialise once at boot

import os, trodo

trodo.init(
    site_id=os.environ['TRODO_SITE_ID'],
    auto_events=True,  # capture uncaught exceptions as server_error
)

Use the same site ID as your browser install.

Track, identify, people, groups

# Direct — distinct id first
trodo.track('user-42', 'invoice_paid', {'amount_cents': 9999})

# Bound — bind once, call many
user = trodo.for_user('user-42')
user.track('invoice_paid', {'amount_cents': 9999})
user.people.set({'plan': 'pro'})
user.set_group('company', 'acme')

Flush on exit

import atexit
atexit.register(trodo.shutdown)

Next

On this page