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.1.0.tar.gz (12.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.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deliveryapi-1.1.0.tar.gz
  • Upload date:
  • Size: 12.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.1.0.tar.gz
Algorithm Hash digest
SHA256 447c1eafae4e89ade427d19ff6ad83c692ceeb35951250193fa0956070acb96a
MD5 099fab670dd42ae297bba943ace4a2f2
BLAKE2b-256 bddd418a504c81f988b1710a1ff61248685ee8c9a878ee9e886853e10d713a75

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deliveryapi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 321a52fcac23698779765c278a1a6937b98618d66e230658e3674cd4938bff93
MD5 8aadbe3d53fa30688c2be3a516cb1363
BLAKE2b-256 be5129a203ea0c1bc43b8fbeef01055187690c04fdc7a6c7b75d4c13ba72bb41

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