Truxl Analytics Python SDK — lightweight, zero-dependency server-side event tracking
Project description
Truxl Python SDK
Lightweight, zero-dependency Python SDK for Truxl server-side event tracking. Works with Python 3.8+ using only the standard library.
Installation
pip install truxl
Quick Start
from truxl import Truxl
truxl = Truxl(
project_token="trxl_proj_demo_123",
client_secret="your-client-secret", # optional, enables HMAC signing
api_endpoint="https://ingest.truxl.com", # default
)
# Track a custom event
truxl.track(
event_name="purchase",
distinct_id="user-42",
properties={"price": 29.99, "currency": "USD"},
)
# Identify a user with traits
truxl.identify("user-42", traits={"email": "user@example.com", "plan": "pro"})
# Create an alias
truxl.alias(new_id="user-42", original_id="anon-abc123")
# Force-flush all queued events
truxl.flush()
# Graceful shutdown (blocks until queue drains)
truxl.shutdown()
API Reference
Truxl(project_token, ...)
Create a new client. The background consumer thread starts automatically.
| Parameter | Type | Default | Description |
|---|---|---|---|
project_token |
str |
required | Project token for the Truxl ingestion API |
client_secret |
str |
"" |
Secret for HMAC-SHA256 request signing |
api_endpoint |
str |
"https://ingest.truxl.com" |
Ingestion service base URL |
batch_size |
int |
20 |
Max events per batch request |
flush_interval |
float |
5.0 |
Seconds between automatic flushes |
max_queue_size |
int |
10000 |
Max queued events before dropping |
retry_attempts |
int |
5 |
Retries on 5xx / network errors |
retry_base_delay |
float |
1.0 |
Base delay for exponential backoff |
timeout |
int |
10 |
HTTP request timeout in seconds |
truxl.track(event_name, distinct_id=None, properties=None, session_id=None, timestamp=None)
Track a custom event. event_name is required.
timestampis epoch milliseconds (int). Defaults to the current time.propertiesis an arbitrary dict attached to the event.
truxl.identify(distinct_id, traits=None)
Identify a user. Sends a $identify event with properties.$set containing the traits dict.
truxl.alias(new_id, original_id)
Link two user identities. Sends a $alias event.
truxl.flush()
Signal the background thread to flush immediately. Non-blocking.
truxl.shutdown(timeout=10.0)
Shut down the client gracefully. Blocks until the consumer thread finishes or timeout seconds elapse. Any remaining events are flushed synchronously after the thread exits.
Always call shutdown() before your process exits to avoid losing events.
Configuration via TruxlConfig
For advanced use, you can import and inspect the config object:
from truxl import TruxlConfig
config = TruxlConfig(
project_token="trxl_proj_demo_123",
client_secret="your-secret",
batch_size=50,
flush_interval=2.0,
)
How It Works
track(),identify(), andalias()enqueue events into a thread-safe, bounded queue.- A daemon thread wakes every
flush_intervalseconds (or whenbatch_sizeis reached) and sends batches to the ingestion API. - HTTP requests include the
X-Project-Tokenheader and, when aclient_secretis configured, anX-SignatureHMAC-SHA256 header. - 5xx and network errors are retried with exponential backoff. 4xx errors are dropped immediately.
shutdown()signals the thread to exit, waits for it to join, then drains any remaining events synchronously.
Logging
The SDK logs to the truxl logger. To see debug output:
import logging
logging.getLogger("truxl").setLevel(logging.DEBUG)
License
MIT
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 truxl-0.1.0.tar.gz.
File metadata
- Download URL: truxl-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49f638c22e47758b1ea965130d7c22360253cbcca973b710d75ddebf20dd90c2
|
|
| MD5 |
8022bf939350ecc1c2c850adfdb1c3cd
|
|
| BLAKE2b-256 |
9b8c45b862b3ef05f7d3ce5ecd99e97a4c868c8e2053d16b3ee6ba5779c4556e
|
File details
Details for the file truxl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: truxl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3abf0a6cb9c3fa8d41056f3a63902910b5d70bd81a3d6153f24d0cad1ae40b22
|
|
| MD5 |
9a6b7e7ee5c28ce3d6cd503dfcf100c1
|
|
| BLAKE2b-256 |
d10f4495e6ca9fa522692cf70e3820bf43ba6b816458bd7d478969e98f10044a
|