Introducing blackfire-python command
Python developers, benefit from an improved developer-experience with our new blackfire-python command!
Today I would like to announce a new step forward in the developer experience by introducing the
Make the Python Probe Easier to Use
If you are a Python developer using Django or Flask, you are probably used to manipulating middleware. While this concept helps you stay in control of your application’s behavior, it can become cumbersome. You need to explicitly modify your application settings in order to enable or disable some middleware. This is specifically the case when you want to use low-level tools like Blackfire, which won’t affect your application per se.
In order to simplify and to unify the developer experience, we introduced a new command:
blackfire-python. This command does the dirty work for you, by adding the appropriate middleware in the appropriate position. The result is that, when using this command, your web application will automatically detect incoming profile requests and activate the probe when needed, without impacting regular requests.
To use it, prepend your python commands by
# With Django development server blackfire-python python manage.py runserver # With Django using gunicorn webserver blackfire-python gunicorn myapp.wsgi # With Flask development server export FLASK_APP=hello.py blackfire-python flask run
Note that, at the time of writing this article, only Django and Flask are supported by
Django and Flask middleware for Blackfire are now deprecated and will raise a warning if you try to use them.
You may use
Running CLI Commands
blackfire-python command is not only about web requests…
In the past, in order to trigger profiles with Python CLI commands using
blackfire run, a site-specific configuration hook,
blackfire_bootstrap.pth, used to be needed.
This is not needed anymore, as you can now profile CLI scripts by using the
blackfire-python run command:
blackfire-python run python my_script.py
blackfire-python run wraps the
blackfire run command and ensures that the probe is properly activated.
If you previously installed the
blackfire_bootstrap.pth script, you must uninstall it before using
python -m blackfire uninstall-bootstrap
Want to give it a try?
It is now way easier to get started with Blackfire on Python, so what about giving it a try?
- If you don’t have an account yet, create one for free
- Benefit from our quick install process
- If need be, find more advanced settings for Django and other Python apps
- Check out our SDK!
Happy Python Profiling!