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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b4688634c4c98cbd52a78721edbd113402d0a0a44add260e9ba52ed54c39ffbd
MD5 56dd41c9aaabe28c6733db97a7b68e9b
BLAKE2b-256 e89baa754ce0447dad5bab6baf83d27416cbf3812fdc4070e1f38756bb95fa44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_api_timer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 728e216ec39583374f1cd88d8748c28bccf880b3271bf74aee67a5f0c20430ab
MD5 d73fe426325b95a6185e13b532d25e6e
BLAKE2b-256 6bc8e4c399ffeca65d08b6c5e920be95b345110e69114d5c74ad557ca9b6627d

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