Skip to main content

Lightweight performance profiler for FastAPI applications

Project description

FastAPI Profiler Lite

FastAPI Profiler Lite Logo

PyPI version License GitHub stars CI Status Release Status

A lightweight, zero-configuration performance profiler for FastAPI applications. Monitor your API performance in real-time without external dependencies.

Dashboard Demo

Why FastAPI Profiler?

Monitoring API performance shouldn't require complex setups or external services. FastAPI Profiler gives you instant visibility into your application's performance with just one line of code.

  • Instant insights - See which endpoints are slow without complex instrumentation
  • Zero configuration - Works out of the box with sensible defaults
  • Rust-powered statistics - High-performance stats calculation using Rust
  • Developer-friendly - Designed for both development and lightweight production use

Installation

pip install fastapi-profiler-lite

For more installation options, see the Installation Guide.

Quick Start

from fastapi import FastAPI
from fastapi_profiler import Profiler

app = FastAPI()

# Add the profiler with just one line
Profiler(app)

@app.get("/")
async def read_root():
    return {"Hello": "World"}

That's it! Visit /profiler to see the performance dashboard.

Features

  • One-line integration - Add to any FastAPI app with minimal code
  • Real-time dashboard - Live updates with automatic refresh
  • Response time tracking - Measure execution time of each request
  • Endpoint analysis - Identify your slowest and most used endpoints
  • Request filtering - Search and sort through captured requests
  • Visual metrics - Charts for response times and request distribution
  • Database monitoring - Tracking of SQLAlchemy queries
  • Minimal overhead - Designed to have low performance impact

Technical Details

  • Rust Core: Statistics calculations are powered by a Rust extension using PyO3 for improved performance. Benchmarks comparing to NumPy will be published soon. Pre-built wheels are provided for all major platforms, but if you encounter any issues, please open a GitHub issue.

  • UI Framework: The dashboard uses Tabler.io, a premium and open-source admin dashboard template, providing a clean and modern interface.

  • Database Instrumentation: Track database queries with SQLAlchemy integration. Manually instrument your SQLAlchemy engines to see detailed query performance data.

Running Examples

The repository includes several examples to demonstrate different features:

# Basic example with simple endpoints
python example.py

# Example with SQLAlchemy database instrumentation
python examples/sqlalchemy_demo.py

# Example with multiple database engines
python examples/multi_db_demo.py

# Real-time continuous monitoring demo
python examples/realtime_demo.py

# Stress test with high load
python examples/stress_test.py

Database Instrumentation Example

To manually instrument database engines:

from fastapi import FastAPI
from sqlalchemy import create_engine
from fastapi_profiler import Profiler
from fastapi_profiler.instrumentations import SQLAlchemyInstrumentation

app = FastAPI()

# Create SQLAlchemy engines
primary_db = create_engine("sqlite:///./primary.db")
analytics_db = create_engine("sqlite:///./analytics.db")

# Initialize profiler
profiler = Profiler(app)

# Manually instrument each database engine
SQLAlchemyInstrumentation.instrument(primary_db)
SQLAlchemyInstrumentation.instrument(analytics_db)

Visit /profiler to see the dashboard with database query performance data.

Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_profiler_lite-0.3.4.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

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

fastapi_profiler_lite-0.3.4-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_profiler_lite-0.3.4.tar.gz.

File metadata

  • Download URL: fastapi_profiler_lite-0.3.4.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for fastapi_profiler_lite-0.3.4.tar.gz
Algorithm Hash digest
SHA256 99c131e1fb9274b017d09fc4dcd8286660a3649653cd52f1605116ad1568a920
MD5 20e8e46756f8f4ede288377991ca2a89
BLAKE2b-256 f495f4a14f1ed5064a48ce0cecbcd880832eb9df305bd65051e54b2136118bbb

See more details on using hashes here.

File details

Details for the file fastapi_profiler_lite-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: fastapi_profiler_lite-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for fastapi_profiler_lite-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 be49a1cbf57d65a9567064b0326c14aeb95c7a97d8ba57718c008863730b0f69
MD5 0f82a7f523cb676b3378ecf852509a34
BLAKE2b-256 f8beb8cea774efac5f7503a21d25b2020d0bfb609449c5605303d975608d203f

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