psycopg2
psycopg2 - Python-PostgreSQL Database Adapter
Install
psycopg2 on PyPI
pip
pip install psycopg2uv
uv add psycopg2poetry
poetry add psycopg2Package facts
| License | LGPL with exceptions (copyleft) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 115 days since the last release |
| Last repo commit | |
| First released | |
| Popularity | one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-13) |
Evidence: psycopg2-2.9.12-cp310-cp310-win_amd64.whl; psycopg2-2.9.12-cp311-cp311-win_amd64.whl; psycopg2-2.9.12-cp312-cp312-win_amd64.whl; psycopg2-2.9.12-cp313-cp313-win_amd64.whl; psycopg2-2.9.12-cp314-cp314-win_amd64.whl; psycopg2-2.9.12-cp39-cp39-win_amd64.whl
About psycopg2
from the package's own PyPI description — quoted content, verbatim
Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection). It was designed for heavily multi-threaded applications that create and destroy lots of cursors and make a large number of concurrent "INSERT"s or "UPDATE"s.
Psycopg 2 is mostly implemented in C as a libpq wrapper, resulting in being both efficient and secure. It features client-side and server-side cursors, asynchronous communication and notifications, "COPY TO/COPY FROM" support. Many Python types are supported out-of-the-box and adapted to matching PostgreSQL data types; adaptation can be extended and customized thanks to a flexible objects adaptation system.
Psycopg 2 is both Unicode and Python 3 friendly.
.. Note::
The psycopg2 package is still widely used and actively maintained, but it
is not expected to receive new features.
`Psycopg 3`__ is the evolution of psycopg2 and is where `new features are
being developed`__: if you are starting a new project you should probably...
Read as markdown · JSON record · Source repository · Homepage · Docs
AI interpretation — verify before relying
AI-generated interpretation of the package facts above; every digit, version, license, or vulnerability id it cites is grounded in the facts already shown on this page
PostgreSQL database adapter implementing the Python DB API 2.0 specification, with thread-safe connections, client and server-side cursors, and asynchronous communication support.
Medium install friction due to C compilation requirements; prebuilt wheels are available for Windows (Python 3.9–3.14) and other platforms. The package is actively maintained with recent releases, though the description notes that new features are directed to Psycopg 3.
Licensed under LGPL with exceptions (copyleft treatment). Users linking psycopg2 into proprietary applications should review the license terms, though the exceptions clause may permit certain use cases; consult the project documentation for specifics.
Usage
pip install psycopg2
import psycopg2
conn = psycopg2.connect("dbname=test user=postgres")
cur = conn.cursor()
cur.execute("SELECT version();")
print(cur.fetchone())
Requires a C compiler and PostgreSQL development libraries to build from source; prebuilt wheels are available for common platforms. Alternatively, install psycopg2-binary for a standalone package without external build dependencies.
Verdict: Psycopg2 is a mature, production-grade PostgreSQL adapter in the top 1000 PyPI packages with no known vulnerabilities and active maintenance. Medium install friction is offset by prebuilt wheels and the option of psycopg2-binary. LGPL copyleft licensing requires review for proprietary use. The package is stable but feature-frozen; new projects should consider Psycopg 3.
Needs verification
- Whether the LGPL exceptions clause permits linking into closed-source applications without license obligation
- Performance characteristics and thread-safety guarantees under specific concurrency patterns
- Compatibility matrix with specific PostgreSQL server versions beyond Python 3.9–3.14
Similar packages
permissive · top 1,000 on PyPI
psycopg2-binarycopyleft · top 1,000 on PyPI
aiosqlitepermissive · top 1,000 on PyPI
asyncpgpermissive · top 1,000 on PyPI
psycopgcopyleft · top 1,000 on PyPI
psycopg-poolcopyleft · top 1,000 on PyPI
pgvectorpermissive · top 1,000 on PyPI
CacheControlpermissive · top 1,000 on PyPI
psycopg-binarycopyleft · top 1,000 on PyPI
opentelemetry-instrumentation-psycopg2permissive · top 1,000 on PyPI