psycopg2
PostgreSQL database adapter for the Python programming language
What is psycopg2?
PostgreSQL database adapter for the Python programming language
Overview of psycopg2
What it is
psycopg2 is a PostgreSQL database adapter for the Python programming language. It is the most popular PostgreSQL adapter for Python and provides a complete implementation of the Python DB API 2.0 specification. The library is mostly implemented in C as a libpq wrapper, making it efficient and secure. It supports thread safety, allowing several threads to share the same connection. The package is still widely used and actively maintained, but it is not expected to receive new features; the project recommends Psycopg 3 for new projects.
Key features
- Complete implementation of the Python DB API 2.0 specification
- Thread safety (several threads can share the same connection)
- Client-side and server-side cursors
- Asynchronous communication and notifications
- COPY TO / COPY FROM support
- Unicode and Python 3 friendly
- Flexible objects adaptation system that can be extended and customized
Use cases
psycopg2 is designed for heavily multi-threaded applications that create and destroy many cursors and perform a large number of concurrent INSERT or UPDATE operations. It is suitable for any Python application that needs to interact with a PostgreSQL database, especially where performance and thread safety are important.
Getting started
If prerequisites (C compiler, development packages) are met, install using pip:$ pip install psycopg2Or from a source package:$ python setup.py build$ sudo python setup.py installFor a stand-alone binary package (no compiler required):$ pip install psycopg2-binarySee the repository README for full installation details.
License and pricing
The license is not stated in the provided metadata. The package is listed as open source.
Based on the project's public README and repository metadata.