Detect event-loop blocking in FastAPI/Starlette with per-request attribution
Project description
Catch event-loop blocking in FastAPI with per-request attribution.
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:
Warn Mode
Adds diagnostic headers to every response for debugging:
Log Mode
Writes structured logs with full request attribution:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c265cef0deede11a101ee9254b634d4c4a8964544475eb60a7a25315a0af561
|
|
| MD5 |
3a6d2fdc28ef2046b473a149c80f23ac
|
|
| BLAKE2b-256 |
b56914c41e96f1937d35886fc74f3585d633c9b0956360401200896e38835002
|
Provenance
The following attestation bundles were made for fastapi_loopguard-0.4.0.tar.gz:
Publisher:
publish.yml on parhamdavari/fastapi-loopguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_loopguard-0.4.0.tar.gz -
Subject digest:
1c265cef0deede11a101ee9254b634d4c4a8964544475eb60a7a25315a0af561 - Sigstore transparency entry: 794054451
- Sigstore integration time:
-
Permalink:
parhamdavari/fastapi-loopguard@48b25393b8104c72fc322e66ba94b6845a66000f -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/parhamdavari
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@48b25393b8104c72fc322e66ba94b6845a66000f -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_loopguard-0.4.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_loopguard-0.4.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8123290ae8cffbb69300f8e326dd861abe7efde8e5f4cc7f5e8e64fa15df1f5
|
|
| MD5 |
cf2e1c75c0cf0f0d92f8045b0764dcd3
|
|
| BLAKE2b-256 |
a9248ae37766dfd5210ebbce0627e8b54e23222a19f30e6c8b034d104d86500b
|
Provenance
The following attestation bundles were made for fastapi_loopguard-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on parhamdavari/fastapi-loopguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_loopguard-0.4.0-py3-none-any.whl -
Subject digest:
d8123290ae8cffbb69300f8e326dd861abe7efde8e5f4cc7f5e8e64fa15df1f5 - Sigstore transparency entry: 794054518
- Sigstore integration time:
-
Permalink:
parhamdavari/fastapi-loopguard@48b25393b8104c72fc322e66ba94b6845a66000f -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/parhamdavari
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@48b25393b8104c72fc322e66ba94b6845a66000f -
Trigger Event:
push
-
Statement type: