Installing Airbrake in a Flask app

python flag

Features

Step 1: Install the latest version of pybrake

Airbrake for Flask uses our official Python notifier pybrake. To install run:

pip install -U pybrake

Step 2: Configure the Airbrake Flask middleware

Replace the placeholder project_id and project_key values from the example below with the real values from your project’s setting page.

Note: Flask integration uses Flask signals and therefore requires the blinker library.

from flask import Flask
import pybrake.flask

app = Flask(__name__)

app.config['PYBRAKE'] = dict(
    project_id=123,
    project_key='FIXME',
)
app = pybrake.flask.init_app(app)

Sending errors to Airbrake

try:
    raise ValueError('hello')
except Exception as err:
    notifier.notify(err)

For more information, check out pybrake’s official GitHub repo.