Skip to main content

relay-python-sdk

Official Python SDK for Relay, a self-hosted webhook delivery engine.

Submit events, inspect delivery lifecycles, manage endpoints, and verify webhook signatures using a Python client.

Installation

pip install relay-python-sdk

Quick start

from relay_python import Relay

with Relay(
    api_key="your-api-key",
    base_url="http://localhost:8080",
) as client:
    # Submit an event
    response = client.send_event(
        source="stripe",
        event_type="payment.completed",
        data={
            "amount": 5000,
            "currency": "usd",
        },
        idempotency_key="order-123",
    )

    print(response.status, response.event_id)

    # Inspect its lifecycle state
    event = client.inspect_event(response.event_id)
    print(event.delivery_status)

The Relay client supports context-manager usage for resource cleanup.

Webhook signature verification

When an endpoint is configured with a signing secret, Relay signs outbound webhook requests using HMAC-SHA256 over:

<timestamp>.<body>

Verify incoming requests before processing their payloads.

from relay_python import verify_webhook_signature, SignatureError


def handle_webhook(request):
    try:
        verify_webhook_signature(
            secret=ENDPOINT_SIGNING_SECRET,
            timestamp_header=request.headers["X-Relay-Timestamp"],
            signature_header=request.headers["X-Relay-Signature"],
            body=request.body,  # Raw bytes, before JSON parsing
        )
    except SignatureError:
        return 401

    # Signature is valid and fresh.
    # Continue processing the webhook.

Important: Pass the original raw request body as bytes. Do not parse or re-serialize the JSON before signature verification.

The default timestamp freshness window is five minutes. The SDK exposes this through:

from relay_python import DEFAULT_MAX_AGE_MS

API reference

The Python SDK exposes the following client operations.

Events

Method Description
send_event() Submit an event to Relay.
list_events() List submitted events.
inspect_event() Retrieve an event's lifecycle information.
replay_event() Request replay of an event.
get_deliveries() Retrieve an event's delivery records.
get_attempts() Retrieve an event's delivery attempts.

Endpoints

Method Description
create_endpoint() Register a webhook endpoint.
list_endpoints() List configured endpoints.
get_endpoint() Retrieve endpoint details.
update_endpoint() Update endpoint configuration.
disable_endpoint() Disable an endpoint.

Health

Method Description
health() Check service liveness.
ready() Check service readiness.

Signature utilities

Function Description
sign_webhook_body() Generate a webhook signature.
verify_webhook_signature() Verify a signature and enforce timestamp freshness.

Idempotency

Every send_event() call requires an idempotency_key.

Relay uses this key to prevent duplicate event acceptance when the same submission is retried.

The response differs depending on whether the event has already been accepted.

First submission:

{
  "status": "accepted",
  "event_id": "event-id"
}

Repeated submission with the same key:

{
  "status": "already_accepted",
  "idempotency_key": "order-123"
}

The repeated-submission response does not include event_id. Relay does not return the original event ID on this retry path.

When the event ID is needed after a retry, retrieve the event using list_events().

Do not assume that event_id is present in every successful submission response.

Versioning

This SDK follows semantic versioning.

Version 0.2.0 aligns the Python SDK with Relay's actual server API contract and corrects inconsistencies in earlier SDK models and request/response handling.

See CHANGELOG.md for breaking changes introduced since 0.1.x.

Relay

Metadata

Release files for relay-python-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)

Source distribution for relay-python-sdk 0.2.0
File Size Uploaded Provenance Actions
relay_python_sdk-0.2.0.tar.gz 14.3 kB Without provenance Details for relay_python_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for relay-python-sdk 0.2.0
File Interpreter ABI Platform Actions
relay_python_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for relay_python_sdk-0.2.0-py3-none-any.whl

Total release size: 29.4 kB

Release files / relay_python_sdk-0.2.0.tar.gz

Download URL relay_python_sdk-0.2.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
45cff35014117485ab1a8b8fbcbf22be8a2074672011483b38e6c40d57bf83fe
BLAKE2b-256 checksum
How to use checksums
dfa7f2cc981292562f4550cdaf6503afb9e01ffccc1598a6031a859dd04b37ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / relay_python_sdk-0.2.0-py3-none-any.whl

Download URL relay_python_sdk-0.2.0-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f808bae89d5e7066ab6a7a17669213944ecede7ac18f6406f233ca023ef4b6f
BLAKE2b-256 checksum
How to use checksums
f0b858a0c6a2ddbbd85eb9e1c9be99f5e43118ed131a029fcf2b5f3f381c032e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for relay-python-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.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page