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.0.tar.gz
(12.9 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.2.0.tar.gz.
File metadata
- Download URL: deliveryapi-1.2.0.tar.gz
- Upload date:
- Size: 12.9 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 |
a56382d011cbe67f22c5fc47280289880b066eec851f118d465777a53ddcdea6
|
|
| MD5 |
438b58864a2bff89ad13bf386c1f1ae5
|
|
| BLAKE2b-256 |
e6e9f300ceaddf592db5bc9bb93c6658b8cc222acc3ca5c229567e580d480354
|
File details
Details for the file deliveryapi-1.2.0-py3-none-any.whl.
File metadata
- Download URL: deliveryapi-1.2.0-py3-none-any.whl
- Upload date:
- Size: 15.7 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 |
c9045ac557916f1ef1163e08ecc3e9c950d89552ba770523bb68d2e18bd3fc26
|
|
| MD5 |
924248b2940176c4ce0444c6641015a0
|
|
| BLAKE2b-256 |
5df62ee088fb22ce02f9052fb8d81739fd75e6a16ccf93f4f249ddead6836cef
|