---
title: "asyncpg"
description: "Learn about importing the asyncpg integration and how it captures queries from asyncpg."
url: https://docs.sentry.io/platforms/python/integrations/asyncpg/
---

# asyncpg | Sentry for Python

The `AsyncPGIntegration` captures queries from [asyncpg](https://github.com/MagicStack/asyncpg), which can be viewed in Sentry's **Performance** page.

## [Install](https://docs.sentry.io/platforms/python/integrations/asyncpg.md#install)

Install `sentry-sdk` from PyPI:

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

## [Configure](https://docs.sentry.io/platforms/python/integrations/asyncpg.md#configure)

If you have the `asyncpg` package in your dependencies, the asyncpg integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring\[ ]Tracing\[ ]Profiling\[ ]Logs

```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/asyncpg.md#verify)

```python
import asyncpg

async def main():
    sentry_sdk.init(...)  # same as above

    with sentry_sdk.start_transaction(name="testing_sentry"):
        conn = await asyncpg.connect(DATABASE_URL)
        await conn.fetch("SELECT * FROM pg_catalog.pg_tables;")
        await conn.close()

asyncio.run(main())
```

This will create a transaction called `testing_sentry` in the Performance section of [sentry.io](https://sentry.io), and create spans for the `connect` and the `SELECT` operations.

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/asyncpg.md#supported-versions)

* asyncpg: 0.23+
* Python: 3.7+
