Python Quickstart
License validation for Python apps — Flask, Django, FastAPI, or standalone scripts.
5 minute setup
$
pip install traffic-orchestrator
1
Install the SDK
Install the Traffic Orchestrator Python package from PyPI.
bash
# pip
pip install traffic-orchestrator
# poetry
poetry add traffic-orchestrator
# pipenv
pipenv install traffic-orchestrator
2
Initialize the Client
Create a client pointing at the Traffic Orchestrator API.
python
from traffic_orchestrator import Client
client = Client(
base_url="https://api.trafficorchestrator.com/api/v1"
)
3
Validate a License Key
Verify a license key is valid and check which features it unlocks.
python
result = client.validate_license(
key="TO-XXXX-XXXX-XXXX",
domain="example.com"
)
if result["valid"]:
print("✅ License active!", result["features"])
# Unlock premium features
else:
print("❌ Invalid:", result["error"])
# Show upgrade prompt
4
Activate on a Device
Register the current machine against a license to enforce seat limits.
python
import uuid, hashlib, platform
# Generate a stable machine fingerprint
machine_id = hashlib.sha256(
f"{uuid.getnode()}-{platform.node()}".encode()
).hexdigest()[:32]
activation = client.activate_license(
key="TO-XXXX-XXXX-XXXX",
machine_id=machine_id
)
print(f"Seats: {activation['activations']}/{activation['max_activations']}")
5
Verify Offline (Optional)
Cryptographic verification without network — ideal for desktop apps and CLI tools.
python
# Ed25519 offline verification
is_valid = client.verify_offline(
"TO-XXXX-XXXX-XXXX",
signature, # cached from online validation
public_key # your Ed25519 public key
)
if is_valid:
# License verified — no network needed
print("Offline verification passed")
6
Enable Grace Period (Optional)
Keep your app running during API outages. Successful validations are cached in-memory and returned if the API becomes unreachable.
python
client = Client(
base_url="https://api.trafficorchestrator.com/api/v1",
grace_period=True, # enable caching
grace_period_ttl=86400, # 24 hours (default)
)
result = client.validate_license(
key="TO-XXXX-XXXX-XXXX",
domain="example.com"
)
if result.get("from_cache"):
print("Using cached validation")
# Clear cache manually
client.clear_cache()
7
Handle Webhooks (Flask)
Receive real-time events when license state changes.
python
import hmac, hashlib, time
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/webhooks/to', methods=['POST'])
def handle_webhook():
signature = request.headers.get('X-TO-Signature', '')
timestamp = request.headers.get('X-TO-Timestamp', '0')
# Reject stale webhooks (>5 min)
if time.time() - int(timestamp) > 300:
return jsonify(error='Expired'), 401
# Verify HMAC signature
expected = hmac.new(
WEBHOOK_SECRET.encode(),
f"{timestamp}.{request.get_data(as_text=True)}".encode(),
hashlib.sha256
).hexdigest()
if not hmac.compare_digest(signature, expected):
return jsonify(error='Invalid signature'), 401
event = request.json
print(f"Event: {event['event']}")
return jsonify(received=True), 200