Psycopg features
Psycopg is a wrapper around the libpq library, the official PostgreSQL client library. This makes it complete, performing, reliable, secure.
- Psycopg 2 is still the most used implementation, as it was first released in 2006. It is still actively maintained, although no new features are planned. Use it if you are maintaining previously written code.
- Psycopg 3 was first released in 2021 and supports many new Python features (static typing, asyncio) and PostgreSQL features (binary protocol, pipeline mode) compared to Psycopg 2. Use it if you are developing something new!
Psycopg 2 features | Psycopg 3 features |
---|---|
Written mostly in C. | Written mostly in Python, with C speed-up module. |
Supports Python 3.7 to 3.12
(check the changelog for older versions support).
|
Supports Python 3.7 to 3.13
(check the changelog for older versions support).
|
Supports PostgreSQL from 7.4 to 17. | Supports PostgreSQL from 10 to 17. |
Pre-compiled bundle available as the psycopg2-binary package.
Difficult dependencies management.
|
Pre-compiled bundle available as the psycopg[binary] extra.
Simpler dependencies management.
|
DB-API 2.0 compliant. | DB-API 2.0 compliant. |
Thread-safe: threads can share the same connection. | Thread-safe: threads can share the same connection. |
Low-level asynchronous I/O. No native asyncio support. | Native asyncio support. |
Integration with coroutine-based libraries (gevent, Eventlet, uGreen) available via psycogreen. | gevent supported out-of-the-box; other libraries can be supported if there is request. |
Built-in adaptation between many Python objects to database types. | Native support for more Python types (such as Enums) and PostgreSQL types (such as multirange, geometric types). |
Adaptation extendible with new adapters to convert Python objects to SQL syntax. | More flexible and complete adaptation customization. |
|
|
Text-only parameters and query results. | Text and binary parameters and query results. |
No prepared statements support. | Automatic or opt-in prepared statements. |
No pipeline/batch mode support. | Pipeline/batch mode support. |
File-based COPY support, synchronous only. | File-based and Python objects-based COPY support. Asynchronous copy support. |
Replication support. | Replication support planned. |
Very basic connection pool. | A much more advanced connection pool. |
No static typing support. | Static typing support. |
Large objects support. | Large objects support planned. |
Support for asynchronous notifications. | Support for asynchronous notifications. |
Support for two-phase commit. | Support for two-phase commit. |