---
title: "SQLAlchemy"
description: "Learn how to set up Sentry's SQLAlchemy integration and how to capture SQLAlchemy queries as breadcrumbs and spans."
url: https://docs.sentry.io/platforms/python/integrations/sqlalchemy/
---

# SQLAlchemy | Sentry for Python

If you're using stream mode, this page's references to "transaction" should be applied to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Prerequisites](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)
* Your application up and running
* SQLAlchemy `1.2+`
* Python `3.6+`

## [Install & Configure](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#install--configure)

Follow our [quick start guide](https://docs.sentry.io/platforms/python.md) to set up Sentry in your Python application (make sure to enable tracing). Sentry's SQLAlchemy integration is enabled automatically if you have the `sqlalchemy` package installed.

## [Verify Your Setup](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#verify-your-setup)

To verify that Sentry captures your SQLAlchemy queries, add this code to your app, which will create a transaction called `testing_sentry` in the [Traces](https://sentry.io/orgredirect/organizations/:orgslug/explore/traces/) section and will create a span for the `SELECT` statement:

```python
from sqlalchemy import create_engine
from sqlalchemy.sql import text

def main():
    # same as in the Pythn quick start guide (https://docs.sentry.io/platforms/python)
    sentry_sdk.init(...)

    engine = create_engine(DATABASE_URL, echo=True)
    statement = text("SELECT 'Hello World'")

    with engine.connect() as conn:
        # or sentry_sdk.traces.start_span(name="testing_sentry", parent_span=None) in stream mode
        with sentry_sdk.start_transaction(name="testing_sentry"):
            result = conn.execute(statement)

main()
```

## [Next Steps](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#next-steps)

At this point, you should have integrated Sentry into your application and should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

* Explore [practical guides](https://docs.sentry.io/guides.md) on what to monitor, log, track, and investigate after setup
* Continue to [customize your configuration](https://docs.sentry.io/platforms/python/configuration.md)
* Learn more about [manually capturing errors or messages](https://docs.sentry.io/platforms/python/usage.md)
* Dive straight into the API with our [API docs](https://getsentry.github.io/sentry-python/)

Are you having problems setting up the SDK or integration?

* Find various topics in [Troubleshooting](https://docs.sentry.io/platforms/python/troubleshooting.md)
* [Get support](https://www.sentry.help/en/)
