Behavioral segmentation ingestion SDK for Python — thread-safe event client with batching and the public-key session handshake.
Project description
segops
Behavioral segmentation ingestion SDK for Python. Thread-safe event client with built-in batching, the public-key session handshake, and graceful shutdown. Zero required runtime dependencies (stdlib only).
Install
pip install segops
Requires Python 3.9+.
Usage
Server — secret key (sk_…)
A secret key authenticates directly and must never reach a browser or mobile app.
import segops
client = segops.SegOpsClient("https://api.segops.ai", "sk_...")
client.track(user_id="u-123", event_type="order_placed", payload={"total": 42})
client.shutdown() # flush + stop the background thread on exit
Or use it as a context manager (flushes on exit):
with segops.SegOpsClient("https://api.segops.ai", "sk_...") as client:
client.track(user_id="u-123", event_type="page_viewed", payload={"path": "/home"})
Public key (pk_…) — session handshake
A public key can't write directly; the SDK exchanges it for a short-lived session
token via the handshake. Provide get_user to return the current user context.
To bind events to a logged-in user, sign the user id on your backend (see below)
and return it from get_user.
import segops
client = segops.SegOpsClient(
"https://api.segops.ai",
"pk_...",
get_user=lambda: segops.UserContext(
user_id=current_user.id,
user_id_sig=signed["user_id_sig"], # from your backend
user_id_ts=signed["user_id_ts"],
),
)
The token is cached, refreshed 60s before expiry, and re-minted on a 401.
Identify
client.identify(
user_id="u-123",
traits={"email": "alice@example.com", "plan": "pro"},
)
Emits a context_identified event whose payload is the traits.
Options
SegOpsClient(api_url, api_key, *, get_user=None, batch=True, batch_size=20, flush_interval=5.0, on_error=None)
| Argument | Default | Description |
|---|---|---|
api_url |
— | Base URL of your SegOps deployment |
api_key |
— | sk_… (server) or pk_… (handshake) |
get_user |
— | Required for pk_…: returns a UserContext at mint time |
batch |
True |
Buffer events and flush automatically; False sends each immediately |
batch_size |
20 |
Max events before an automatic flush |
flush_interval |
5.0 |
Periodic flush interval (seconds) |
on_error |
log to stderr | Called when a background flush fails |
Signing a user id (backend only)
Run this on your backend only — never ship the HMAC secret to a client.
import os
import segops
signed = segops.sign_user_id(os.environ["SEGOPS_HMAC_SECRET"], current_user.id)
# -> {"user_id": ..., "user_id_sig": ..., "user_id_ts": ...} — hand to get_user()
Enable "require signed user_id" on the public key so the server rejects unsigned or forged identities.
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 segops-0.1.0.tar.gz.
File metadata
- Download URL: segops-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46adbcde4529ae38de626f8ba35e67266e7f656968f98ab91f27038cea253a4
|
|
| MD5 |
43a3a68f9ad8ab8b5efc5b27d20cd04a
|
|
| BLAKE2b-256 |
a0169341018c9151c9ec54bad570e2d05c69b955d327c8993feb2175ced4ca66
|
Provenance
The following attestation bundles were made for segops-0.1.0.tar.gz:
Publisher:
release-sdks.yml on applifi-apps/segops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segops-0.1.0.tar.gz -
Subject digest:
d46adbcde4529ae38de626f8ba35e67266e7f656968f98ab91f27038cea253a4 - Sigstore transparency entry: 1752078653
- Sigstore integration time:
-
Permalink:
applifi-apps/segops@c24048afb8fe50e5f66480722b5d7b9e3ccf9090 -
Branch / Tag:
refs/tags/sdk-py-v0.1.0 - Owner: https://github.com/applifi-apps
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdks.yml@c24048afb8fe50e5f66480722b5d7b9e3ccf9090 -
Trigger Event:
push
-
Statement type:
File details
Details for the file segops-0.1.0-py3-none-any.whl.
File metadata
- Download URL: segops-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 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 |
34fcdd4f23d84e96ea8df0b6a63cb81f7f60b1dcab72adfaa46a19ec6d26cc9e
|
|
| MD5 |
807d9f9fdf7d5d0101ea5da5b7761e4f
|
|
| BLAKE2b-256 |
f7356799542d6d626ccdbe23e04841d746a259bf5ccf2dc11accf8ba78de9314
|
Provenance
The following attestation bundles were made for segops-0.1.0-py3-none-any.whl:
Publisher:
release-sdks.yml on applifi-apps/segops
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segops-0.1.0-py3-none-any.whl -
Subject digest:
34fcdd4f23d84e96ea8df0b6a63cb81f7f60b1dcab72adfaa46a19ec6d26cc9e - Sigstore transparency entry: 1752078758
- Sigstore integration time:
-
Permalink:
applifi-apps/segops@c24048afb8fe50e5f66480722b5d7b9e3ccf9090 -
Branch / Tag:
refs/tags/sdk-py-v0.1.0 - Owner: https://github.com/applifi-apps
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdks.yml@c24048afb8fe50e5f66480722b5d7b9e3ccf9090 -
Trigger Event:
push
-
Statement type: