Skip to content

moisesbenzan/python-sdk

 
 

Repository files navigation

Blackfire SDK for Python

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.

Installation

Please follow the official Blackfire Installation Guide.

Usage

These examples and more can be found on the official Blackfire Python SDK documentation

Manual profiling

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 servers

You can view your profiles here: https://blackfire.io/my/profiles

Aggregation of Traces

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()

Profiling Python scripts via CLI

Save below as foo.py:

def foo():
    print('foo called!')

foo()

Then run following:

blackfire run python foo.py

Above command will run your script till end and uploads the profile payload to https://blackfire.io/my/profiles

Profiling Django via Middleware

Read the Django Integration documentation on the Blackfire website.

  1. Install the Blackfire Browser Extension.

  2. Add Blackfire middleware in your Django settings.py as following:

    MIDDLEWARE = [
        ...
        ...
        'blackfire.middleware.DjangoMiddleware',
    ]
  3. Follow these steps to profile via Browser.

Resources

About

The Blackfire Python SDK https://blackfire.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%