Version: 1.8.4.4
Flask-ProfilerForked measures the performance of your Flask application endpoints and provides detailed reports through a user-friendly web interface.
- Where are the bottlenecks in my application?
- Which endpoints are the slowest?
- What are the most frequently called endpoints?
- What causes slow performance?
- How long did a specific request take?
Flask-ProfilerForked allows you to monitor all your endpoints' performance and inspect incoming requests by drilling down through filters.
- More Modern UI
- Improved and Maintained Features
- Light and Dark Mode system
- Multiple Users System
- Update Checking
- Error Handing for Developers
- Less storage taken by the Profiler
- More modern UI
- Addition of user access levels
The dashboard provides a summary of the application’s performance:
You can apply filters to investigate specific requests:
To install Flask-ProfilerForked, use:
pip install Flask-ProfilerForked
For the latest development version, use:
pip install git+https://github.com/Kalmai221/flask-profiler@master
Here’s an example Flask application using Flask-ProfilerForked:
# app.py
from flask import Flask
import flask_profiler
app = Flask(__name__)
app.config["DEBUG"] = True
# Flask-Profiler configuration
app.config["flask_profiler"] = {
"enabled": app.config["DEBUG"],
"storage": {
"engine": "sqlite"
},
"basicAuth": {
"enabled": True,
"users": {
"1": {
"username": "admin",
"password": "password",
"role": "admin"
},
"2": {
"username": "user",
"password": "password",
"role": "user"
}
}
},
"features": {
"filtering":{
"enabled": True,
"role": "user"
},
"emulation": {
"enabled": True,
"role": "admin"
}
},
"ignore": [
"^/static/.*"
],
"updateCheck": False
}
@app.route('/product/<id>', methods=['GET'])
def get_product(id):
return f"Product ID is {id}"
# Activate flask-profiler
flask_profiler.init_app(app)
# Profile specific endpoint
@app.route('/doSomethingImportant', methods=['GET'])
@flask_profiler.profile()
def do_something_important():
return "This endpoint is being profiled."
if __name__ == '__main__':
app.run(host="127.0.0.1", port=5000)
Flask-ProfilerForked supports SQLite, MongoDB, PostgreSQL, MySQL, and more. Here's how to set up some of the common database engines:
app.config["flask_profiler"] = {
"storage": {
"engine": "sqlite",
}
}
Key | Description | Default Value |
---|---|---|
storage.FILE |
SQLite database file name | flask_profiler.sql |
storage.TABLE |
Table name to store profiling data | measurements |
app.config["flask_profiler"] = {
"storage": {
"engine": "mongodb",
}
}
Key | Description | Default Value |
---|---|---|
storage.MONGO_URL |
MongoDB connection string | mongodb://localhost |
storage.DATABASE |
Database name | flask_profiler |
storage.COLLECTION |
Collection name | measurements |
You can specify a custom storage engine as follows:
app.config["flask_profiler"] = {
"storage": {
"engine": "custom.project.flask_profiler.mysql.MysqlStorage",
"MYSQL": "mysql://user:password@localhost/flask_profiler"
}
}
You can control the number of samples taken with a custom sampling_function
. Here are two examples:
Random Sampling (1 in 100 requests):
import random
app.config["flask_profiler"] = {
"sampling_function": lambda: True if random.randint(1, 100) == 42 else False
}
Sample Specific Users:
app.config["flask_profiler"] = {
"sampling_function": lambda: True if user == 'admin' else False
}
By default, Flask-Profiler is available at /profiler
. To change this:
app.config["flask_profiler"] = {
"endpointRoot": "custom-profiler-root"
}
To ignore specific endpoints from being tracked, use regex patterns:
app.config["flask_profiler"] = {
"ignore": [
"^/static/.*",
"/api/users/\w+/password"
]
}
Contributions are welcome! Review the Contributing Guidelines for more details on:
- Submitting issues
- Contributing solutions
- Adding new features
MIT