Skip to main content

alitycs-python

Official Alitycs analytics SDK for Python servers. Zero runtime dependencies — HTTP uses urllib.request from the standard library.

Install

pip install alitycs

Quickstart

from alitycs import Alitycs

client = Alitycs(api_key="pk_...")

client.track("checkout_completed", {"plan": "pro", "mrr": 49})
client.identify("user-123", {"email": "user@example.com"})
client.page("settings")

# Deliver everything queued before your process exits:
client.shutdown()

For a client shared by concurrent server requests, scope identity to each event instead of changing ambient state with identify():

client.track("checkout_started", user_id=request.user_id)
client.capture_error("checkout_failed", {"code": "E_CARD"}, user_id=request.user_id)

The same user_id keyword is accepted by track_revenue() and page() and does not change the identity used by any other call.

With batching enabled (the default), events are queued and dispatched on a daemon flusher thread, so track does not block on network I/O. With batching=False, each track call sends inline and can block up to the configured request/retry limits. Batches flush when flush_size (default 20) events are queued, every flush_interval seconds (default 2.0), or when you call flush() / shutdown() explicitly. shutdown() waits up to 30 seconds by default; pass join_timeout=None only when an unbounded drain is appropriate. On process exit a safety net drains live instances; SIGTERM and SIGINT also trigger a best-effort drain before the default termination disposition is restored (registered from the main thread only).

Configuration

Alitycs(
    api_key="pk_...",            # required
    endpoint="https://api.alitycs.com/events",
    flush_size=20,               # events per batch
    flush_interval=2.0,          # seconds; None disables the timer
    debug=False,
    max_queue_size=1000,
    max_retries=3,               # exponential backoff from retry_backoff_base
    session_timeout=1800.0,
    batching=True,               # False sends each event inline
    request_timeout=10.0,
    retry_backoff_base=1.0,
    persistence_path=None,       # optional exact in-flight batch WAL file
)

Delivery guarantees

  • Honest results: flush() returns True only when every event was delivered. Transient failures re-queue survivors at the head without persistence; with persistence_path, the exact serialized in-flight batch remains on disk for restart. Permanent refusals are dropped loudly.
  • No silent loss: delivery failures and local rejections are logged at warn level (never hidden behind debug) and counted — see pending, rejected_locally, plus delivered_total / requeued_total / lost_total on the batch manager.
  • Split-on-rejection: an HTTP 400 can mean one event poisoned a whole batch, so the SDK splits that response in half to isolate valid events, with a hard cap of 64 sends. Authentication, authorization, redirect, and other permanent responses are never split.
  • Retries reuse the exact batch body so batchId stays stable for server-side dedup.
  • SDK-generated exponential backoff is capped at 10 seconds. A server Retry-After replaces that generated delay and is capped at one hour to keep delivery bounded.
  • A new process using the same persistence_path replays retained bodies on flush() (or an unbounded shutdown) and honors any remaining persisted Retry-After deadline. If a finite shutdown deadline expires first, queued events are appended to the WAL in FIFO order. The WAL starts immediately before the first network attempt and is capped at max_queue_size retained events. Each path is exclusively owned by one live client; a same-process registry and a POSIX advisory lock reject overlapping owners. After a fork, the child drops its copy of the parent-owned queue and detaches from the inherited WAL; create a fresh client with a child-specific path when child delivery also needs durability.

Ingestion limits

Events violating these limits are rejected locally at build time — never queued, never sent, never truncated (they would cause the server to reject the whole batch):

Limit Value
Properties per event ≤ 50
Property key length ≤ 100 chars
Property value length ≤ 1000 chars
Estimated event size ≤ 64 KB
Required fields non-blank name AND (userId or anonymousId)
Timestamp epoch milliseconds, ≤ 7 days past, none future

Revenue payloads (trusted ingestion, requires a key with revenue:write) validate their per-kind fields strictly:

from alitycs import RevenuePayload

RevenuePayload.transaction(fact_id="inv-1", amount="19.99", currency="USD")
RevenuePayload.mrr_snapshot(
    fact_id="snap-1", subscription_id="sub-1",
    customer_id="cus-1", mrr_amount="250.00", currency="USD",
)
RevenuePayload.mrr_baseline_complete(fact_id="base-1", currency="USD", expected_active_subscriptions=120)

client.track_revenue(RevenuePayload.transaction(fact_id="inv-2", amount="9.99", currency="EUR"))

Development

pytest tests/unit        # unit tests, no network
scripts/e2e_run.py       # end-to-end against a local stack (Docker)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alitycs-1.0.0.tar.gz (93.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alitycs-1.0.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file alitycs-1.0.0.tar.gz.

File metadata

  • Download URL: alitycs-1.0.0.tar.gz
  • Upload date:
  • Size: 93.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alitycs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 44abcd0dea46261ba7981ad0ed6f81c0171c94cbbf587a8179a04250b4233abb
MD5 4aef6cf4b4b4066e2fcf257978d29fd2
BLAKE2b-256 8de440a009c3e2f3d62d6ea5969737e2286936e560dd7abde408d32ca0f195e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for alitycs-1.0.0.tar.gz:

Publisher: release.yml on alitycs/alitycs-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alitycs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: alitycs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alitycs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8cd8d98568a98c65c8275a1f39761fd979ef3031029ca056f662655db245d2
MD5 7e8f8577ab6e7da629177d1a2f040e20
BLAKE2b-256 19ea90001d4d522fc285db68a0ea1383fb23dba55a1539e7c0425f5b97623453

See more details on using hashes here.

Provenance

The following attestation bundles were made for alitycs-1.0.0-py3-none-any.whl:

Publisher: release.yml on alitycs/alitycs-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page