Python PostgreSQL libraries

Updated Nov 2026

Python PostgreSQL libraries connect applications to a PostgreSQL database, run SQL, and return rows. A driver either calls libpq, the PostgreSQL C client library, or speaks the PostgreSQL wire protocol directly. These libraries let web apps and backend services read and write relational data from Python.

Popularity

psycopg2 has the most monthly downloads in this comparison, at 239.0M.

LibraryMonthly downloadsStarsLast releaseLicense
psycopg2
239.0M
3.7KSep 2026LGPL with exceptions
Psycopg
216.8M
2.5KNov 2026LGPL-3.0-only
asyncpg
145.4M
8.1KOct 2026Apache-2.0
pg8000
55.0M
Not on GitHubOct 2026BSD-3-Clause
ConnectorX
1.6M
2.7KSep 2026MIT
ADBC PostgreSQL
1.2M
639Oct 2026Apache-2.0
aiopg
685.1K
1.4KOct 2022BSD
PyGreSQL
339.5K
48Jan 2026PostgreSQL
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Packages the Psycopg 2 PostgreSQL adapter as a binary wheel.

Downloads / mo
239.0M
Stars
3.7K
Last release
2.9.13
License
LGPL with exceptions

Strengths

  • Wraps PostgreSQL’s libpq client. Use the established libpq-backed PostgreSQL adapter.
  • Includes threaded connection pooling. Use ThreadedConnectionPool when application threads need pooled database connections.

Limitations

  • Binary dependencies update separately. Upgrade the package to update its bundled libpq and libssl libraries.
  • Async mode disables COPY. Use a synchronous connection for Psycopg COPY operations.

Quickstart

From usage.html
$ python3 -m pip install psycopg2-binary
import psycopg2
conn = psycopg2.connect("dbname=test user=postgres")
cur = conn.cursor()
cur.execute("SELECT 1")
print(cur.fetchone())
cur.close()
conn.close()

psycopg2 examples

From open-source projects on GitHub

Provides PostgreSQL connections, cursors, and query execution for Python.

Downloads / mo
216.8M
Stars
2.5K
Last release
3.3.9
License
LGPL-3.0-only

Strengths

  • Offers sync and async interfaces. Use similar connection and cursor patterns in synchronous and asynchronous code.
  • Streams PostgreSQL COPY data. Read or write COPY data through a managed Copy object.

Limitations

  • Pooling needs another package. Install psycopg_pool or the pool extra to use connection pools.
  • Windows async needs another loop. Select an event loop compatible with Psycopg asynchronous connections.

Quickstart

From usage.html
$ python3 -m pip install "psycopg[binary]"
import psycopg
with psycopg.connect("dbname=test user=postgres") as conn:
    print(conn.execute("SELECT 1").fetchone())

Psycopg examples

From open-source projects on GitHub

Implements PostgreSQL’s protocol for Python asyncio applications.

Downloads / mo
145.4M
Stars
8.1K
Last release
0.32.0
License
Apache-2.0

Strengths

  • Includes an asynchronous connection pool. Acquire, use, and return connections through the built-in pool.
  • Converts PostgreSQL types automatically. Receive arrays, composite values, and other PostgreSQL types as Python values.

Limitations

  • Prepared objects expire after release. Recreate statement and cursor objects when acquiring a connection again.

Quickstart

From README.rst
$ python3 -m pip install asyncpg
import asyncio
import asyncpg
async def main():
    conn = await asyncpg.connect("postgresql://postgres@localhost/test")
    try:
        print(await conn.fetchval("SELECT 1"))
    finally:
        await conn.close()
asyncio.run(main())

asyncpg examples

From open-source projects on GitHub
async def start(
    self, is_root: bool, extra_options: typing.Dict[typing.Any, typing.Any]
) -> None:
    assert self._connection._connection is not None, "Connection is not acquired"
    self._transaction = self._connection._connection.transaction(**extra_options)
    await self._transaction.start()

Provides a pure-Python PostgreSQL driver that implements DB-API.

Downloads / mo
55.0M
Last release
1.31.6
License
BSD-3-Clause

Strengths

  • Runs as a pure-Python driver. Use PostgreSQL without installing a C client-library extension.
  • Offers native and DB-API interfaces. Choose the native interface or the standardized DB-API interface.

Limitations

  • Connections belong to one thread. Create separate connections for concurrent work in different threads.

Quickstart

From README.md
$ python3 -m pip install pg8000
import pg8000.dbapi
conn = pg8000.dbapi.connect(user="postgres", database="test")
cur = conn.cursor()
cur.execute("SELECT 1")
print(cur.fetchone())
cur.close()
conn.close()

pg8000 examples

From open-source projects on GitHub

Loads data from databases into DataFrames from Rust and Python.

Downloads / mo
1.6M
Stars
2.7K
Last release
0.4.6
License
MIT

Quickstart

From README.md
$ python3 -m pip install connectorx pandas
import connectorx as cx
cx.read_sql("postgresql://username:password@server:port/database", "SELECT * FROM lineitem")

ConnectorX examples

From open-source projects on GitHub

ADBC PostgreSQL

Connects to PostgreSQL through an ADBC driver built on libpq.

Downloads / mo
1.2M
Stars
639
Last release
1.13.0
License
Apache-2.0

Quickstart

From dbapi.py
$ python3 -m pip install adbc-driver-postgresql adbc-driver-manager pyarrow
import adbc_driver_postgresql.dbapi as dbapi
with dbapi.connect("postgresql://postgres@localhost/test") as conn:
    with conn.cursor() as cur:
        cur.execute("SELECT 1")
        print(cur.fetchone())

ADBC PostgreSQL examples

From open-source projects on GitHub

Integrates PostgreSQL with asyncio.

Downloads / mo
685.1K
Stars
1.4K
Last release
1.4.0
License
BSD

Quickstart

From index.html
$ python3 -m pip install aiopg
import asyncio
import aiopg
async def main():
    async with aiopg.create_pool("dbname=test user=postgres host=localhost") as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute("SELECT 1")
                print(await cur.fetchone())
asyncio.run(main())

aiopg examples

From open-source projects on GitHub

Provides Python interfaces to PostgreSQL.

Downloads / mo
339.5K
Stars
48
Last release
6.2.3
License
PostgreSQL

Quickstart

From module.html
$ python3 -m pip install pygresql
import pgdb
conn = pgdb.connect(database="test", user="postgres")
cur = conn.cursor()
cur.execute("SELECT 1")
print(cur.fetchone())
cur.close()
conn.close()

PyGreSQL examples

From open-source projects on GitHub

FAQ

Psycopg suits new projects and offers synchronous and native async interfaces. asyncpg suits asyncio services that want a dedicated protocol client and pool. pg8000 suits environments that cannot install libpq.

Psycopg is the current generation of the adapter. Its publisher recommends it for new projects and keeps psycopg2 for existing integrations.

asyncpg is an asyncio PostgreSQL driver with its own protocol client and connection pool. It does not offer a synchronous DB-API interface.

pg8000 is a pure Python PostgreSQL driver with both DB-API and native query interfaces. It does not depend on libpq.

For coding agents

Found your PostgreSQL library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official