Drop-in ASGI/WSGI middleware for endpoint timing
Project description
philiprehberger-api-timer
Drop-in ASGI/WSGI middleware for endpoint timing with Server-Timing headers.
Installation
pip install philiprehberger-api-timer
Usage
ASGI (FastAPI, Starlette)
from fastapi import FastAPI
from philiprehberger_api_timer import ASGITimerMiddleware
app = FastAPI()
app.add_middleware(ASGITimerMiddleware, slow_threshold_ms=500)
WSGI (Flask, Django)
from flask import Flask
from philiprehberger_api_timer import WSGITimerMiddleware
app = Flask(__name__)
app.wsgi_app = WSGITimerMiddleware(app.wsgi_app, slow_threshold_ms=500)
Custom Logger
import logging
from philiprehberger_api_timer import ASGITimerMiddleware
logger = logging.getLogger("my_api")
app.add_middleware(ASGITimerMiddleware, logger=logger, include_header=False)
What It Does
- Adds
Server-Timingheader 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
| Function / Class | Description |
|---|---|
ASGITimerMiddleware(app, logger=None, slow_threshold_ms=500, include_header=True) |
ASGI middleware |
WSGITimerMiddleware(app, logger=None, slow_threshold_ms=500, include_header=True) |
WSGI middleware |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_api_timer-0.1.12.tar.gz.
File metadata
- Download URL: philiprehberger_api_timer-0.1.12.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c776036c6bac0e68289863b0cc4ef9afd18ef9eec2ca4fffdbc4f394f4846d59
|
|
| MD5 |
fad67dfd103bb884f6aff7b0b8bfa982
|
|
| BLAKE2b-256 |
fca94c6515e8db21ff944426bc39a83f21bcabb27ea6e41493310fb604f8ef3b
|
File details
Details for the file philiprehberger_api_timer-0.1.12-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_api_timer-0.1.12-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d62b317a76995345cfb65c83e9add1a6f24d1d777a65c3e25037704f5cbea51b
|
|
| MD5 |
5030d4394ed7eb5f291588fbdd17ce34
|
|
| BLAKE2b-256 |
dfec8218c61edad3cecc21baecefa6694084ff1f2eb46d456ccbacfc336482dc
|