TopStats SDK
Python analytics SDK
A dependency-free client for Python 3.10+. capture() enqueues and returns immediately; a background thread batches and sends. FastAPI, Starlette, Flask and Django have ready-made middleware in the topstats-web package built on this SDK.
Install
pip install git+https://github.com/top-stats/analytics-python-sdk # PyPI soonCapture your first event
from topstats_analytics import TopStats
client = TopStats(os.environ["TOPSTATS_API_KEY"])
client.capture("job_finished", {"rows": 1200}, actor="worker-7")
client.shutdown() # flushes the tailBehaviour you can rely on
- Capture never throws into your code and never blocks on the network - a bounded queue buffers and a background loop batches.
- Retries only 429, 5xx and network failures, with jittered backoff honouring Retry-After; your API key never appears in error output.
- Never raises from capture: validation problems, full queues and failed sends surface through on_error.
- Blank TOPSTATS_HOST is treated as unset; the API key never appears in error text.