Siren SDK for Python
Affiliate, referral, and incentive tracking for any commerce stack — record sales, verify signed webhooks in one call, and reconcile Siren's ledger against your own.
What is Siren?
Siren is an affiliate, referral, and incentive platform. You register commerce events — sales, refunds, referred visits — and Siren attributes them to collaborators, computes rewards, and pays out.
This SDK is the official Python client for the Siren API. It lets you:
- Record sales, refunds, referred visits, and custom events (
events) - Verify signed webhook deliveries in a single, constant-time call (
webhooks) - Read Siren's ledger and manage webhook subscriptions with an API key that holds the ledger and webhook scopes
- Manage API keys with a signed-in dashboard session
- Reconcile Siren's ledger against your own with paginated readers
The full developer surface is described in the OpenAPI specification.
Install
pip install siren-sdk
The distribution is named siren-sdk, but the import name is siren:
import siren
Requires Python 3.9+. The only dependency is httpx.
Quickstart
Record a sale
import siren
client = siren.Siren(api_key="sk_live_...") # Settings -> API Keys in the Siren dashboard
result = client.events.sale(
source="stripe", # your commerce source
external_id="cs_test_a1b2c3", # your order id; used to match refunds later
total=49.99, # major units: 49.99 means $49.99
tracking_id=4021, # opportunity id from the Siren tracking cookie
)
print(result.opportunity_id) # read from the X-Siren-OID response header
print(result.status) # created, recorded, duplicate, unattributed, ignored, or queued
Siren answers each sale with what came of it, in result.body. Sending the
same source and external_id again records nothing new and answers
duplicate. While your organization's processing is paused, Siren queues the
event and answers 202, and result.queued is True.
With line items (reward pools compute amount x quantity per line; a missing
quantity defaults to 1):
client.events.sale(
source="stripe",
external_id="ord_77",
total=109.97,
tracking_id=4021,
currency="USD",
items=[
{"external_id": "sku_1", "name": "Pro Plan (annual)", "amount": 49.99},
{"name": "Add-on", "quantity": 3, "amount": 19.99},
],
)
Refunds and referred visits:
client.events.refund(source="stripe", external_id="cs_test_a1b2c3")
client.events.site_visited(collaborator_id=88, user_id=12345)
# Custom event types registered on your org:
client.events.ingest("loyalty-points-earned", {"points": 120, "memberId": "m_9"})
Verify a webhook
Siren signs every delivery with X-Siren-Signature: sha256=<hex hmac> — an
HMAC-SHA256 of the raw request body keyed by your subscription's signing
secret. construct_event verifies the signature (constant-time) and parses
the event in one call.
The body is the event's payload alone, such as {"conversionId": 991}. The
event type arrives in the X-Siren-Event header and the event id in
X-Siren-Delivery, so pass both headers along. Without event_type,
construct_event raises SignatureVerificationError, because the body alone
does not name the event. The event id stays the same when Siren retries a
delivery, so use it to drop repeats.
import siren
from flask import Flask, request
app = Flask(__name__)
client = siren.Siren(api_key="sk_live_...")
@app.post("/webhooks/siren")
def handle_webhook():
try:
event = client.webhooks.construct_event(
request.get_data(), # RAW body bytes — critical
request.headers.get("X-Siren-Signature"),
"whsec_...", # your signing secret
event_type=request.headers.get("X-Siren-Event"),
delivery_id=request.headers.get("X-Siren-Delivery"),
)
except siren.SignatureVerificationError:
return "invalid signature", 400
if event.type == siren.WebhookEventType.CONVERSION_APPROVED:
handle_conversion(event.data)
return "", 204
Pass the raw body bytes. The HMAC is computed over the exact bytes Siren sent. If you parse the JSON and re-serialize it, key order and whitespace change and verification will fail. Use
request.get_data()(Flask),request.body(Django),await request.body()(FastAPI/Starlette) — neverjson.dumps(request.json).
To just check a signature without parsing:
if client.webhooks.verify_signature(raw_body, signature_header, secret):
...
Manage subscriptions
The API key needs the webhook-subscriptions:manage scope. A key with
webhook-subscriptions:read can call list() only.
subscription = client.webhooks.subscriptions.create(
target_url="https://example.com/webhooks/siren",
events=[
siren.WebhookEventType.CONVERSION_APPROVED,
siren.WebhookEventType.PAYOUT_PAID,
],
# or events=[siren.WebhookEventType.ALL] to subscribe to everything
)
print(subscription.signing_secret) # returned ONCE — store it now
client.webhooks.subscriptions.list()
client.webhooks.subscriptions.delete(subscription.id)
Features
- Event ingestion —
events.sale,events.refund,events.site_visited, andevents.ingestfor custom event types. - One-call webhook verification —
webhooks.construct_eventverifies the HMAC-SHA256 signature in constant time and parses the payload. - Subscription management — create, list, and delete subscriptions with an API key that holds a webhook scope, or a dashboard session.
- API-key management — create, list, and revoke API keys with a signed-in dashboard session. One-time secrets are never auto-retried.
- Reconciliation readers — paginated access to conversions, transactions, obligations, and payouts, with an API key that holds the ledger scopes.
- Typed, correct errors — every failure subclasses
siren.SirenErrorwithmessage,code, andstatus_code;BadRequestError.field_errorsandRateLimitError.retry_afterwhere relevant. - Automatic retries — exponential backoff on network errors and 429/5xx for idempotent reads and event ingestion (never for secret-minting writes).
- Fully typed — ships
py.typed; works with mypy and Pyright out of the box.
Credentials
An API key (sk_live_...) does what its scopes allow. siren.ApiKeyScope
names each one:
| Scope | What the key can do |
|---|---|
ApiKeyScope.ALL_EVENTS (event:*), event_scope(slug) |
Send events |
ApiKeyScope.LEDGER_CONVERSIONS_READ (ledger:conversions:read) |
conversions.list() |
ApiKeyScope.LEDGER_TRANSACTIONS_READ (ledger:transactions:read) |
transactions.list() |
ApiKeyScope.LEDGER_OBLIGATIONS_READ (ledger:obligations:read) |
obligations.list() |
ApiKeyScope.LEDGER_PAYOUTS_READ (ledger:payouts:read) |
payouts.list() |
ApiKeyScope.WEBHOOK_SUBSCRIPTIONS_READ (webhook-subscriptions:read) |
webhooks.subscriptions.list() |
ApiKeyScope.WEBHOOK_SUBSCRIPTIONS_MANAGE (webhook-subscriptions:manage) |
Every webhooks.subscriptions call, and a test delivery (POST /webhooks/{id}/test, which the SDK has no method for) |
Siren grants the ledger and webhook scopes only by their exact names. *,
event:*, wildcards such as ledger:*, and older names such as
conversions:read grant none of them, so a key made before these scopes
existed reads nothing until you replace it with one that holds them. A key's
requests count against the organization's API rate limit.
api_keys takes a signed-in dashboard session's token, passed as api_key.
No API key scope reaches it, and Siren answers a key there with
ApiKeyNotAcceptedError. The reconciliation readers also take a dashboard
session's token or a connected site's token.
A key created with a property_id is bound to that store. It reads only its
own store's conversions, transactions and obligations, and Siren refuses it
on payouts and webhook subscriptions with StoreKeyNotAllowedError. An
organization-wide key reads the whole organization, and narrows a ledger read
to one store with property_id:
client.conversions.list(property_id=5, status="approved")
API keys
from siren import ApiKeyScope
key = client.api_keys.create(
label="Accounting export",
scopes=[ApiKeyScope.LEDGER_CONVERSIONS_READ, ApiKeyScope.LEDGER_PAYOUTS_READ],
)
print(key.raw_key) # sk_live_... — returned ONCE, cannot be retrieved later
client.api_keys.list() # no raw key material
client.api_keys.revoke(key.id)
Reconciliation
Thin paginated readers over Siren's ledger. page and per_page become
Siren's number and offset, and a page holds at most 200 records:
page = client.conversions.list(page=1, per_page=50)
for conversion in page:
print(conversion["id"])
print(page.total, page.total_pages)
client.transactions.list()
client.obligations.list()
client.payouts.list(status="paid") # extra filters pass through as query args
Errors
All errors subclass siren.SirenError and carry message, code, and
status_code:
| HTTP status | Exception |
|---|---|
| 400 | BadRequestError (.field_errors when a field failed its check) |
| 401 | AuthenticationError, or its subclass ApiKeyNotAcceptedError (code api_key_not_accepted) when the route takes a session and not an API key |
| 403 | PermissionError, or its subclasses MissingScopeError (code missing_scope, with .scope and .any_of) and StoreKeyNotAllowedError (code store_key_not_allowed, with .property_id) |
| 404 | NotFoundError |
| 409 | ConflictError |
| 422 | ValidationError (.field_errors), from the few routes that still use 422 |
| 429 | RateLimitError (.retry_after) |
| 5xx | ApiError |
| network/timeout | ConnectionError |
Webhook verification failures raise SignatureVerificationError.
siren.ErrorCode holds the codes the SDK raises a dedicated error for.
try:
client.events.refund(source="stripe", external_id="unknown")
except siren.NotFoundError:
print("no matching sale")
except siren.RateLimitError as err:
print(f"retry in {err.retry_after}s")
Configuration
client = siren.Siren(
api_key="sk_live_...",
base_url="https://api.sirenaffiliates.com/siren/v1", # default; point at staging/local to test
timeout=30.0, # seconds
max_retries=2, # exponential backoff on network errors and 429/5xx
)
Other SDKs
Siren maintains official SDKs for other stacks:
- Node.js — Novatorius/siren-node
- PHP — Novatorius/siren-php
Links
- Website: sirenaffiliates.com
- API reference: OpenAPI specification
- Issues: github.com/Novatorius/siren-python/issues
Contributing
Contributions are welcome. See CONTRIBUTING.md for how to set up a development environment and run the test suite. By participating you agree to the Code of Conduct.
License
MIT — see LICENSE.
Metadata
Release files for siren-sdk 0.2.0
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 |
|---|---|---|---|---|
| siren_sdk-0.2.0.tar.gz | 42.1 kB | With provenance | Details for siren_sdk-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| siren_sdk-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for siren_sdk-0.2.0-py3-none-any.whl |
Total release size: 69.3 kB
Release files / siren_sdk-0.2.0.tar.gz
| Download URL | siren_sdk-0.2.0.tar.gz |
|---|---|
| Size | 42.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c94479a094da6f7068ee50890d786c877237c4eaca0b45c512011fa06ec6bea
|
|
BLAKE2b-256 checksum How to use checksums |
d10650442380acd7493d55a6896f8d8064e766b7a8f321d32581bb9c849b061d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / siren_sdk-0.2.0-py3-none-any.whl
| Download URL | siren_sdk-0.2.0-py3-none-any.whl |
|---|---|
| Size | 27.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1bcad82b08c62f7e7d02e084c715bebb0173c65853b91112737825fb1282dd07
|
|
BLAKE2b-256 checksum How to use checksums |
c6005136efb0f9fedfadc96f5051bb56474ead2bafdbb5c9d178b42dc4becabb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for siren-sdk 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for siren_sdk-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA 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.