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.
Official sources
- [1]MagicStack/asyncpg — GitHub repository(2026-10-06)
- [2]asyncpg 0.31.0 — README(2026-10-06)
- [3]asyncpg 0.31.0 — setup.py(2026-10-06)
- [4]asyncpg 0.31.0 release(2026-10-06)
- [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
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
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
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
Growth
Growth trends · Last 30 days
8,098 Stars
Trend data is still being collected.
Built with
Categories and tags
Categories
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
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- sqlc18,348 Stars
3 shared tag(s) · 2 shared category(s)
keep SQL as the source of truth and generate type-safe data-access code
Go - sqlx17,743 Stars
3 shared tag(s) · 2 shared category(s)
extend database/sql with struct scanning and named queries without replacing its interfaces
Go - Ent17,204 Stars
3 shared tag(s) · 2 shared category(s)
generate statically typed query APIs from Go schemas with an entity framework
Go - Go MySQL Driver15,278 Stars
3 shared tag(s) · 2 shared category(s)
connect standard database/sql applications to MySQL and MariaDB with a pure-Go driver
Go - Diesel14,193 Stars
3 shared tag(s) · 2 shared category(s)
validate SQL queries and schemas with Rust's type system through an ORM and query builder
Rust - SeaORM9,914 Stars
3 shared tag(s) · 2 shared category(s)
manage asynchronous queries, relations, and migrations with a relational ORM for Rust
Rust
Report incorrect information
Tell us if any listing information is incorrect or outdated.