Psycopg2 is a PostgreSQL database adapter for the Python programming language that implements the Python DB API 2.0 specification.
The tool solves the problem of connecting Python applications to PostgreSQL databases with thread safety and efficiency. It is implemented primarily in C as a wrapper around libpq, enabling both secure and performant database operations. The adapter supports client-side and server-side cursors, asynchronous communication, server notifications, and COPY operations. Many Python types map automatically to PostgreSQL data types, and the adaptation system allows customization for additional types.
Psycopg2 suits applications that require stable, mature PostgreSQL connectivity with multi-threaded access patterns. It handles scenarios involving concurrent inserts and updates across multiple threads sharing the same connection. The tool is Unicode and Python 3 compatible. However, the README notes that while the package remains actively maintained, new features are not expected in this version. For projects starting fresh, the README recommends considering Psycopg 3, where active feature development occurs.
The project maintains its codebase through automated testing via continuous integration workflows. Documentation is provided both within the repository and online. Installation is straightforward through standard Python package management, with options for both source builds and pre-compiled binary packages, though source builds are recommended for production use.