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


Full Configuration Reference

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.1.tar.gz (368.4 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.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_loopguard-0.4.1.tar.gz
  • Upload date:
  • Size: 368.4 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.1.tar.gz
Algorithm Hash digest
SHA256 ab23b938505ccd2b400cfedee84b8c296fd3406078da2b2d2e0d57a5dadbad96
MD5 b41822163fa6842bc27c2c4335ef0c7c
BLAKE2b-256 489660f5308613a9a20a6136753ee20b3782f5c54ec341a0dc81a07da1e8c9bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_loopguard-0.4.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_loopguard-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d5aa8dc4fb7c4830f9b735e912f59625bc15667db417834a5fc814b55717daf
MD5 df4b8ae25b52788ac4c3fc06f46ebcff
BLAKE2b-256 1806443b409b644e6fde072709c682a0414fbe958d78f73ac88ea4acb4c7d116

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_loopguard-0.4.1-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