Blackfire Python SDK is a Python library that manages the Blackfire Python Profiler and handles communication with Blackfire.io servers.
Read the official Blackfire documentation for more information.
Please follow the official Blackfire Installation Guide.
These examples and more can be found on the official Blackfire Python SDK documentation.
Following is an example of manual profiling:
from blackfire import probe
probe.initialize(client_id='xxxxx', client_token='xxxxx')
probe.enable()
foo()
bar()
baz()
probe.end() # this will send all collected data Blackfire.io serversYou can view your profiles here on your dashboard.
We can call enable()/disable() multiple times until we finally
call end().
from blackfire import probe
probe.initialize()
probe.enable()
foo()
probe.disable()
probe.enable()
bar()
probe.disable()
with probe.run():
baz()Save below as foo.py:
def foo():
print('foo called!')
foo()Then run following:
blackfire run python foo.pyAbove command will run your script till end and uploads the resulting profile to Blackfire. You profile will be available on your dashboard.
Read the Django Integration documentation on the Blackfire website.
Install the Blackfire Browser Extension.
Add Blackfire middleware in your Django
settings.pyas following:MIDDLEWARE = [ ... ... 'blackfire.middleware.DjangoMiddleware', ]
Follow these steps to profile via Browser.