aiopg
Postgres integration with asyncio.
What it is and what it does
aiopg is an asyncio driver for PostgreSQL that wraps psycopg2's synchronous interface to provide non-blocking database access. It lets you execute queries, manage transactions, and maintain connection pools without blocking the event loop—essential for async web frameworks and concurrent applications that need to query PostgreSQL.
The library supports both raw SQL execution via cursors and optional SQLAlchemy integration for ORM-style queries. It handles connection pooling, transaction management, and cursor operations asynchronously. Two runtime dependencies—psycopg2-binary and async-timeout—provide the underlying database driver and timeout handling.
Use it for:
- Build async web services (FastAPI, aiohttp) that query PostgreSQL without blocking I/O.
- Implement concurrent batch processing where multiple coroutines execute database queries in parallel.
- Use SQLAlchemy ORM asynchronously by leveraging aiopg.sa for schema-driven database operations.
- Manage connection pools efficiently in long-running async applications to avoid resource exhaustion.
- Write async database migrations or data pipelines that process large datasets without halting the event loop.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
aiopg provides asyncio-based access to PostgreSQL databases, wrapping psycopg2 to enable non-blocking queries and connection pooling in async Python applications.
Yes, with conditions. aiopg is stable and production-ready for async PostgreSQL access, with low install friction and no known vulnerabilities. However, the aging maintenance status (last release October 2022) means it may lag behind recent PostgreSQL or asyncio changes. Install it if you need async PostgreSQL support in an existing codebase or stable async framework; evaluate alternatives if you require cutting-edge PostgreSQL features or are starting a new project where ongoing maintenance is critical.
Install
aiopg on PyPI
pip
pip install aiopguv
uv add aiopgpoetry
poetry add aiopgInstalling aiopg
Before you install
Low install friction with a pure-wheel distribution. Maintenance status is aging—last release was 2022-10-26 (1388 days ago)—but the repository remains active and unarchived. The package supports current Python versions (3.7–3.11) and has a stable production classifier.
License in practice
BSD permissive license places no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
import asyncio
import aiopg
async def query():
pool = await aiopg.create_pool('dbname=mydb user=user password=pass host=localhost')
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute('SELECT 1')
async for row in cur:
print(row)
asyncio.run(query())
Requires a running PostgreSQL server and psycopg2-binary (C extension) to be installed; psycopg2-binary must compile or a pre-built wheel must be available for your platform.
Verify before relying
- Whether the aging maintenance status (1388 days since last release) affects compatibility with recent PostgreSQL versions or asyncio changes.
- Current state of SQLAlchemy integration support given the 1.4.x compatibility fixes in the changelog but no recent releases.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — psycopg2-binary, async-timeout |
| Maintenance | aging — 1,388 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 634,709/month — #5,643 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiopg-1.4.0-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
aiomysqlaiomysql provides async/await access to MySQL…
permissive · top 5,000 on PyPI
hopsworks-aiomysqlAsync MySQL database driver for Python asyncio…
permissive · top 15,000 on PyPI
aioodbcaioodbc provides async/await access to ODBC…
permissive · top 5,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
aiosqliteaiosqlite provides an async interface to SQLite…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-aiopgAdds distributed tracing instrumentation for…
permissive · top 5,000 on PyPI
psycopgPsycopg 3 is a PostgreSQL database adapter for…
copyleft · top 1,000 on PyPI
postgresProvides a lightweight abstraction layer over…
permissive · top 15,000 on PyPI
psycopg2PostgreSQL database adapter for Python that…
copyleft · top 1,000 on PyPI
aiosmtplibaiosmtplib is an asynchronous SMTP client that…
permissive · top 5,000 on PyPI