Skip to main content

Official Python SDK for GenieOS — sync + async clients, typed responses, idempotency-aware retries, webhook verification.

Project description

genieos — Python SDK

PyPI version

The official Python SDK for GenieOS. Sync and async clients, typed responses (Pydantic), automatic idempotency, retry-on-429/5xx with exponential back-off, and webhook signature verification.

Install

pip install genieos

Requires Python 3.9+ and httpx>=0.27, pydantic>=2.6.

Quickstart (sync)

from genieos import GenieOS

with GenieOS(api_key="gos_live_...") as mg:
    ws = mg.workspace.get()
    print(ws.name, "on", ws.plan)

    send = mg.templates.send(
        "welcome",
        to="aki@example.com",
        variables={"firstName": "Aki"},
    )
    print("queued:", send.id)

The API key is also picked up from the GENIEOS_API_KEY env var, matching the Node SDK and CLI.

Quickstart (async)

import asyncio
from genieos import AsyncGenieOS

async def main():
    async with AsyncGenieOS() as mg:  # MAILGENIUS_API_KEY env var
        await mg.events.emit(
            "subscription.cancelled",
            email="aki@example.com",
            traits={"tier": "pro", "reason": "moving to weekly"},
        )

asyncio.run(main())

Webhook verification (Flask)

from flask import Flask, request, abort
from genieos import verify_webhook, WebhookSignatureError

app = Flask(__name__)

@app.post("/genieos/webhook")
def webhook():
    try:
        delivery = verify_webhook(
            request.get_data(as_text=True),
            request.headers,
            secret=os.environ["MAILGENIUS_WEBHOOK_SECRET"],
        )
    except WebhookSignatureError as e:
        abort(400, str(e))

    if delivery.type == "send.delivered":
        ... # handle it
    return "", 204

verify_webhook rejects out-of-window timestamps (default ±5 min) and performs constant-time signature comparison. The same module exposes sign_webhook for local testing.

Error handling

from genieos import (
    GenieOSRateLimitError,
    GenieOSValidationError,
    GenieOSAuthError,
)

try:
    mg.events.emit("checkout.completed", email="aki@example.com")
except GenieOSRateLimitError as e:
    time.sleep(e.retry_after_seconds)
except GenieOSValidationError as e:
    log.warning("422: %s", e.body)
except GenieOSAuthError:
    rotate_my_key()

All SDK errors inherit from GenieOSError and expose .code, .status, .request_id, .body.

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

genieos-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

genieos-0.1.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for genieos-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2763396faf961a754d3f37dd0a65069735c231b5686ba2f217c4bf851cae3aab
MD5 c464a2e1cd577be7368e65159d742fc2
BLAKE2b-256 4cc42e206d3ffb3aebbbb75dfca3ba2df4997b112b4cc2116e2be678458a8a48

See more details on using hashes here.

Provenance

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

Publisher: release.yml on GenieOS-0/sdk-python

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

File details

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

File metadata

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

File hashes

Hashes for genieos-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 337096a36f10b6185996b99fa403f53ca79e5d89b43c3602d87e6221d6324e53
MD5 1bedc17b7c62f2f3f1bc438d07567466
BLAKE2b-256 9b509c966bdb7aa662b2c063f41ca2540c803881fd261f24bd6378594c601840

See more details on using hashes here.

Provenance

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

Publisher: release.yml on GenieOS-0/sdk-python

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