Skip to main content

fastapi-insights is a FastAPI extension that tracks request and system metrics and provides a built-in dashboard.

Project description

fastapi-insights

Dashboard Screenshot

Introduction

fastapi-insights is a FastAPI extension for application performance monitoring. It tracks request and system metrics using lightweight middleware. Metrics can be stored in in-memory, SQLite, or Redis backends and visualized in a built-in dashboard UI.

Who is it for?

  • Developers who want a metrics dashboard without running a full Prometheus + Grafana stack.
  • Indie devs or small teams running single-instance FastAPI backends who just need lightweight insights.

Features

  • 🚀 Zero-config FastAPI middleware
  • 🗄 Multiple storage backends: in-memory, SQLite, Redis
  • 💻 Built-in dashboard UI with charts
  • ⚡ Lightweight & async-first design
  • 🔌 Configurable retention, bucket sizes, and cleanup

Installation

> pip install fastapi-insights

Optional dependencies:

> pip install "fastapi-insights[redis]"

Supported Python versions: 3.10+

Development

Install dev dependencies and set up pre-commit hooks:

> uv sync --dev
> uv run pre-commit install

Run the checks manually at any time with:

> uv run pre-commit run --all-files

Quick Start

Check the examples folder for more.

from fastapi import FastAPI
from fastapi_insights import FastAPIInsights, Config
from fastapi_insights.backends.in_memory import InMemoryMetricsStore

app = FastAPI()

FastAPIInsights.init(
    app,
    InMemoryMetricsStore(),
    config=Config(),
)

@app.get("/")
def index():
    return "ok"

Visit /metrics to view the UI.

Backends

In-Memory (default)

from fastapi_insights.backends.in_memory import InMemoryMetricsStore
store = InMemoryMetricsStore()

Redis

from fastapi_insights.backends.redis import AsyncRedisMetricsStore, RedisMetricsStore

# sync
import redis

redis_client = redis.Redis(host="localhost", port=6379, db=0)
store = RedisMetricsStore(redis_client)

# async
import redis.asyncio as async_redis

async_redis_client = async_redis.Redis(host="localhost", port=6379, db=0)
async_store = AsyncRedisMetricsStore(async_redis_client)

SQLite

from fastapi_insights.backends.sqlite import SQLiteMetricsStore
store = SQLiteMetricsStore("metrics.db")

The SQLite backend uses the standard library sqlite3 module, so no extra dependency is required.

Configuration

You can customize the behavior by adjusting the Config options at initialization.

Example

from fastapi_insights import Config

config = Config(
    ignored_routes=["/health", "/internal/*"],
    exclude_library_metrics=True,
    ui_config_route="/config-b887e852-bd12-41f2-b057-1bd31eb5443e",
    enable_dashboard_ui=True,
    custom_path="/metrics",
    include_in_openapi=False,
    ui_title="FastAPI Metrics"
)

Available Options

Option Type Default Description
ignored_routes list[str] [] Routes to be ignored by the metrics middleware. Use exact matches like /route, or wildcard matches like /route/* for prefixes.
exclude_library_metrics bool True If True, excludes internal fastapi-insights endpoints from being tracked.
ui_config_route str "/config-b887e852-bd12-41f2-b057-1bd31eb5443e" Internal route used to serve the dashboard’s configuration JSON. Should generally be left unchanged.
enable_dashboard_ui bool True Enables or disables the built-in dashboard UI. When disabled, only raw metrics endpoints remain active.
custom_path str "/metrics" The URL path under which metrics are exposed (e.g., /metrics or /stats).
include_in_openapi bool False Whether to include the metrics endpoints in your FastAPI OpenAPI schema (Swagger UI).
ui_title str "FastAPI Metrics" The title displayed in the dashboard UI.

Development

git clone https://github.com/HamzaDLM/fastapi-insights
cd fastapi-insights
uv sync
uv run pytest

Limitations

  • Best suited for single-instance FastAPI deployments or small teams that want an embedded dashboard.
  • Not a replacement for a full metrics pipeline such as Prometheus + Grafana in larger distributed systems.
  • The in-memory backend is process-local and not durable across restarts.

License

This project is licensed under the Apache-2.0 License.

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_insights-0.1.2.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

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

fastapi_insights-0.1.2-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file fastapi_insights-0.1.2.tar.gz.

File metadata

  • Download URL: fastapi_insights-0.1.2.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastapi_insights-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1c9bd69beaddb1ab6759a20869bf7553144c9a65370ad4b2371e422a335411fe
MD5 87c5028d36f680be577e03c996767fcb
BLAKE2b-256 9e8038ed1670bec9bd23b1995bb6ed76784962e9d9d14775baabc29b45179eb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_insights-0.1.2.tar.gz:

Publisher: release.yml on HamzaDLM/fastapi-insights

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_insights-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_insights-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ea548bc43870aff83cdfe3c92dad9fe7e89411e7cb94886ff212f428be0faabb
MD5 22a24f2ef5e132c61aefe6c54eb273a1
BLAKE2b-256 aed71492b1350ffd308373543202bb14dcf64650fd6b37e361a3b8c98eb7b56d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_insights-0.1.2-py3-none-any.whl:

Publisher: release.yml on HamzaDLM/fastapi-insights

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