Skip to main content

Official Python SDK for the DeliveryAPI courier tracking platform

Project description

deliveryapi — Python SDK

Official Python SDK for the DeliveryAPI courier tracking and webhook platform.

Installation

pip install deliveryapi

Quick Start

from deliveryapi import DeliverySaasClient

client = DeliverySaasClient(
    api_key="pk_live_...",
    secret_key="sk_live_...",
)

# Query a single tracking number
result = client.tracking.get_one("LOTTE", "1234567890")
item = result["results"][0]
if item["success"]:
    print(item["data"]["deliveryStatus"])  # e.g. "IN_TRANSIT"

# Batch query
result = client.tracking.get([
    {"courierCode": "LOTTE", "trackingNumber": "1234567890"},
    {"courierCode": "cj",    "trackingNumber": "9876543210"},
])
print(result["summary"])

Async Support

import asyncio
from deliveryapi import AsyncDeliverySaasClient

async def main():
    async with AsyncDeliverySaasClient(
        api_key="pk_live_...",
        secret_key="sk_live_...",
    ) as client:
        result = await client.tracking.get_one("LOTTE", "1234567890")
        print(result)

asyncio.run(main())

Webhook Signature Verification

from deliveryapi import verify_webhook_signature, WebhookSignatureError

# Flask example
@app.route("/webhook", methods=["POST"])
def handle_webhook():
    try:
        verify_webhook_signature(
            payload=request.get_data(as_text=True),
            signature=request.headers["X-Webhook-Signature"],
            timestamp=request.headers["X-Webhook-Timestamp"],
            secret="whsec_...",
        )
    except WebhookSignatureError:
        return "Invalid signature", 400

    event = request.json
    print(event["data"]["currentStatus"])
    return "", 200

Error Handling

from deliveryapi import (
    DeliverySaasClient,
    DeliverySaasError,
    AuthenticationError,
    RateLimitError,
    NotFoundError,
)

client = DeliverySaasClient(api_key="pk_...", secret_key="sk_...")

try:
    result = client.tracking.get_one("LOTTE", "1234567890")
except AuthenticationError:
    print("Invalid API credentials")
except RateLimitError:
    print("Rate limit exceeded — slow down requests")
except NotFoundError:
    print("Resource not found")
except DeliverySaasError as e:
    print(f"API error {e.status_code}: {e}")

Webhook Management

# Register an endpoint
endpoint = client.webhooks.create({
    "url": "https://my-server.com/webhook",
    "name": "Production server",
})
print(endpoint["id"])  # e.g. "ep_..."

# Create a subscription
sub = client.subscriptions.create({
    "courierCode": "LOTTE",
    "trackingNumber": "1234567890",
    "endpointId": endpoint["id"],
})
print(sub["id"])  # e.g. "sub_..."

# List and cancel
subs = client.subscriptions.list(status="active")
client.subscriptions.cancel(sub["id"])

Supported Couriers

couriers = client.couriers.list()
for c in couriers["couriers"]:
    print(c["id"], c["displayName"])

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deliveryapi-1.2.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deliveryapi-1.2.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file deliveryapi-1.2.1.tar.gz.

File metadata

  • Download URL: deliveryapi-1.2.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.11.6 HTTPX/0.28.1

File hashes

Hashes for deliveryapi-1.2.1.tar.gz
Algorithm Hash digest
SHA256 5e2e40394b65e554d9f7b8a371665d2ea9d57b8fb9b2840057039cdc6b8b182c
MD5 1146a9e0d996e831acaf97d626cae2d8
BLAKE2b-256 337dc0c94f6047aea8c4f6b6f3f912d7e301e66d53697cc75349a7c91d87f188

See more details on using hashes here.

File details

Details for the file deliveryapi-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: deliveryapi-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.11.6 HTTPX/0.28.1

File hashes

Hashes for deliveryapi-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a648474aaf9d79f8ba9c9505b7acbb9287ec1c348fd452d46dddc352af3e8a32
MD5 4423683e2148e6db62f5a4258788df7c
BLAKE2b-256 777a6e9f8633b4a27cfd4bf6ffb3074ab593ec1a70a3c46448c3a7882be3bb15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page