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.9.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.9.0
File Size Uploaded Provenance Actions
sendrelay-1.9.0.tar.gz 15.9 kB With provenance Details for sendrelay-1.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 31.0 kB

Release files / sendrelay-1.9.0.tar.gz

Download URL sendrelay-1.9.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4bfdfbf267f3f04cee7b3e622286213054eb0f7cf8249b0c9582b4002ed9662c
BLAKE2b-256 checksum
How to use checksums
05e0951f84368e8e8314f73a50bc71021e583c6630b50572a191caabba9d73a8
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 8, 2026.

Transparency log

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

Download URL sendrelay-1.9.0-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02ea38f0b0e7df2aaa37f8deb90e0abdbaabf244fd3f96c662402e836c4e6566
BLAKE2b-256 checksum
How to use checksums
d427c94cefb43e1321c36f6cefff3a12061869daf44f7be21131075874ef3a93
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 8, 2026.

Transparency log

Security for sendrelay 1.9.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.9.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 8, 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