Psycopg 3 is a modern implementation of a PostgreSQL adapter for Python.
Quick version:
pip install --upgrade pip # upgrade pip to at least 20.3 pip install "psycopg[binary,pool]" # install binary dependencies
For further information about installation please check the documentation.
In order to work on the Psycopg source code, you must have the
libpq
PostgreSQL client library installed on the system. For instance, on
Debian systems, you can obtain it by running:
sudo apt install libpq5
On macOS, run:
brew install libpq
On Windows you can use EnterpriseDB's installers to obtain libpq
which is included in the Command Line Tools.
You can then clone this repository to develop Psycopg:
git clone https://github.com/psycopg/psycopg.git cd psycopg
Please note that the repository contains the source code of several Python packages, which may have different requirements:
- The
psycopg
directory contains the pure python implementation ofpsycopg
. The package has only a runtime dependency on thelibpq
, the PostgreSQL client library, which should be installed in your system. - The
psycopg_c
directory contains an optimization module written in C/Cython. In order to build it you will need a few development tools: please look at Local installation in the docs for the details. - The
psycopg_pool
directory contains the connection pools implementations. This is kept as a separate package to allow a different release cycle.
You can create a local virtualenv and install the packages in development mode, together with their development and testing requirements:
python -m venv .venv source .venv/bin/activate pip install -e "./psycopg[dev,test]" # for the base Python package pip install -e ./psycopg_pool # for the connection pool pip install ./psycopg_c # for the C speedup module
Please add --config-settings editable_mode=strict
to the pip install
-e
above if you experience editable mode broken.
Now hack away! You can run the tests using:
psql -c 'create database psycopg_test' export PSYCOPG_TEST_DSN="dbname=psycopg_test" pytest
To use cross-platform zipapps created with shiv that include Psycopg
as a dependency you must also have libpq
installed. See
the section above for install instructions.