Logging and observability helpers for FastAPI applications.
Project description
fastapi-inspector
Structured logging and observability middleware for FastAPI applications.
Documentation · Changelog · Contributing
Features
- Zero-boilerplate middleware — one line to log every request and response
- Structured events — typed
LogEventobjects with method, path, status code, latency, and more - Pluggable storage — in-memory, JSON file, JSON Lines, or SQLite backends
- Filter pipeline — drop health-check noise, log only errors, or set a minimum latency threshold
- Built-in dashboard — mount an event-inspector UI at any path in your app
- Multiple formatters — plain-text or JSON output
- Python 3.10–3.14 with full CI coverage across all versions
Install
pip install fastapi-inspector
Quick start
Basic logging
from fastapi import FastAPI
from fastapi_inspector import ObserverConfig, ObserverMiddleware
app = FastAPI()
app.add_middleware(ObserverMiddleware, config=ObserverConfig())
@app.get("/items")
async def list_items():
return {"items": ["alpha", "beta", "gamma"]}
Every request is now logged to the console with method, path, status code, and latency.
Persist events and open the dashboard
from fastapi import FastAPI
from fastapi_inspector import ObserverConfig, ObserverMiddleware, build_dashboard_app
from fastapi_inspector.storage import InMemoryEventStore
app = FastAPI()
store = InMemoryEventStore()
app.add_middleware(ObserverMiddleware, config=ObserverConfig(), storage=store)
app.mount("/dashboard", build_dashboard_app(store, title="Observer Dashboard"))
Open http://localhost:8000/dashboard to browse and inspect logged events.
Filter out noise
from fastapi_inspector import ObserverConfig, ObserverMiddleware, only_errors, min_duration_ms
app.add_middleware(
ObserverMiddleware,
config=ObserverConfig(handlers=["console"], log_format="json"),
event_filters=[
only_errors, # log 4xx/5xx responses only
min_duration_ms(50.0), # ignore fast responses
],
)
See the examples/ directory for more patterns including SQLite storage and custom filters.
Storage backends
| Backend | Class | Use case |
|---|---|---|
| In-memory | InMemoryEventStore |
Development, testing |
| JSON file | JsonFileEventStore |
Simple persistence |
| JSON Lines | JsonLinesEventStore |
Append-only log files |
| SQLite | SQLiteEventStore |
Queryable local storage |
Python compatibility
- Supported versions:
3.10,3.11,3.12,3.13,3.14 - Enforced in CI with a tox matrix across all versions
Development
Install all dependencies:
pip install -e ".[test,docs,dev]"
pre-commit install
Run tests:
pytest -q
pytest -q --cov=fastapi_inspector --cov-report=term-missing # with coverage
tox # full version matrix
Build and preview docs:
mkdocs serve # http://127.0.0.1:8000
mkdocs build --strict
See CONTRIBUTING.md for the full contribution guide.
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
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_inspector-0.2.1.tar.gz.
File metadata
- Download URL: fastapi_inspector-0.2.1.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7847e9bf9ea6612b9940d9a0aae3af87aa2a2aaa9c6cf8b724ceced40bb75ad5
|
|
| MD5 |
9f153c8659246222e73ab2e990a8efcd
|
|
| BLAKE2b-256 |
cbcc6589eb5d4b6e7b86192282851b853287c1015f762a7bdd2cabfe5085ccda
|
Provenance
The following attestation bundles were made for fastapi_inspector-0.2.1.tar.gz:
Publisher:
publish.yml on MehrazRumman/fastapi-observer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_inspector-0.2.1.tar.gz -
Subject digest:
7847e9bf9ea6612b9940d9a0aae3af87aa2a2aaa9c6cf8b724ceced40bb75ad5 - Sigstore transparency entry: 1388790293
- Sigstore integration time:
-
Permalink:
MehrazRumman/fastapi-observer@f7f991130f0cbea1d456ed991bd64f2b9fb11963 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/MehrazRumman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7f991130f0cbea1d456ed991bd64f2b9fb11963 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_inspector-0.2.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_inspector-0.2.1-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebc70be80feab7fdac356e89530dde465c93c07d2d402a067c379a46c76547d7
|
|
| MD5 |
11304cd99a91c6b7189d83b907445434
|
|
| BLAKE2b-256 |
99ee2d00558584ebea7ede9048b319b3551a65103121406e29f6e9703e351775
|
Provenance
The following attestation bundles were made for fastapi_inspector-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on MehrazRumman/fastapi-observer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_inspector-0.2.1-py3-none-any.whl -
Subject digest:
ebc70be80feab7fdac356e89530dde465c93c07d2d402a067c379a46c76547d7 - Sigstore transparency entry: 1388790433
- Sigstore integration time:
-
Permalink:
MehrazRumman/fastapi-observer@f7f991130f0cbea1d456ed991bd64f2b9fb11963 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/MehrazRumman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7f991130f0cbea1d456ed991bd64f2b9fb11963 -
Trigger Event:
push
-
Statement type: