Metadata-Version: 2.4
Name: apirelio-django
Version: 0.2.0
Summary: Fail-safe customer-aware API analytics middleware for Django and Django REST Framework.
Author: Apirelio
License-Expression: MIT
Project-URL: Homepage, https://apirelio.com/docs
Project-URL: Repository, https://github.com/pryznar/apirelio-django
Project-URL: Issues, https://github.com/pryznar/apirelio-django/issues
Keywords: apirelio,django,drf,api,analytics,observability
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5
Classifier: Framework :: Django :: 6
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: django<7,>=4.2
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: djangorestframework>=3.14; extra == "dev"
Requires-Dist: django-stubs>=4.2; extra == "dev"
Requires-Dist: djangorestframework-stubs>=3.14; 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 Django SDK

Native Django middleware for privacy-safe, customer-aware API analytics. The same package supports
regular Django views and Django REST Framework endpoints.

```bash
pip install apirelio-django
```

Add the middleware after Django's authentication middleware so identity resolvers can use
`request.user`:

```python
# settings.py
import os

MIDDLEWARE = [
    # ...
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "apirelio_django.ApirelioMiddleware",
]

APIRELIO = {
    "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": "billing.apirelio.resolve_customer",
}
```

Resolvers receive the completed `HttpRequest` and may return an Apirelio customer, application or
metadata dictionary:

```python
def resolve_customer(request):
    account = getattr(request.user, "account", None)
    if account is None:
        return None
    return {"id": str(account.id), "name": account.name, "plan": account.plan}
```

The middleware records the final status, duration, resolved URL pattern and DRF error code. Both
synchronous and asynchronous Django handlers are supported. Events enter the bounded Python Core
background queue and are flushed when the process exits. Bodies, query strings, cookies,
authorization values, email addresses and client IP addresses are never captured.

