SDK Goal
Your SDK should make ingest trivial:- capture request lifecycle data
- normalize payloads
- batch and flush safely
- retry on transient failures
Official Python SDK
API Lens ships an official Python SDK insdks/python, published as apilenss.
Supported today:
- FastAPI (
apilens.fastapimiddleware) - Flask (
apilens.flaskwrapper) - Django / Django Ninja (
apilens.djangomiddleware)
sdk/python-setup.mdx. Use extras for the framework you need:
Recommended Pipeline
- Intercept request start/end timestamps
- Build normalized request item
- Add to in-memory queue
- Flush queue on interval or size threshold
- POST to
/ingest/requestswith API key
Required Headers
Content-Type: application/jsonX-API-Key: <app_api_key>
Suggested Defaults
- Batch size: 100-500
- Flush interval: 2-5 seconds
- Max retries: 3
- Backoff: exponential with jitter
Normalization Rules
- Uppercase HTTP method
- Remove query string from route path
- Convert response time to milliseconds
- Include environment (
production/staging)
Minimal Node Example
Endpoint Checklist
When generating SDK clients for dashboard APIs, include:- Auth endpoints (
/auth/*) - App CRUD (
/apps/*) - Endpoint stats + options (
/apps/{slug}/endpoint-stats,/endpoint-options) - Analytics endpoints (
/apps/{slug}/analytics/*) - Ingest endpoint (
/ingest/requests)
Versioning Advice
- Keep schema adapters per API version
- Hide wire schema behind typed SDK interfaces
- Add integration test against a running APILens local env