--- title: "SQLAlchemy" description: "Learn about importing the SQLAlchemy integration and how it captures queries from SQLAlchemy as breadcrumbs." url: https://docs.sentry.io/platforms/python/integrations/sqlalchemy/ --- # SQLAlchemy | Sentry for Python The SQLAlchemy integration captures queries from [SQLAlchemy](https://www.sqlalchemy.org/) as breadcrumbs and spans. ## [Install](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#install) Install `sentry-sdk` from PyPI: ```bash pip install sentry-sdk ``` ## [Configure](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#configure) The SQLAlchemy integration is enabled automatically if you have the `sqlalchemy` package installed. Error Monitoring\[ ]Logs\[ ]Tracing\[ ]Profiling ```python import sentry_sdk sentry_sdk.init( dsn="___PUBLIC_DSN___", # Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, # ___PRODUCT_OPTION_START___ performance # Set traces_sample_rate to 1.0 to capture 100% # of transactions for tracing. traces_sample_rate=1.0, # ___PRODUCT_OPTION_END___ performance # ___PRODUCT_OPTION_START___ profiling # To collect profiles for all profile sessions, # set `profile_session_sample_rate` to 1.0. profile_session_sample_rate=1.0, # Profiles will be automatically collected while # there is an active span. profile_lifecycle="trace", # ___PRODUCT_OPTION_END___ profiling # ___PRODUCT_OPTION_START___ logs # Enable logs to be sent to Sentry enable_logs=True, # ___PRODUCT_OPTION_END___ logs ) ``` ## [Verify](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#verify) ```python from sqlalchemy import create_engine from sqlalchemy.sql import text def main(): sentry_sdk.init(...) # same as above engine = create_engine(DATABASE_URL, echo=True) statement = text("SELECT 'Hello World'") with engine.connect() as conn: with sentry_sdk.start_transaction(name="testing_sentry"): result = conn.execute(statement) main() ``` This will create a transaction called `testing_sentry` in the Performance section of [sentry.io](https://sentry.io) and will create a span for the `SELECT` statement. It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io). ## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/sqlalchemy.md#supported-versions) * SQLAlchemy: 1.2+ * Python: 3.6+ The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.