The `segops_admin` package is the server-side Python Admin SDK for SegOps. It gives you programmatic access to every platform surface — segments, products, schemas, activations, AI queries, landing pages, and analytics — the same way the dashboard does.
Server-side only. Requires a secret API key (sk_…). Public (pk_) and
MCP (mk_) keys are rejected. Zero required runtime dependencies (stdlib only).
Python 3.9+.
TypeScript users: the @segops/admin npm package exposes the same
resource namespaces and method names. See the TypeScript Admin SDK
docs.
import os
from segops_admin import SegOpsAdmin
client = SegOpsAdmin(api_key=os.environ["SEGOPS_API_KEY"])
# List segments (first page)
page = client.segments.list()
print(page["count"], "segments")
# Trigger a recompute
client.segments.recompute(12)
# Iterate all segments across pages
for segment in client.segments.iterate():
print(segment["id"], segment["name"])
# Single page — returns a dict with count / next / previous / results
page = client.segments.list({"page": 2, "page_size": 50})
print(page["count"]) # total items
print(page["results"]) # list[dict] for this page
# Iterator — transparently fetches all pages
for segment in client.segments.iterate():
process(segment)
# With initial params
for seg in client.segments.iterate({"page_size": 100}):
process(seg)
from segops_admin import SegOpsApiError
try:
client.segments.get(9999)
except SegOpsApiError as exc:
print(exc.status) # HTTP status code, e.g. 404
print(exc.body) # parsed JSON body or raw string
SegOpsConfigError is raised at construction time for bad API keys.
All mutating operations (create, recompute, bulk_upsert, export, etc.)
automatically send a unique Idempotency-Key header. This is forward-compatible
with upcoming server-side idempotency storage (24h replay window) — the header
is sent today even before the server honours it.
SegOps signs outbound webhook payloads with HMAC-SHA256 and sends:
X-SegOps-Signature: sha256=<hex>
Verify the signature before processing:
python
from segops_admin.webhook import verify_webhook
# Flask example
raw_body = request.get_data()
sig = request.headers.get("X-SegOps-Signature", "")
if not verify_webhook(raw_body, sig, os.environ["SEGOPS_WEBHOOK_SECRET"]):
abort(401)
event = request.get_json()
python
# Django example
raw_body = request.body
sig = request.headers.get("X-SegOps-Signature", "")
if not verify_webhook(raw_body, sig, settings.SEGOPS_WEBHOOK_SECRET):
return HttpResponse(status=401)