Installing Airbrake in a Python app

python flag

Features

  • Simple to install and configure
  • Integrates with your existing logger
  • Add extra context to errors before they are sent
  • Set error severity and control notification thresholds
  • Compatible with Airbrake On-Premise

What version of Python are you using?

The version of Python your app is using determines which installation instructions to follow.

Installation

The pybrake notifier supports Python 3.4 and above.

pip install -U pybrake

Configuration

You must set both project_id & project_key.

To find your project_id and project_key navigate to your project’s Settings and copy the values from the right sidebar.

import pybrake

notifier = pybrake.Notifier(project_id=123,
                            project_key='FIXME',
                            environment='production')

Sending errors to Airbrake

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

Taking pybrake further

Now that pybrake is configured and ready to go we recommend you check out some of the additional integrations and features pybrake supports:

Visit the pybrake GitHub repo for full details.

Manual configuration

Or, you can manually instantiate your AirbrakeHandler by passing your PROJECT ID and PROJECT API KEY as arguments to the getLogger() helper.

import airbrake

logger = airbrake.getLogger(api_key="<Your project API KEY>", project_id=<Your project ID>)

try:
    1/0
except Exception:
    logger.exception("Bad math.")

Taking airbrake-python further

Now that you have configured Airbrake to report exceptions from your Python 2.7 app, we recommend you add extra context to your errors and add Airbrake to your existing logger. Please visit the airbrake-python GitHub repo for the full list of notifier features.