Skip to main content

Relay Python SDK

The official server SDK for Relay, the delivery API. Quote and create deliveries, read them back with the rider's live ETA, manage webhooks, and mint tracking tokens for your apps.

pip install sendrelay

Python 3.9 or newer. Use Relay in regular code and AsyncRelay with asyncio. Both have the same methods.

Quick start

import os
from sendrelay import Relay

relay = Relay(api_key=os.environ["RELAY_API_KEY"])  # sk_test_... or sk_live_..., server only

stages = [
    {
        "type": "PICKUP",
        "location": {"latitude": 6.5244, "longitude": 3.3792, "address": "12 Marina Road, Lagos"},
        "items": [{"name": "Phone case", "estimatedValue": 500000, "estimatedWeight": "LIGHT", "estimatedSize": "BOX"}],
    },
    {"type": "DROPOFF", "location": {"latitude": 6.4474, "longitude": 3.4723, "address": "22 Admiralty Way, Lekki"}},
]

quote = relay.tasks.quote({"taskType": "PACKAGE_DELIVERY", "stages": stages})
print(quote["total"])  # kobo

created = relay.tasks.create(
    {"taskType": "PACKAGE_DELIVERY", "stages": stages, "quoteId": quote["quoteId"]},
    idempotency_key="order-1042",  # retries with the same key never create a second delivery
)

read = relay.tasks.get(created["task"]["id"])
if read["liveEta"]:
    print(f"Arriving at stop {read['liveEta']['stageIndex'] + 1} at {read['liveEta']['arrivesAt']}")

Responses are plain dicts with the API's field names (liveEta, totalFee, ...). sendrelay.types has TypedDicts for them.

Asyncio

from sendrelay import AsyncRelay

async with AsyncRelay(api_key=os.environ["RELAY_API_KEY"]) as relay:
    async for task in relay.tasks.list_all(limit=50):
        print(task["id"], task["status"])

Webhooks

from sendrelay import verify_webhook_signature

result = verify_webhook_signature(raw_body, request.headers["X-Relay-Signature"], os.environ["RELAY_WEBHOOK_SECRET"])
if not result.valid:
    return 400

Pass the raw request body exactly as received, not re-serialized JSON.

Errors and retries

  • ApiError has status_code, code and details from the API.
  • NetworkError means the request never got an answer.
  • ValidationError means the SDK rejected the input before sending.

Timeouts, 408, 429 and 5xx responses are retried up to 3 times with exponential backoff. Test-mode quota errors are not retried. Change this with max_retries= or retry=RetryConfig(...).

Tracking in your app

Mint a short-lived token on your server and hand it to your app:

token = relay.auth.create_websocket_token({"scope": [f"task:{task_id}"]})["token"]

Your app then tracks the task live with one of the UI SDKs.

Full documentation

Metadata

Release files for sendrelay 1.8.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 sendrelay 1.8.0
File Size Uploaded Provenance Actions
sendrelay-1.8.0.tar.gz 16.3 kB With provenance Details for sendrelay-1.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sendrelay 1.8.0
File Interpreter ABI Platform Actions
sendrelay-1.8.0-py3-none-any.whl Python 3 none any Details for sendrelay-1.8.0-py3-none-any.whl

Total release size: 31.2 kB

Release files / sendrelay-1.8.0.tar.gz

Download URL sendrelay-1.8.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
74bae7621e111835fd97306aaa0d023c145b52d5a9ada27cf5d67529d2c2c18e
BLAKE2b-256 checksum
How to use checksums
7c027d0bc4295d138990a99c9995d7b595f2ccc964dfdbf38635a2a90de2f10d
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 3, 2026.

Transparency log

Release files / sendrelay-1.8.0-py3-none-any.whl

Download URL sendrelay-1.8.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b680edde548763fd67f1a1bc98d3dfb291fa2e49b79beec46602cab50e822d38
BLAKE2b-256 checksum
How to use checksums
0d1f0375035201c6847d0e0bb823a7616b697cfc8f85b5f31784f118d4638e57
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 3, 2026.

Transparency log

Security for sendrelay 1.8.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.

Select from 2 files

Attestation for sendrelay-1.8.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 Nov 3, 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.

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