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.1

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.1
File Size Uploaded Provenance Actions
relay_python_sdk-0.2.1.tar.gz 16.5 kB With provenance Details for relay_python_sdk-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 31.5 kB

Release files / relay_python_sdk-0.2.1.tar.gz

Download URL relay_python_sdk-0.2.1.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b3f5cfda1358ff40e7e93770678cac0e14ce5dba0f30add7e3acd4872d34b1ba
BLAKE2b-256 checksum
How to use checksums
238ab24934d9171772f2f1b4331681698299023e181aa8395c50aa5f4abe74c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

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

Download URL relay_python_sdk-0.2.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f67b2a3fceb5822ada680434763d97f96c03165cdc54fac1e78d20d76461b2be
BLAKE2b-256 checksum
How to use checksums
abfd17661cd0020645372b8eaaa73c54c6a419c52a60ba9639bcf1cc687f1b35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

Security for relay-python-sdk 0.2.1

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.

Select from 2 files

Attestation for relay_python_sdk-0.2.1.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 Nov 24, 2026.

Transparency log

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.1 This release

2 release files Full 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