Flask Pythonbeta

Our Flask integration lets you instrument individual HTTP requests by adding a dedicated WSGI middleware to your application.

Installation

Wrap your application with FlaskMiddleware (the code is part of the blackfire package when you install Blackfire for Python):

1
2
3
4
5
6
7
8
from flask import Flask
app = Flask(__name__)

from blackfire.middleware import FlaskMiddleware

app.wsgi_app = FlaskMiddleware(app)

# You can now define your routes and controllers

Caution

When chaining WSGI middleware, the order is important. You should include Blackfire as early as possible in the list. However, it must come after any response content encoders (such as gzip for example).

Profiling HTTP Requests

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.