Server-side analytics SDK for Clamp. Send tracked events from Python apps (Django, FastAPI, Flask, etc.).
Project description
clamp-analytics
Server-side analytics SDK for Clamp Analytics in Python.
Send tracked events from any Python server runtime to Clamp. Works with Django, FastAPI, Flask, Celery workers, scheduled jobs, and anything else that runs Python and can make outbound HTTPS calls.
Install
pip install clamp-analytics
Python 3.9+ supported.
Quick start
from clamp_analytics import init, track, Money
init(project_id="proj_xxx", api_key="sk_proj_xxx")
# Simple event
track("signup", properties={"plan": "pro", "method": "email"})
# Link a server event to a browser visitor (e.g. inside a Stripe webhook)
track(
"subscription_started",
anonymous_id="aid_xxx",
properties={"plan": "pro", "total": Money(29.00, "USD")},
)
Get a server API key at https://clamp.sh/dashboard (Settings → API Keys, format sk_proj_...). Set it as an environment variable; never commit it.
API
init(project_id, api_key, endpoint=None)
Initializes the SDK. Call once at process startup (e.g. in your Django settings.py, FastAPI lifespan, Flask app factory). Stores config in module-level state; subsequent track() calls use it.
endpoint is optional and overrides the default https://api.clamp.sh. Use this for self-hosted Clamp deployments or integration testing.
track(name, properties=None, anonymous_id=None, timestamp=None)
Sends a server event.
name: event name string. Examples:"signup","subscription_started","feature_used".properties: optional dict. Values may bestr,int,float,bool, orMoney. No nested dicts (other thanMoney) and no arrays.anonymous_id: optional string. Links the server event to a browser visitor. Read the browser's anonymous ID via the JS SDK'sgetAnonymousId()and pass it through your auth flow (e.g. Stripe'sclient_reference_id).timestamp: optional. Pass adatetime(timezone-aware preferred; naive datetimes are assumed UTC) or an ISO 8601 string. If omitted, the SDK uses the current UTC time.
Returns True on success. Raises ClampHTTPError on a non-2xx response or ClampNotInitializedError if init() wasn't called.
Money(amount, currency)
A typed monetary value. Use it for revenue, refunds, taxes; anywhere a currency-denominated amount belongs.
track("purchase", properties={
"plan": "pro",
"total": Money(29.00, "USD"),
"tax": Money(4.35, "USD"),
})
amount is in major units (29.00, not 2900). currency is an ISO 4217 code (uppercase, three letters).
Framework integrations
Per-framework integration patterns (Django middleware, FastAPI dependency, Flask after_request, Celery task hook) are documented at https://clamp.sh/docs/sdk/python.
Errors
The SDK is synchronous and raises on failure. There are no automatic retries. If you want fire-and-forget behavior, wrap the call yourself:
import logging
try:
track("subscription_started", properties={...})
except Exception:
logging.exception("failed to send to Clamp")
For high-throughput webhook handlers, consider sending events through a background task queue (Celery, RQ, Dramatiq).
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clamp_analytics-0.1.0.tar.gz.
File metadata
- Download URL: clamp_analytics-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
feac5bee33e4b216f035b02c42cf9cd84aee3c709f8f2b08401f4a7789552ba1
|
|
| MD5 |
3e0f0d3f0e854340145700d5940290ca
|
|
| BLAKE2b-256 |
049314644878e0db53c035cff55f36bf91adc0868a1eaaa08da4bef4c5730277
|
Provenance
The following attestation bundles were made for clamp_analytics-0.1.0.tar.gz:
Publisher:
sdk-python-release.yml on clamp-sh/clamp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clamp_analytics-0.1.0.tar.gz -
Subject digest:
feac5bee33e4b216f035b02c42cf9cd84aee3c709f8f2b08401f4a7789552ba1 - Sigstore transparency entry: 1409292233
- Sigstore integration time:
-
Permalink:
clamp-sh/clamp@ddbcd91d06802ce91bd73183f0c69beb03024c63 -
Branch / Tag:
refs/tags/sdk-python-v0.1.0 - Owner: https://github.com/clamp-sh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-release.yml@ddbcd91d06802ce91bd73183f0c69beb03024c63 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clamp_analytics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clamp_analytics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59da69ad95441d7d233446900e4836080c66b5bdf2ba2ab5ea6e30f4459c84c
|
|
| MD5 |
91f36b69f736d78ded0318fa9718d700
|
|
| BLAKE2b-256 |
b950d2a13c29e2870fa3d4582001a7e74b795bd6277f35a3756e554118cc5f5c
|
Provenance
The following attestation bundles were made for clamp_analytics-0.1.0-py3-none-any.whl:
Publisher:
sdk-python-release.yml on clamp-sh/clamp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clamp_analytics-0.1.0-py3-none-any.whl -
Subject digest:
f59da69ad95441d7d233446900e4836080c66b5bdf2ba2ab5ea6e30f4459c84c - Sigstore transparency entry: 1409292237
- Sigstore integration time:
-
Permalink:
clamp-sh/clamp@ddbcd91d06802ce91bd73183f0c69beb03024c63 -
Branch / Tag:
refs/tags/sdk-python-v0.1.0 - Owner: https://github.com/clamp-sh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-release.yml@ddbcd91d06802ce91bd73183f0c69beb03024c63 -
Trigger Event:
push
-
Statement type: