skillfed

fastapi-profiler

A FastAPI Middleware of pyinstrument to check your service performance.

fastapi-profiler v1.5.0 200.8K downloads/30d#9,682 on PyPI365
Permissive license MIT Active released

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-profiler

uv

uv add fastapi-profiler

poetry

poetry add fastapi-profiler

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries

Tags

fastapi request profilingperformance monitoring middlewarepyinstrument fastapi integrationrequest latency profilingfastapi performance dashboardcall stack sampling fastapiservice performance analysis
profilingperformance-monitoringmiddleware

More Libraries packages