Skip to main content

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

from fastapi import FastAPI
from apilens import ApiLensClient, ApiLensConfig
from apilens.fastapi import instrument_app

app = FastAPI()

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/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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apilenss-0.1.2.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apilenss-0.1.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file apilenss-0.1.2.tar.gz.

File metadata

  • Download URL: apilenss-0.1.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for apilenss-0.1.2.tar.gz
Algorithm Hash digest
SHA256 120a83f1fc50bc510d26d25b93850132a0340bba62153c3741cd391a2510deda
MD5 f7b8097594d79da8796f0c52cfaecb29
BLAKE2b-256 e540075c5d1ea4b4998207d837cc54951bbe3ac9cec3381a996b17671ecbea4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for apilenss-0.1.2.tar.gz:

Publisher: workflow.yml on apilens/apilens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apilenss-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: apilenss-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for apilenss-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 346b5ca154574cf72d1bc921df2b8ef45a54b39dccaada6f6fdf74c1d7af6427
MD5 f75759e9b4b9906f4e759c11adb4a980
BLAKE2b-256 40d32f1a8ff245b95b533f5865944e3a35f0dfce06bc0f48915e8c0f500435ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for apilenss-0.1.2-py3-none-any.whl:

Publisher: workflow.yml on apilens/apilens

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page