Installing Airbrake in a Python app
- 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 instrutcions to follow.
- Using a 3.x version of Python? follow the Python 3 instructions.
- Using a 2.x version of Python? follow the Python 2 instructions.
The pybrake notifier supports Python 3.4 and above.
pip install -U pybrake
To configure pybrake you will need your Airbrake project’s
these are available from your project’s settings page.
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:
- integrate with the logging standard library
- integrating with Django via Airbrake middleware
- integrating with Flask via the blinker library
- add custom information to notices before they are sent
- define custom filters to ignore notices by type or any other criteria
Visit the pybrake GitHub repo for full details.
Not on Python 3.4+ yet? No problem! Follow these instructions and you will be capturing errors in no time.
pip install -U airbrake
The easiest way to get set up is with a few environment variables.
You can find your
PROJECT ID and
PROJECT API KEY on your project’s
export AIRBRAKE_API_KEY='<Your project API KEY>' export AIRBRAKE_PROJECT_ID='<Your project ID>' export AIRBRAKE_ENVIRONMENT=production
and you’re done! These environment variables are used to automatically
Or, you can manually instantiate your
AirbrakeHandler by passing your
PROJECT API KEY as arguments to the
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.