Skip to main content

Server-side Python Admin SDK for the SegOps platform — programmatic access to segments, products, schemas, activations, queries, pages, and analytics.

Project description

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

Project details


Download files

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

Source Distribution

segops_admin-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

segops_admin-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file segops_admin-0.1.0.tar.gz.

File metadata

  • Download URL: segops_admin-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for segops_admin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f6a8d4c63169fc1393e2ee8946388cafba996c994e104baca5dfc1a39e40c862
MD5 725cd499d48c779d5f2abd4ed1f6d836
BLAKE2b-256 570837fef2e1d758b3db522a2eee76cc7c83fa8e2fd8eb3d743817086280a70f

See more details on using hashes here.

Provenance

The following attestation bundles were made for segops_admin-0.1.0.tar.gz:

Publisher: release-sdks.yml on applifi-apps/segops

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

File details

Details for the file segops_admin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: segops_admin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for segops_admin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bb99b05cd9a38774901acb3ccd2413db4a8855f44860498547ba09b62c79d7a
MD5 262de4c2d011be53021a851f8c7a2101
BLAKE2b-256 d8166a2c4b73125e8ee8d97b213ffdc0f8af39d4da7c056fc7cbd41a93a44482

See more details on using hashes here.

Provenance

The following attestation bundles were made for segops_admin-0.1.0-py3-none-any.whl:

Publisher: release-sdks.yml on applifi-apps/segops

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page