fastapi-profiler
A FastAPI Middleware of pyinstrument to check your service performance.
What it is and what it does
fastapi-profiler wraps your FastAPI application with a middleware layer that uses pyinstrument to sample and measure the execution time of each request's call stack. It captures which functions consume the most time and reports results in multiple formats (text, HTML, JSON, prof, speedscope). The middleware supports sampling rate control to reduce overhead in production, threshold-based filtering to profile only slow requests, and structured JSON logging for integration with log aggregation systems.
The package includes a built-in web dashboard that displays per-route statistics (p95/p99 latencies, error counts, averages) and exposes APIs to toggle profiling on and off at runtime without restarting. You can exclude certain URL paths from profiling, automatically profile all 5xx errors regardless of sampling settings, and keep a rolling history of profiles per route for later inspection.
Use it for:
- Identify performance bottlenecks in FastAPI endpoints by examining call trees and function-level timing data.
- Monitor production services with low-overhead sampling to detect slow requests without profiling every call.
- Generate HTML reports of request profiles for sharing with team members or archiving for later analysis.
- Use the dashboard to view live per-route statistics and toggle profiling on/off without redeploying.
- Automatically capture profiles of failed requests (5xx errors) to diagnose error-path performance issues.
- Export profiles in speedscope format for visualization in external performance analysis tools.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Integrates pyinstrument profiling into FastAPI as middleware to measure per-request performance with configurable sampling, thresholds, and output formats.
Yes. The package is actively maintained, has no security vulnerabilities, installs with minimal friction, and solves a concrete problem—profiling FastAPI request performance—with flexible configuration for both development and production use. The permissive MIT license removes any licensing concern. Install it if you need per-request profiling or a runtime-configurable performance dashboard for FastAPI.
Install
fastapi-profiler on PyPI
pip
pip install fastapi-profileruv
uv add fastapi-profilerpoetry
poetry add fastapi-profilerInstalling fastapi-profiler
Before you install
Low friction: pure-Python wheel with only two runtime dependencies (fastapi and pyinstrument). Active maintenance with recent release and no known vulnerabilities.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions.
Quickstart
pip install fastapi-profiler
from fastapi import FastAPI
from fastapi_profiler import PyInstrumentProfilerMiddleware
app = FastAPI()
app.add_middleware(PyInstrumentProfilerMiddleware)
# Requests are now profiled and printed to stdout
Verify before relying
- Overhead impact of profiling on production throughput at various sampling rates
- Memory consumption when storing per-route profile history with max_profiles_per_route set high
- Dashboard performance under high request volume
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — fastapi, pyinstrument |
| Maintenance | actively maintained — 143 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 200,822/month — #9,682 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fastapi_profiler-1.5.0-py3-none-any.whl
Keywords: fastapi, pyinstrument, profiler
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
pyinstrumentPyinstrument is a statistical call-stack…
permissive · top 5,000 on PyPI
django-cprofile-middlewareMiddleware that profiles Django view execution…
permissive · top 15,000 on PyPI
yappiYappi is a deterministic profiler for Python…
permissive · top 5,000 on PyPI
py-spypy-spy is a sampling profiler that attaches to…
permissive · top 1,000 on PyPI
pytest-profilingPytest plugin that profiles test execution…
permissive · top 5,000 on PyPI
pyroscope-ioPyroscope-io is a continuous profiling agent…
permissive · top 5,000 on PyPI
line-profilerline_profiler measures execution time on a…
permissive · top 5,000 on PyPI
starlette-exporterCollects and exports Prometheus metrics for…
permissive · top 5,000 on PyPI
tunatuna visualizes Python performance profiles in…
copyleft · top 15,000 on PyPI
PymplerPympler measures, monitors, and analyzes memory…
permissive · top 5,000 on PyPI