# philiprehberger-api-timer

[![Tests](https://github.com/philiprehberger/py-api-timer/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-api-timer/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-api-timer.svg)](https://pypi.org/project/philiprehberger-api-timer/)
[![License](https://img.shields.io/github/license/philiprehberger/py-api-timer)](LICENSE)

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)
```

## API

| Function / Class | Description |
|------------------|-------------|
| `ASGITimerMiddleware(app, slow_threshold_ms=500)` | ASGI middleware |
| `WSGITimerMiddleware(app, slow_threshold_ms=500)` | WSGI middleware |


## Development

```bash
pip install -e .
python -m pytest tests/ -v
```

## License

MIT
