Metadata-Version: 2.4
Name: apirelio-fastapi
Version: 0.2.0
Summary: Fail-safe customer-aware API analytics middleware for FastAPI.
Author: Apirelio
License-Expression: MIT
Project-URL: Homepage, https://apirelio.com/docs
Project-URL: Repository, https://github.com/pryznar/apirelio-fastapi-python
Project-URL: Issues, https://github.com/pryznar/apirelio-fastapi-python/issues
Keywords: apirelio,fastapi,api,analytics,observability
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: apirelio<0.3.0,>=0.2.0
Requires-Dist: fastapi<1,>=0.100
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: httpx>=0.24; extra == "dev"
Requires-Dist: mypy<2,>=1.10; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# Apirelio FastAPI SDK

Native FastAPI/Starlette ASGI middleware for privacy-safe, customer-aware API analytics. It uses
the resolved route template and only enqueues after the response completes.

```bash
pip install apirelio-fastapi
```

```python
import os

from fastapi import FastAPI
from apirelio_fastapi import install_apirelio

app = FastAPI()

install_apirelio(
    app,
    api_key=os.environ.get("APIRELIO_API_KEY", ""),
    endpoint=os.environ.get("APIRELIO_ENDPOINT", "https://apirelio.com"),
    service="billing-api",
    environment="production",
    include_routes=("/api/**",),
    exclude_routes=("/api/health", "/api/internal/**"),
    resolve_customer=lambda request: {
        "id": str(request.state.user.company_id),
        "plan": request.state.user.plan,
    } if hasattr(request.state, "user") else None,
)
```

The installer stores the client at `app.state.apirelio` and flushes it during FastAPI shutdown.
Bodies, query strings, cookies, authorization values, email addresses and IP addresses are never
captured. Python 3.9+, FastAPI 0.100+ and FastAPI versions below 1.0 are supported.
