Legacy SDK

For pairing Sentry up with Python you can use the Raven for Python (raven-python) library. It is the official standalone Python client for Sentry. It can be used with any modern Python interpreter be it CPython 2.x or 3.x, PyPy or Jython. It’s an Open Source project and available under a very liberal BSD license.

If you haven’t already, start by downloading Raven. The easiest way is with pip:

pip install raven --upgrade

Settings are specified as part of the initialization of the client. The client is a class that can be instantiated with a specific configuration and all reporting can then happen from the instance of that object. Typically an instance is created somewhere globally and then imported as necessary. For getting started all you need is your DSN:

from raven import Client
client = Client('https://examplePublicKey@o0.ingest.sentry.io/0')

The most basic use for raven is to record one specific error that occurs:

from raven import Client

client = Client('https://examplePublicKey@o0.ingest.sentry.io/0')

    1 / 0
except ZeroDivisionError:

Much of the usefulness of Sentry comes from additional context data with the events. The Python client makes this very convenient by providing methods to set thread local context data that is then submitted automatically with all events. For instance you can use user_context() to set the information about the current user:

def handle_request(request):
        'email': request.user.email

Raven Python is more than that however. To dive deeper into what it does, how it works and how it integrates into other systems there is more to discover:


Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").