# Python Error Monitoring & Performance Monitoring

> Diagnose failures in Django, Flask, FastAPI, and Celery with local variables in the stack, function-level profiling, and logs. Free to start.

**URL:** https://sentry.io/for/python/

---

Python error monitoring with actionable insight into every exception. See the full picture behind any Python error, resolve performance bottlenecks, and get framework-specific coverage that spans Django application monitoring, Flask, FastAPI, and Celery.

**Documentation:** [https://docs.sentry.io/platforms/python/](https://docs.sentry.io/platforms/python/)

## Install

### Python

Grab the [Sentry Python SDK](https://github.com/getsentry/sentry-python):

```bash
pip install --upgrade sentry-sdk
```

Configure your DSN:

```python
import sentry_sdk

sentry_sdk.init(
    "https://<key>@sentry.io/<project>",

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for Tracing.
    # We recommend adjusting this value in production.
    traces_sample_rate=1.0,
)
```

See the [Python docs](https://docs.sentry.io/platforms/python/) for full setup options.

### Django

Install our Python SDK using [pip](https://pip.pypa.io/en/stable/):

```bash
pip install --upgrade sentry-sdk
```

Initialize the Python SDK with the Django integration in your `settings.py` file.

```python
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[DjangoIntegration()],

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for Tracing.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,

    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True
)
```

See the [Django docs](https://docs.sentry.io/platforms/python/integrations/django/) for full setup options.

### Flask

Install `sentry-sdk` from PyPI with the `flask` extra:

```bash
pip install --upgrade 'sentry-sdk[flask]'
```

Configure your DSN:

```python
import sentry_sdk
from flask import Flask
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[FlaskIntegration()],

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for Tracing.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0
)

app = Flask(__name__)
```

See the [Flask docs](https://docs.sentry.io/platforms/python/integrations/flask/) for full setup options.

### FastAPI

Grab the [Sentry Python SDK](https://github.com/getsentry/sentry-python):

```bash
pip install --upgrade sentry-sdk
```

Configure your DSN:

```python
from fastapi import FastAPI

import sentry_sdk
sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for Tracing.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,

    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True,
)

app = FastAPI()
```

See the [FastAPI docs](https://docs.sentry.io/platforms/python/integrations/fastapi/) for full setup options.

### Bottle

Install `sentry-sdk` from PyPI with the `bottle` extra:

```bash
pip install --upgrade 'sentry-sdk[bottle]==0.16.2'
```

To configure the SDK, initialize it with the integration before your app has been initialized:

```python
import sentry_sdk

from bottle import Bottle, run
from sentry_sdk.integrations.bottle import BottleIntegration

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[BottleIntegration()]
)

app = Bottle()
```

See the [Bottle docs](https://docs.sentry.io/platforms/python/integrations/bottle/) for full setup options.

### Celery

Just add `CeleryIntegration()` to your `integrations` list:

```python
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration

sentry_sdk.init(
    dsn='https://<key>@sentry.io/<project>',
    integrations=[CeleryIntegration()]
)
```

See the [Celery docs](https://docs.sentry.io/platforms/python/integrations/celery/) for full setup options.

### Pyramid

Install `sentry-sdk` from PyPI:

```bash
pip install --upgrade sentry-sdk
```

To configure the SDK, initialize it with the integration before or after your app has been created:

```python
import sentry_sdk

from sentry_sdk.integrations.pyramid import PyramidIntegration

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[PyramidIntegration()]
)

from pyramid.config import Configurator

with Configurator() as config:
    # ...
```

See the [Pyramid docs](https://docs.sentry.io/platforms/python/integrations/pyramid/) for full setup options.

### Tornado

Install our Python SDK using [pip](https://pip.pypa.io/en/stable/):

```bash
pip install --upgrade sentry-sdk
```

Initialize the Python SDK with the Tornado integration in your `settings.py` file.

```python
import sentry_sdk
from sentry_sdk.integrations.tornado import TornadoIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    integrations=[
        TornadoIntegration(),
    ],

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for Tracing.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,
)

# Your app code here, without changes

class MyHandler(...):
    # ...
```

See the [Tornado docs](https://docs.sentry.io/platforms/python/integrations/tornado/) for full setup options.

### RQ

Create a file called `mysettings.py` with the following content:

```python
import sentry_sdk
from sentry_sdk.integrations.rq import RqIntegration

sentry_sdk.init("https://<key>@sentry.io/<project>", integrations=[RqIntegration()])
```

Start your worker with:

```bash
rq worker \
-c mysettings \  # module name of mysettings.py
--sentry-dsn=""  # only necessary for RQ < 1.0
```

See the [RQ docs](https://docs.sentry.io/platforms/python/integrations/rq/) for full setup options.

### AWS Lambda Python

Install our Python SDK using `pip`:

```bash
pip install --upgrade sentry-sdk
```

Then use the AWS Lambda integration for the Python SDK like this:

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[AwsLambdaIntegration()],
    traces_sample_rate=1.0, # adjust the sample rate in production as needed
)

def my_function(event, context):
    # ...
```

See the [AWS Lambda Python docs](https://docs.sentry.io/platforms/python/integrations/aws-lambda/) for full setup options.

### Google Cloud Functions Python

Add the Sentry SDK to your `requirements.txt`:

```bash
pip install sentry-sdk
```

Then use the GCP Functions integration for the Python SDK like this:

```python
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    integrations=[GcpIntegration()],
    traces_sample_rate=1.0, # adjust the sample rate in production as needed
)

def http_function_entrypoint(request):
    # ...
```

See the [Google Cloud Functions Python docs](https://docs.sentry.io/platforms/python/integrations/gcp-functions/) for full setup options.

## Features

### Python Performance Monitoring

Within minutes after installing Sentry, software teams can trace Python [performance](/product/tracing/) issues back to a poor-performing API call and surface every related code error. From Django application monitoring to FastAPI performance, engineering managers and developers get a single tool to optimize their code and deliver fast customer experiences.

### Complete Stack Traces, With Local Variables

See local variables in the stack for prod errors, just like in your dev environment. Introspect more deeply into the runtime and jump into the frame to get additional data for any local variable. Filter and group Python exceptions intuitively to eliminate noise, whether you're doing Flask error handling, tracking Django views, or monitoring Celery jobs.

### Fill In the Blanks

Expose the important events that led to each Python exception: SQL queries, debug logs, network requests, past errors. Improve debugging workflow with a full view of releases so you can mark errors as resolved and prioritize live issues.

### Profiling, Down to the Function

Profiling lets you see what parts of your code are consuming the most resources, like CPU or memory, in your application— so you can optimize them before end user experience is impacted. Test your application performance in any environment, including in production, without writing manual tests or extensive troubleshooting.

### Your Logs, Next to the Trace

Ship your Python logging output to Sentry and query it next to the [trace](/product/tracing/) that produced it. The `logging` calls you already write become searchable context on the exact request that failed, so retries, third-party API failures, and internal state are visible without a second tool.

Learn more about [Logs in Sentry](/product/logs/).

## FAQ

**What is the difference between Sentry and traditional logging?**

Traditional logging provides you with a trail of events. Some of those events are errors, but many times they're simply informational. Sentry is fundamentally different because we focus on exceptions, or in other words, we capture application crashes. We discuss in more detail [here](/vs/logging/) and on our [blog](https://blog.sentry.io/lets-get-ready-to-monitor/).

**What  languages does Sentry support?**

Sentry supports every major  language, framework, and library. You can browse each of them [here](/platforms/).

**How much does Sentry cost?**

You can get started for free. Pricing depends on the number of monthly events, transactions, and attachments that you send Sentry. For more details, visit our [pricing page](/pricing/).

**How does Sentry impact the performance of my app?**

Sentry doesn't impact a web site's performance.

If you look at the configuration options for when you initialize Sentry in your code, you'll see there's nothing regarding minimizing its impact on your app's performance. This is because our team of SDK engineers already developed Sentry with this in mind.

Sentry is a listener/handler for errors that asynchronously sends out the error/event to Sentry.io. This is non-blocking. The error/event only goes out if this is an error.

Global handlers have almost no impact as well, as they are native APIs provided by the browsers.

**Can I send logs to Sentry?**

Yes. Sentry Logs lets you send, view, and query structured logs from your application alongside your errors and traces. Because logs sit next to the error and the trace that produced them, you get the granular context — retries, API failures, internal state — that spans and stack traces alone can miss, without switching tools.

Learn more about [Logs in Sentry](/product/logs/).

**What is Seer, Sentry's AI debugging agent?**

Seer is Sentry's AI debugging agent. It reads the full context Sentry already has — the error, its stack trace, the surrounding trace, logs, and profiles — to find the root cause of an issue and propose a fix. Seer can open a pull request with that fix, hand the work to an external coding agent, or review your PRs before they ship.

Learn more about [Seer](/product/seer/) and [Autofix](/product/seer/autofix/).

---

*Source: [sentry.io/for/python/](https://sentry.io/for/python/)*
