Metadata-Version: 2.4
Name: philiprehberger-api-timer
Version: 0.1.0
Summary: Drop-in ASGI/WSGI middleware for endpoint timing
Project-URL: Homepage, https://github.com/philiprehberger/py-api-timer
Project-URL: Repository, https://github.com/philiprehberger/py-api-timer
Project-URL: Issues, https://github.com/philiprehberger/py-api-timer/issues
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: api,asgi,middleware,performance,timer,wsgi
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# philiprehberger-api-timer

Drop-in ASGI/WSGI middleware for endpoint timing with Server-Timing headers.

## Installation

```bash
pip install philiprehberger-api-timer
```

## Usage

### ASGI (FastAPI, Starlette)

```python
from fastapi import FastAPI
from philiprehberger_api_timer import ASGITimerMiddleware

app = FastAPI()
app.add_middleware(ASGITimerMiddleware, slow_threshold_ms=500)
```

### WSGI (Flask, Django)

```python
from flask import Flask
from philiprehberger_api_timer import WSGITimerMiddleware

app = Flask(__name__)
app.wsgi_app = WSGITimerMiddleware(app.wsgi_app, slow_threshold_ms=500)
```

### What It Does

- Adds `Server-Timing` header to every response (e.g., `Server-Timing: total;dur=42.5`)
- Logs a WARNING for requests exceeding the slow threshold
- Zero configuration required — just add the middleware

## API

- `ASGITimerMiddleware(app, slow_threshold_ms=500)` — ASGI middleware
- `WSGITimerMiddleware(app, slow_threshold_ms=500)` — WSGI middleware

## License

MIT
