Our Flask integration lets you instrument individual HTTP requests. Please note that Blackfire supports Flask 0.12 and higher.
The recommended way to use Blackfire with Flask is to use the blackfire-python command, as it configures the needed bits for you.
Run your webserver with blackfire-python
command:
1 2
export FLASK_APP=hello.py
blackfire-python flask run
Or with gunicorn
:
1
blackfire-python gunicorn myproject:app
If you prefer configuring Flask manually, you can add the following call manually within your code:
1 2
import blackfire
blackfire.patch_all()
This call should be made as early as possible in the lifecycle of an application,
ideally before any otherimport
statements.
Then, restart your server.
We used to provide a Flask middleware along with the Blackfire Python SDK,
blackfire.middleware.FlaskMiddleware
.
This middleware is now deprecated in favor of the blackfire-python
or the
blackfire.patch_all()
call.
Using the middleware will trigger a deprecation warning.
You can use the blackfire curl
command to profile specific requests:
1
blackfire curl http://localhost:5000/
You can also use one of our browser extensions for Firefox or Chrome.
Read more about profiling web applications with a browser, or profiling with the CLI.