Honeybadger Python
Honeybadger Python is the official client library for sending Python and Django errors to Honeybadger.io. It provides real-time error tracking, uptime monitoring, and performance insights for applications built with frameworks like Django, Flask, and Celery, as well as general Python applications and AWS Lambda functions. The library is actively maintained, with version 1.2.2 being the latest, and receives frequent updates including bug fixes and minor features.
Common errors
-
Honeybadger API key is not configured. Errors will not be sent.
cause The `api_key` was not provided to `honeybadger.configure()` or the `HONEYBADGER_API_KEY` environment variable is missing.fixSet the `HONEYBADGER_API_KEY` environment variable or explicitly pass `api_key='YOUR_KEY'` to `honeybadger.configure()`. -
No errors appearing in Honeybadger UI, even after `honeybadger.notify()` calls.
cause Errors are sent asynchronously by default. In fast-exiting scripts (e.g., a CLI tool or serverless function without proper await), the process might terminate before the error report is sent.fixAdd `force_sync=True` to your `honeybadger.notify()` call: `honeybadger.notify(e, force_sync=True)`. -
TypeError: __init__() got an unexpected keyword argument 'config'
cause This error can occur if you're trying to pass a dictionary of configuration options as `config` to `honeybadger.configure()`. The `configure` method expects keyword arguments directly.fixPass configuration options as individual keyword arguments: `honeybadger.configure(api_key='...', environment='production', ...)` instead of `honeybadger.configure(config={'api_key': '...'})`.
Warnings
- gotcha Errors not appearing in Honeybadger dashboard due to missing API key configuration.
- gotcha Manual `honeybadger.notify()` calls might not complete in short-lived scripts or serverless functions without `force_sync=True`.
- gotcha Automatic error capture for frameworks like Django or Flask requires specific integration setup (middleware/init), not just importing the library.
- breaking Prior to v1.0, the configuration method was `honeybadger.init()`. This was renamed to `honeybadger.configure()`.
Install
-
pip install honeybadger -
pip install honeybadger[django] -
pip install honeybadger[flask] -
pip install honeybadger[celery]
Imports
- honeybadger
import honeybadger
- configure
honeybadger.configure(...)
- notify
honeybadger.notify(...)
- set_context
honeybadger.set_context(...)
- Honeybadger
from honeybadger.contrib.flask import Honeybadger
Quickstart
import honeybadger
import os
# Configure Honeybadger using an environment variable or direct assignment
honeybadger.configure(api_key=os.environ.get('HONEYBADGER_API_KEY', ''))
def problematic_function():
raise ValueError("This is a test error from Honeybadger Python!")
try:
problematic_function()
except Exception as e:
# Manually send the error to Honeybadger
honeybadger.notify(e, force_sync=True)
print("Error notified to Honeybadger. Check your dashboard.")
# Example of setting custom context
honeybadger.set_context(user_id=123, email='test@example.com')