API Lens Python SDK with OpenTelemetry-based ingest forwarding
Project description
API Lens Python SDK
Production-ready Python ingest client for API Lens with OpenTelemetry integration.
Framework support matrix
| Framework | Integration Module | Integration Type | Client Type |
|---|---|---|---|
| FastAPI | apilens.fastapi |
ASGI Middleware | AsyncIO |
| Starlette | apilens.starlette |
ASGI Middleware | AsyncIO |
| Django REST Framework | apilens.django |
Django Middleware | Threading |
| Django Ninja | apilens.django |
Django Middleware | Threading |
| Flask | apilens.flask |
WSGI Wrapper | Threading |
| Litestar | apilens.litestar |
Plugin Protocol | AsyncIO |
| BlackSheep | apilens.blacksheep |
ASGI Middleware | AsyncIO |
What this SDK includes
- batched + retrying ingest client (
ApiLensClient) - OpenTelemetry span exporter (
apilens.otel) for teams already on OTel - first-class framework integrations listed above
- automatic request/response payload sampling (size-limited)
Install
pip install apilenss
With framework support:
pip install 'apilenss[all]'
# or only one
pip install 'apilenss[fastapi]'
pip install 'apilenss[flask]'
Local development install (from repo):
pip install ./sdks/python
pip install './sdks/python[all]'
Quick start (manual capture)
from apilens import ApiLensClient, ApiLensConfig
client = ApiLensClient(
ApiLensConfig(
api_key="your_app_api_key",
base_url="https://api.apilens.ai/api/v1",
environment="production",
)
)
client.capture(
method="GET",
path="/health",
status_code=200,
response_time_ms=12.4,
)
client.shutdown(flush=True)
FastAPI
No OpenTelemetry instrumentation is required for endpoint + payload monitoring.
from fastapi import FastAPI
from typing import Annotated
from fastapi import Depends, Request
from apilens.fastapi import ApiLensMiddleware, set_consumer
app = FastAPI()
app.add_middleware(
ApiLensMiddleware,
api_key="your_app_api_key",
base_url="https://api.apilens.ai/api/v1",
env="production",
enable_request_logging=True,
log_request_body=True,
log_response_body=True,
)
def identify_consumer(request: Request, user_id: Annotated[str, Depends(lambda: "user_123")]):
set_consumer(request, identifier=user_id, name="Demo User", group="starter")
app.router.dependencies.append(Depends(identify_consumer))
@app.get("/v1/orders")
def list_orders():
return {"ok": True}
Starlette
from starlette.applications import Starlette
from apilens import ApiLensClient, ApiLensConfig
from apilens.starlette import instrument_app
app = Starlette()
client = ApiLensClient(ApiLensConfig(api_key="your_app_api_key"))
instrument_app(app, client)
Flask
from flask import Flask
from apilens import ApiLensClient, ApiLensConfig
from apilens.flask import instrument_app
app = Flask(__name__)
client = ApiLensClient(
ApiLensConfig(
api_key="your_app_api_key",
base_url="https://api.apilens.ai/api/v1",
environment="production",
)
)
instrument_app(app, client)
@app.get("/v1/invoices")
def invoices():
return {"ok": True}
Django (DRF + Django Ninja)
Add middleware in Django settings:
MIDDLEWARE = [
# ...
"apilens.django.ApiLensDjangoMiddleware",
]
APILENS_API_KEY = "your_app_api_key"
APILENS_BASE_URL = "https://api.apilens.ai/api/v1"
APILENS_ENVIRONMENT = "production"
Litestar
from litestar import Litestar
from apilens import ApiLensClient, ApiLensConfig
from apilens.litestar import ApiLensPlugin
client = ApiLensClient(ApiLensConfig(api_key="your_app_api_key"))
app = Litestar(route_handlers=[], plugins=[ApiLensPlugin(client=client)])
BlackSheep
from blacksheep import Application
from apilens import ApiLensClient, ApiLensConfig
from apilens.blacksheep import instrument_app
app = Application()
client = ApiLensClient(ApiLensConfig(api_key="your_app_api_key"))
instrument_app(app, client)
Notes
- default flush interval:
3s - default batch size:
200 - max ingest batch payload sent per request: follows backend limit (
<= 1000) - call
client.shutdown(flush=True)on graceful shutdown
Roadmap
Next adapters planned after FastAPI and Flask:
- Django
- Starlette
- Aiohttp
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 apilenss-0.1.3.tar.gz.
File metadata
- Download URL: apilenss-0.1.3.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df4ff49adcf147550208d2726530c2147e59a6873410c33dfb30aa747911a268
|
|
| MD5 |
dd7513ff3cebfb6b166115217c5bbe3d
|
|
| BLAKE2b-256 |
2cc2e8609e569b96f8815af433e434373b0a0e77ca27709c6e9241e420d3b341
|
Provenance
The following attestation bundles were made for apilenss-0.1.3.tar.gz:
Publisher:
workflow.yml on apilens/apilens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apilenss-0.1.3.tar.gz -
Subject digest:
df4ff49adcf147550208d2726530c2147e59a6873410c33dfb30aa747911a268 - Sigstore transparency entry: 955067685
- Sigstore integration time:
-
Permalink:
apilens/apilens@f7bbe44f464294f0ebc5ca5037043a1bfc975def -
Branch / Tag:
refs/tags/apilens-sdk-v0.1.3 - Owner: https://github.com/apilens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@f7bbe44f464294f0ebc5ca5037043a1bfc975def -
Trigger Event:
push
-
Statement type:
File details
Details for the file apilenss-0.1.3-py3-none-any.whl.
File metadata
- Download URL: apilenss-0.1.3-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd384d247af16a31b2dd1578841025151014468ab0b508e6cffb040df0eb03e
|
|
| MD5 |
e0c61e972800fd09b26ea8e27f0de4d5
|
|
| BLAKE2b-256 |
a7c18554023bfc6dc00cedfcd8bf1ec27a07e942ec0ee21568d6b049c1b07305
|
Provenance
The following attestation bundles were made for apilenss-0.1.3-py3-none-any.whl:
Publisher:
workflow.yml on apilens/apilens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
apilenss-0.1.3-py3-none-any.whl -
Subject digest:
fbd384d247af16a31b2dd1578841025151014468ab0b508e6cffb040df0eb03e - Sigstore transparency entry: 955067706
- Sigstore integration time:
-
Permalink:
apilens/apilens@f7bbe44f464294f0ebc5ca5037043a1bfc975def -
Branch / Tag:
refs/tags/apilens-sdk-v0.1.3 - Owner: https://github.com/apilens
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@f7bbe44f464294f0ebc5ca5037043a1bfc975def -
Trigger Event:
push
-
Statement type: