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

Configuring the Client

Settings are specified as part of the initialization of the client. The client is a class that can be instanciated 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('___DSN___')

Capture an Error

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

from raven import Client

client = Client('___DSN___')

    1 / 0
except ZeroDivisionError:

Adding Context

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):

Deep Dive

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: