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).
capture_error(exception, context=None, anonymous_id=None, timestamp=None)
Sends an exception as a $error event. Convenience over track() that extracts message, type, and stack from the exception. The server adds a stable fingerprint at ingest so the same bug groups across occurrences.
from clamp_analytics import capture_error
try:
process_webhook(payload)
except Exception as e:
capture_error(e, context={"webhook": "stripe"})
exception: any exception instance. Stack trace is captured viatraceback.format_exception.context: optional flat mapping of additional properties. Values must be primitives (str,int,float,bool); the reserved keyhandledis ignored.anonymous_id: optional. Links the error to a browser visitor via the same anonymous ID flow astrack.timestamp: optionaldatetimeor ISO 8601 string.
Same return value and exceptions as track(). Lengths are capped (error.message 1KB, error.type 64 chars, error.stack 16KB) to match server-side limits.
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
Metadata
Release files for clamp-analytics 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| clamp_analytics-0.2.0.tar.gz | 7.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clamp_analytics-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / clamp_analytics-0.2.0.tar.gz
| Download URL | clamp_analytics-0.2.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65f4b194bb4b78afbb3afcb7cfeb25f4175b760dba54c6734594d26fe576a5d7
|
|
BLAKE2b-256 checksum How to use checksums |
9214bd205a0f5f1e58978fcbb8a793db60742e84ef98b77d88755e04746b9335
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency logRelease files / clamp_analytics-0.2.0-py3-none-any.whl
| Download URL | clamp_analytics-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fefa9fd2768cc8bed140937f326dcd211682d7e3a01eb401aa0ce6c61649ab9
|
|
BLAKE2b-256 checksum How to use checksums |
e7ebb40b9c8419b5557b9fd5289a2c8709ac091db4cc704238f33fc2b56c429e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency logSecurity for clamp-analytics 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for clamp_analytics-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.