On this page, we provide concise information to get you up and running with Sentry's Python SDK, automatically reporting errors and exceptions in your application.

Using a framework? Take a look at our specific guides to get started.


Sentry captures data by using an SDK within your application’s runtime. These are platform specific and allow Sentry to have a deep understanding of how your application works.

Install our Python SDK using pip:

$ pip install --upgrade sentry-sdk

The SDK provides support for Python 2.7 and 3.4 or later. Integrations with specific frameworks (particularly asynchronous ones) may impose additional requirements though.


After you’ve completed setting up a project in Sentry, Sentry will give you a value which we call a DSN or Data Source Name. It looks a lot like a standard URL, but it’s just a representation of the configuration required by the Sentry SDKs. It consists of a few pieces, including the protocol, public key, the server address, and the project identifier.

Import and initialize the Sentry SDK early in your application’s setup:

import sentry_sdk


Great! Now that you’ve completed setting up the SDK, maybe you want to quickly test out how Sentry works. Start by capturing an exception:

sentry_sdk.capture_exception(Exception("This is an example of an error message."))

Once the exception is captured, you'll see the error in your Sentry dashboard.


In Python you can either capture a caught exception or the one currently held in sys.exc_info() by not passing an argument:

from sentry_sdk import capture_exception

except Exception as e:
    # Alternatively the argument can be omitted

Monitor Performance

To get started with performance monitoring using Sentry's Python SDK, first install sentry_sdk:

pip install --upgrade sentry-sdk

Next, initialize the integration in your call to sentry_sdk.init:

import sentry_sdk

    traces_sample_rate=1.0 # be sure to lower this in production to prevent quota issues

Performance data is transmitted using a new event type called "transactions", which you can learn about in Distributed Tracing. To capture transactions, you must install and configure your SDK to set the traces_sample_rate option to a nonzero value. The example configuration above will transmit 100% of captured traces. Be sure to lower this value in production otherwise you could burn through your quota quickly.

Learn more about sampling in Using Your SDK to Filter Events.

You can edit this page on GitHub.