segops_admin
Server-side Python Admin SDK for the SegOps platform. Programmatic access to segments, products, schemas, activations, AI queries, landing pages, analytics, and more — the same surface the dashboard uses.
Server-side only. Requires a secret API key (sk_…). Never expose secret
keys to browsers or mobile apps.
Zero required runtime dependencies (stdlib only). Python 3.9+.
Install
pip install segops_admin
Quick Start
from segops_admin import SegOpsAdmin
client = SegOpsAdmin(api_key="sk_...") # or set SEGOPS_API_KEY env var
# List all segments (paginated)
page = client.segments.list()
print(page["results"])
# Trigger a recompute
client.segments.recompute(12)
# Iterate all segments across pages
for segment in client.segments.iterate():
print(segment["name"])
Resources
Every resource exposes the same CRUD surface plus resource-specific actions:
| Namespace | Path prefix | Notable actions |
|---|---|---|
segments |
/segments/ |
recompute, members, membership, export, preview, estimate, versions |
product_segments |
/product-segments/ |
recompute |
products |
/pim/products/ |
bulk_upsert, score, score_all, facets, schema, import_csv, import_status, confirm_import |
schemas |
/schemas/ |
infer, validate |
activations |
/activations/ |
sync |
users |
/explorer/users/ |
search, get, events, segments, explain, publish_sandbox |
queries |
/ai-reach/queries/ |
run, results, simulate, dashboard, win_rate |
pages |
/ai-pages/pages/ |
bulk_generate, regenerate, build, publish, export, query |
analytics |
/analytics/ |
overview, segments, overlap, activations, usage (read-only) |
CRUD methods (all resources except users and analytics)
client.segments.list({"page": 1, "page_size": 20}) # paginated dict
client.segments.iterate() # generator over all items
client.segments.get(id)
client.segments.create({"name": "VIP", "definition": {...}})
client.segments.update(id, {"name": "VIP v2"})
client.segments.delete(id)
Segments
client.segments.preview(definition) # estimate without persisting
client.segments.estimate(id)
client.segments.versions(id)
client.segments.recompute(id) # POST /segments/{id}/compute/
client.segments.members(id, {"page": 1})
client.segments.membership("user-123")
client.segments.export(id, format="csv") # or "parquet"
Products (PIM)
client.products.bulk_upsert([{"sku": "SKU-1", "name": "Alpha"}, ...])
client.products.import_csv(open("products.csv", "rb").read(), "products.csv")
client.products.import_status(job_id)
client.products.confirm_import(job_id, {"confirmed": True})
client.products.score(id)
client.products.score_all()
client.products.facets()
client.products.schema()
Users (Explorer)
client.users.search({"q": "alice"})
client.users.get("user-123")
client.users.events("user-123", {"since": "2024-01-01"})
client.users.segments("user-123")
client.users.explain("user-123", segment_id=5)
client.users.publish_sandbox({"user_id": "u1", "event_type": "page_viewed", "payload": {}})
AI Queries
client.queries.run(id)
client.queries.results(id)
client.queries.simulate({"query_text": "best running shoes"})
client.queries.dashboard()
client.queries.win_rate()
Pages
client.pages.bulk_generate({"segment_id": 3, ...})
client.pages.regenerate(id)
client.pages.build(id, {"template": "default"})
client.pages.publish(id)
client.pages.export(id, format="html") # "tsx" | "html" | "json"
client.pages.query("running shoes")
Pagination
# Single page (dict with count / next / previous / results)
page = client.segments.list({"page": 1, "page_size": 50})
print(page["count"])
# Iterate all items transparently
for segment in client.segments.iterate():
process(segment)
Errors
from segops_admin import SegOpsApiError
try:
client.segments.get(9999)
except SegOpsApiError as exc:
print(exc.status) # 404
print(exc.body) # {"detail": "Not found."}
Idempotency
All mutating operations (create, recompute, export, etc.) automatically
send a unique Idempotency-Key header. This is forward-compatible with the
upcoming server-side idempotency storage (24h replay window) — the SDK sends
the header today even before the server honours it.
Retries
The client retries on 429 and 5xx responses with exponential backoff
(default 3 retries, cap 30s). Set max_retries=0 to disable.
client = SegOpsAdmin(api_key="sk_...", max_retries=5)
Webhook Verification
from segops_admin.webhook import verify_webhook
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)
SegOps signs the raw request body with HMAC-SHA256 and sends
X-SegOps-Signature: sha256=<hex>.
CLI
# Install exposes the `segops-admin` command.
pip install segops_admin
export SEGOPS_API_KEY=sk_...
export SEGOPS_API_URL=https://api.segops.ai/api # optional
segops-admin segments list
segops-admin segments recompute 12
segops-admin products import products.csv
segops-admin pages export 8 --format=html
segops-admin --help
All output is JSON; exit code 0 on success, 1 on API error, 2 on usage error.
Configuration
SegOpsAdmin(
api_key="sk_...",
base_url="https://api.segops.ai/api", # optional override
max_retries=3, # default 3
)
License
MIT
Metadata
Release files for segops-admin 0.2.2
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 | Actions |
|---|---|---|---|---|
| segops_admin-0.2.2.tar.gz | 12.1 kB | Without provenance | Details for segops_admin-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| segops_admin-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for segops_admin-0.2.2-py3-none-any.whl |
Total release size: 28.2 kB
Release files / segops_admin-0.2.2.tar.gz
| Download URL | segops_admin-0.2.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e993aa6f9b4efebbaaf7c6f7cbc8946d654a580f690b89c3d72586d157f0cd1
|
|
BLAKE2b-256 checksum How to use checksums |
473a0dcc58f6288ad1f9a4955da1ff27095031ffcc3bea44bc1eaf7dc596c874
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / segops_admin-0.2.2-py3-none-any.whl
| Download URL | segops_admin-0.2.2-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48d76df870c2d1a9822aaa492739b41d2bcafacd5c6e04e7823ccc21b634f0df
|
|
BLAKE2b-256 checksum How to use checksums |
18c7549f65cd854ed3ea53caa1e311d669af331032ff6772331e74e6cd9c886e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for segops-admin 0.2.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.