Skip to main content

Logging and observability helpers for FastAPI applications.

Project description

fastapi-inspector

Structured logging and observability middleware for FastAPI applications.

Test coverage pypi package python

Documentation · Changelog · Contributing


Features

  • Zero-boilerplate middleware — one line to log every request and response
  • Structured events — typed LogEvent objects 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_observer 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_observer import ObserverConfig, ObserverMiddleware, build_dashboard_app
from fastapi_observer.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_observer 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_observer --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

fastapi_inspector-0.1.0.tar.gz (21.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_inspector-0.1.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_inspector-0.1.0.tar.gz.

File metadata

  • Download URL: fastapi_inspector-0.1.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for fastapi_inspector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e7d3ccc350b1135e1dda3219e743df57da034725cde17d98aa12f721102cfab
MD5 23ef878379c4044381350bef4238d7d2
BLAKE2b-256 1e2b6ad0ae7a0378065b3dbd337ab4044d5828792e881c1475ea965b27fe55f2

See more details on using hashes here.

File details

Details for the file fastapi_inspector-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_inspector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c02a71d2f8ee31d513d55cdc1e9e978f105acb47839f5c6d02366c6da7db041
MD5 0f5a2f98bc6e0bdd7932b2be86d1722b
BLAKE2b-256 51f433b922c1b38d838a9286e0904ec9079bfa60d35fa690ad6d02504060cf08

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