Skip to main content

Flask-MultiProfiler

A Flask extension that provides multi-dimensional profiling capabilities for Flask applications.

Features

  • Code profiling: Statistical profiling using pyinstrument to identify performance bottlenecks
  • SQL profiling: Database query profiling using sqltap to track query performance
  • Search profiling: Custom profiler for OpenSearch/Elasticsearch operations via trace logging

Installation

pip install flask-multiprofiler

For search profiling support, install with the appropriate extra:

# For OpenSearch
pip install flask-multiprofiler[opensearch]

# For Elasticsearch
pip install flask-multiprofiler[elasticsearch]

Quick Start

from flask import Flask
from flask_multiprofiler import MultiProfiler

app = Flask(__name__)
profiler = MultiProfiler(app)

# Or using the factory pattern
profiler = MultiProfiler()
profiler.init_app(app)

Usage

  1. Navigate to /profiler in your Flask application
  2. Start a profiling session by selecting which profilers to enable
  3. Use your application normally - profiling data is collected automatically
  4. View profiling reports through the web interface

Configuration

# Storage directory for profiling sessions (default: "{Flask.instance_path}/profiler")
MULTIPROFILER_STORAGE = "/path/to/storage"

# Logger name for search profiling (default: "opensearchpy.trace")
MULTIPROFILER_SEARCH_TRACE_LOGGER = "elasticsearchpy.trace"

# Session lifetime (default: 60 minutes)
MULTIPROFILER_ACTIVE_SESSION_LIFETIME = timedelta(minutes=30)

# Endpoints to ignore during profiling (regex patterns)
MULTIPROFILER_IGNORED_ENDPOINTS = ["static", r"profiler\..+", "api.health"]

# Permission function (default: lambda: True)
MULTIPROFILER_PERMISSION = lambda: current_user.is_admin

Development

This project uses uv for dependency management and just for task automation. Tests use testcontainers to run PostgreSQL and OpenSearch in Docker containers.

# Run tests
just test

# Run all code-quality checks
just check

Architecture

  • Each profiling session creates its own SQLite database for storing profiling reports in a self-contained HTML format
  • Profilers can be enabled/disabled individually per session
  • Web interface provides session management and report viewing

Search Profiler Compatibility

The search profiler currently supports:

  • OpenSearch client (opensearch-py)
  • Elasticsearch client v7.x only (elasticsearch~=7.17.12)

Both clients use the same logging mechanism (plain Python logger) for trace logging, which our profiler intercepts. Elasticsearch v8.x uses a different tracing approach and is not currently supported.

Future Development

Planned features and improvements:

  • Redis profiling: Track Redis operations and performance
  • Enhanced search query viewer: Improved visualization and analysis of search queries
  • SQL profiler rewrite: Replace sqltap with custom implementation to add stack traces and better integration

Non-Goals

This module intentionally keeps things simple and will not support:

  • Customizing rendering: Reports are stored as fully renderable HTML pages to keep complexity low
  • REST API: No plans to expose profiling data via API endpoint
  • Async support: Focused on traditional Flask applications only
  • Full type hints: Minimal type annotations to maintain simplicity
  • Translations/I18N: This is an sysadmin/developer interface

Metadata

Release files for flask-multiprofiler 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-multiprofiler 0.1.0
File Size Uploaded
flask_multiprofiler-0.1.0.tar.gz 24.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-multiprofiler 0.1.0
File Interpreter ABI Platform
flask_multiprofiler-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 58.5 kB

Release files / flask_multiprofiler-0.1.0.tar.gz

Download URL flask_multiprofiler-0.1.0.tar.gz
Size 24.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8ce585bbc458325dfc834de7a5094dbe39e3d1cbe6533115a65e8ee5fabf90eb
BLAKE2b-256 checksum
How to use checksums
454bbfac8a8625601878da56c900c38a9333c7d0d1701e8d6c3aa69f96fa6b66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / flask_multiprofiler-0.1.0-py3-none-any.whl

Download URL flask_multiprofiler-0.1.0-py3-none-any.whl
Size 34.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1eab18950be506d39bf5cadf17b951a669c6c4fc5fbcce6389b3f034bf21a74c
BLAKE2b-256 checksum
How to use checksums
29b35ce921d4a904080516b062cb682ec2b1bcdd4e634a24c83906d8387ca0a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page