Flask-Perf
A simple Flask extension for profiling your application code and database queries.
Installation
$ pip install flask_perf
Example
from flask import Flask, jsonify
from flask_perf import Profiler
app = Flask(__name__)
app.config["PROFILER_ENABLED"] = True
profiler = Profiler(app) # or profiler.init_app(app)
@app.route("/")
def index():
return jsonfiy({
"message": "Hello World!"
})
Configuration
Config Name | Description | default |
---|---|---|
PROFILER_ENABLED |
Enable the profiler. | False |
PROFILER_RESTRICTIONS |
List of profiler restrictions, described in depth in the Official Python Docs | [] |
PROFILER_SQLALCHEMY_ENABLED |
Enable SQLAlchemy query logging. Note: This option requires that the flask_sqlalchemy package is installed and the SQLALCHEMY_RECORD_QUERIES config option is set to True . |
False |
PROFILER_SQLALCHEMY_THRESHOLD |
Minimum query duration in seconds to log. | 0 |
PROFILER_SQLALCHEMY_FORMAT |
Logged SQLAlchemy query format. See the Flask-SQLAlchemy docs for a list of attributes you can use in this format string. | "\n\n{duration:1.2e}s\n\n{statement}\n" |