OSS TanbouSign in with GitHub

access PostgreSQL directly from asyncio through a high-performance Python driver

OSS scale score 244.9OSS health 100
About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
8,098
Primary language
Python
License
Apache-2.0
Repository last updated
Oct 5, 2026
On this page

Overview

asyncpg is a PostgreSQL client library designed for Python asyncio. It implements the PostgreSQL server protocol directly and provides asynchronous APIs for connections, prepared statements, cursors, type adaptation, and connection pooling.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Run PostgreSQL connections and queries through asyncio-native APIs

asyncpg.connect() creates an asynchronous connection, with fetch(), fetchrow(), and execute() for query execution. The driver implements the PostgreSQL protocol directly instead of hiding it behind a generic DB-API facade.

Sources: [2]

Use prepared statements, cursors, composite and array codecs, and pooling

asyncpg supports prepared statements, scrollable cursors, partial iteration, automatic encoding and decoding for composite and array types, custom type codecs, and asynchronous connection pools.

Sources: [2]

Best fit

Fits asyncio backends whose workload is dominated by PostgreSQL I/O

It is a strong fit for asynchronous web APIs and event-driven services that want database waits integrated into the asyncio scheduler while keeping direct control of the driver layer.

Sources: [2]

Before adoption

asyncpg 0.31.0 requires Python 3.9+ and targets PostgreSQL 9.5 through 18

Version 0.31.0 requires Python 3.9 or newer and actively supports PostgreSQL 9.5 through 18. It adds Python 3.14 plus experimental subinterpreter and free-threading support. Upstream performance results depend on benchmark conditions, so measure pool sizing, query patterns, and network latency with the actual workload.

Sources: [2][3][4]

Official sources

  1. [1]MagicStack/asyncpg — GitHub repository(2026-10-06)
  2. [2]asyncpg 0.31.0 — README(2026-10-06)
  3. [3]asyncpg 0.31.0 — setup.py(2026-10-06)
  4. [4]asyncpg 0.31.0 release(2026-10-06)
  5. [5]asyncpg Apache-2.0 license(2026-10-06)
Supplemental curator note

Direct PostgreSQL protocol and type support make asyncpg attractive when an asyncio service does not need a generic database abstraction. Connection-pool sizing and transaction boundaries remain explicit application design decisions.

Try it in 3 steps

  1. 1

    Install asyncpg 0.31.0

    Pin the reviewed stable release. asyncpg 0.31.0 requires Python 3.9 or newer.

    python -m pip install "asyncpg==0.31.0"
  2. 2

    Set a disposable PostgreSQL connection string

    Replace USER, PASSWORD, HOST, and DBNAME with a PostgreSQL database that is safe for verification. Do not commit real credentials.

    export DATABASE_URL='postgresql://USER:PASSWORD@HOST:5432/DBNAME'
  3. 3

    Run a read-only query through asyncio

    Use a read-only SELECT to verify the asynchronous connection and query path without modifying schema or data.

    python - <<'PY' import asyncio import os import asyncpg async def main(): conn = await asyncpg.connect(os.environ['DATABASE_URL']) try: print(await conn.fetchval('select version()')) finally: await conn.close() asyncio.run(main()) PY
Check the official README

Growth

Growth trends · Last 30 days

8,098 Stars

Trend data is still being collected.

Built with

Categories and tags

GitHub data

GitHub dataView detailed GitHub data

GitHub Topics

  • async-programming
  • async-python
  • asyncio
  • database-driver
  • high-performance
  • postgresql
  • python
  • python-3
Stars
8,098
Forks
472
Watchers
104
Open issues
274
Contributors
105
Owner type
Organization
Primary language
Python
License
Apache-2.0
Repository last updated
Oct 5, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?