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.0.0.tar.gz
(10.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deliveryapi-1.0.0.tar.gz.
File metadata
- Download URL: deliveryapi-1.0.0.tar.gz
- Upload date:
- Size: 10.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5bac4e0ce2e476cc049804ae11258beda2a37f1086a4858bc731ef5d6388196
|
|
| MD5 |
f1d4f0877fa09be4861a4274b218f903
|
|
| BLAKE2b-256 |
9a12ce68bd984d9b8c0c05563dcb716d47a39fa124a62bd3b5a3830bf6aea247
|
File details
Details for the file deliveryapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: deliveryapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14987c92af79f6df4f067b0221d9ad41e96b6f7af557d2ea2be7192010aa49b2
|
|
| MD5 |
a4ed6b8c0d2f8d6b47a49104a89deaa9
|
|
| BLAKE2b-256 |
3645648ab8a8e0191aae8928f4694bdc0b3255284696df2ab51314f2e3d97f96
|