Skip to main content

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)

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.8.tar.gz (3.4 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.8-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.8.tar.gz
Algorithm Hash digest
SHA256 a67c8e380930a3e49a7da7dcd6c92c13db503b0e16faa93ba15e9e9d48762ffc
MD5 0e8f65375a7c0127580f31cac9e2cec2
BLAKE2b-256 5a911b5f8b9e75bc9f57b48990adb0b239e2e1df8530ed8c05fe530b9b215b45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7926ef31248712025b336d685090fb228812d1c9392976d502f35dd144156da3
MD5 a2d523cfcf06cc10beba77b6597b8add
BLAKE2b-256 7c7ff662ac34797b662fdfd40e2f0f140e884f58d4eff3026c70a3b33f840a83

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