Skip to main content

Detect event-loop blocking in FastAPI/Starlette with per-request attribution

Project description

LoopGuard

Catch event-loop blocking in FastAPI with per-request attribution.

PyPI version Python 3.12+ License: MIT


When a request blocks your event loop (via time.sleep(), blocking I/O, or CPU work), LoopGuard detects it and tells you which endpoint caused it.

Install

pip install fastapi-loopguard

Quick Start

from fastapi import FastAPI
from fastapi_loopguard import LoopGuardMiddleware

app = FastAPI()
app.add_middleware(LoopGuardMiddleware)

Enforcement Modes

Mode Behavior Use Case
"warn" Console warnings + headers Default
"strict" HTTP 503 + error page Development / CI
"log" Silent logging Production
from fastapi_loopguard import LoopGuardConfig

# Development: strict enforcement (503 on blocking)
config = LoopGuardConfig(dev_mode=True)

# Production: silent logging
config = LoopGuardConfig(enforcement_mode="log")

app.add_middleware(LoopGuardMiddleware, config=config)

What You Get

Strict Mode

Returns an educational 503 page that explains what went wrong and how to fix it:

Strict mode error page


Warn Mode

Adds diagnostic headers to every response for debugging:

Warn mode headers


Log Mode

Writes structured logs with full request attribution:

Console output


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

fastapi_loopguard-0.4.0.tar.gz (367.1 kB view details)

Uploaded Source

Built Distribution

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

fastapi_loopguard-0.4.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_loopguard-0.4.0.tar.gz.

File metadata

  • Download URL: fastapi_loopguard-0.4.0.tar.gz
  • Upload date:
  • Size: 367.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastapi_loopguard-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1c265cef0deede11a101ee9254b634d4c4a8964544475eb60a7a25315a0af561
MD5 3a6d2fdc28ef2046b473a149c80f23ac
BLAKE2b-256 b56914c41e96f1937d35886fc74f3585d633c9b0956360401200896e38835002

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_loopguard-0.4.0.tar.gz:

Publisher: publish.yml on parhamdavari/fastapi-loopguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_loopguard-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_loopguard-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8123290ae8cffbb69300f8e326dd861abe7efde8e5f4cc7f5e8e64fa15df1f5
MD5 cf2e1c75c0cf0f0d92f8045b0764dcd3
BLAKE2b-256 a9248ae37766dfd5210ebbce0627e8b54e23222a19f30e6c8b034d104d86500b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_loopguard-0.4.0-py3-none-any.whl:

Publisher: publish.yml on parhamdavari/fastapi-loopguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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