Skip to main content

Drop-in ASGI/WSGI middleware for endpoint timing

Project description

philiprehberger-api-timer

Tests PyPI version License

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)

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

Development

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_api_timer-0.1.9.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_api_timer-0.1.9-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_api_timer-0.1.9.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.9.tar.gz
Algorithm Hash digest
SHA256 79d6a97770fdc26403b53cc95013e51a91d6436ad4a43703782570bfed06b127
MD5 fda4e706b96e7a35d62e7e91a8f79a3a
BLAKE2b-256 5ca3819ea0019ec5f4cea5c5b81196a6ae0cc28612620abcfd38a6c0502c3e0b

See more details on using hashes here.

File details

Details for the file philiprehberger_api_timer-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6dad4f0cca2836b6de8295c59c4548f61572cad3c88e4184393417c2f9e0de72
MD5 7e49ab9a6bf0636794b07929eab600e0
BLAKE2b-256 9d11df828e71c1cc1bbc337ea3811bf61a6bb690deaef35f5e09da895012dd4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page