Raven Client for Sentry
Raven is the legacy Python client for Sentry, providing error and exception tracking for Python applications. It offers integrations for frameworks like Django and Flask, and supports general WSGI applications. The library is currently in maintenance mode, with new feature development and most bug fixes now occurring exclusively in the successor `sentry-sdk` library.
Warnings
- breaking Raven is the legacy Sentry client and is largely deprecated in favor of `sentry-sdk`. New projects should use `sentry-sdk` for an improved experience and all new features. Migrating from `raven` to `sentry-sdk` involves significant API changes.
- breaking The `raven.conf.load` function was removed, and binding transports via a scheme prefix on DSNs was deprecated in version 5.4.0. The `aiohttp` transport was also moved to a separate `raven-aiohttp` package.
- breaking The UDP transport was removed in version 5.3.0. Additionally, server configuration *must* now be specified with a DSN.
- gotcha In Raven versions prior to 6.10.0, stackframes in some situations could be in inverse order, and `NaN` local variables might be sent as non-standard JSON, potentially causing issues with Sentry event processing.
Install
-
pip install raven
Imports
- Client
from raven import Client
- captureException
client.captureException()
Quickstart
import os
from raven import Client
# Get your DSN from Sentry (e.g., from environment variables)
dsn = os.environ.get('SENTRY_DSN', 'https://examplePublicKey@o0.ingest.sentry.io/0')
# Initialize the Raven client
client = Client(dsn)
try:
1 / 0
except ZeroDivisionError:
client.captureException()
print("Error captured by Raven (check your Sentry dashboard).")
client.captureMessage('This is a test message from Raven.')
print("Message captured by Raven.")