How to Install asyncpg in Python

v0.31.0 Async & Networking Python >=3.9.0

An asyncio PostgreSQL driver

Install pip install asyncpg

What is asyncpg?

An asyncio PostgreSQL driver

asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio

asyncpg is a database interface library designed specifically for PostgreSQL and Python/asyncio. asyncpg is an efficient, clean implementation of PostgreSQL server binary protocol for use with Python's `` framework. You can read more about asyncpg in an introductory .

asyncpg requires Python 3.9 or later and is supported for PostgreSQL versions 9.5 to 18. Other PostgreSQL versions or other databases implementing the PostgreSQL protocol may work, but are not being actively tested.

Quick Start

Minimal example to get started with asyncpg:

import asyncio
import asyncpg

async def main():
    conn = await asyncpg.connect("postgresql://user:pass@localhost/mydb")
    rows = await conn.fetch("SELECT id, name FROM users LIMIT 5")
    for row in rows:
        print(dict(row))
    await conn.close()

asyncio.run(main())

Installation

pip (standard)

pip install asyncpg

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install asyncpg

pip3

pip3 install asyncpg

conda

conda install -c conda-forge asyncpg

Poetry

poetry add asyncpg

Dependencies

Installing asyncpg will also install these packages:

Verify the Installation

After installing, confirm the package is available:

python -c "import asyncpg; print(asyncpg.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing asyncpg with pip.

ModuleNotFoundError: No module named 'asyncpg'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install asyncpg. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'asyncpg' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install asyncpg to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'asyncpg'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show asyncpg and upgrade with pip install --upgrade asyncpg.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install asyncpg. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user asyncpg

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org asyncpg

RuntimeError: This event loop is already running

Cause: Calling <code>asyncio.run()</code> inside Jupyter or another already-running event loop.

Fix: In Jupyter, use await directly. Or install nest_asyncio and call nest_asyncio.apply().

Recent Releases

VersionReleased
0.31.0 latest 2025-11-24
0.30.0 2024-10-20
0.29.0 2023-11-05
0.28.0 2023-07-07
0.27.0 2022-10-26

Full release history on PyPI →

Manage asyncpg

Upgrade to latest version

pip install --upgrade asyncpg

Install a specific version

pip install asyncpg==0.31.0

Uninstall

pip uninstall asyncpg

Check what is installed

pip show asyncpg

Last updated: 2026-04-11 • Data from PyPI