Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

psycopg

> 数据库
Open source

New generation PostgreSQL database adapter for the Python programming language

2.5K stars0 likes1 views
WebsiteGitHub

About

New generation PostgreSQL database adapter for the Python programming language

Psycopg 3 -- PostgreSQL database adapter for Python

Psycopg 3 is a modern implementation of a PostgreSQL adapter for Python.

Installation

Quick version::

bash
pip install "psycopg[binary,pool]"

For further information about installation please check the documentation__.

.. __: https://www.psycopg.org/psycopg3/docs/basic/install.html

.. _Hacking:

Hacking

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::

bash
sudo apt install libpq5

On macOS, run::

bash
brew install libpq

On Windows you can use EnterpriseDB's installers__ to obtain libpq which is included in the Command Line Tools.

.. __: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

You can then clone this repository to develop Psycopg::

bash
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 of psycopg. The package has only a runtime dependency on the libpq, 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.

.. __: https://www.psycopg.org/psycopg3/docs/basic/install.html#local-installation .. __: https://www.psycopg.org/psycopg3/docs/advanced/pool.html

You can create a local virtualenv and install the packages in development mode__, together with their development and testing requirements::

bash
python -m venv .venv
source .venv/bin/activate

# Install the base Psycopg package in editable mode
pip install --config-settings editable_mode=strict -e "./psycopg[dev,test]"

# Install the connection pool package in editable mode
pip install --config-settings editable_mode=strict -e ./psycopg_pool

# Install the C speedup extension
pip install ./psycopg_c

.. __: https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs

The --config-settings editable_mode=strict will be probably required to work around the problem of the editable mode broken__.

.. __: https://github.com/pypa/setuptools/issues/3557

Now hack away! You can run the tests using::

bash
psql -c 'create database psycopg_test'
export PSYCOPG_TEST_DSN="dbname=psycopg_test"
pytest

If some of the tests fail on your local host, it may be helpful to exclude the proxy, subprocess, and/or timing tests to get a clean test run, for example::

 pytest  -m 'not proxy and not timing'

The project includes some pre-commit__ hooks to check that the code is valid according to the project coding convention. Please make sure to install them by running::

pre-commit install

This will allow to check lint errors before submitting merge requests, which will save you time and frustrations.

.. __: https://pre-commit.com/

Please follow the conventional commits__ specification for your commit messages.

.. __: https://www.conventionalcommits.org/en/v1.0.0/

Cross-compiling

To use cross-platform zipapps created with shiv__ that include Psycopg as a dependency you must also have libpq installed. See the section above <Hacking_>_ for install instructions.

.. __: https://github.com/linkedin/shiv

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythondatabasedevelopmentdriverpostgresql

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库