You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docker/django.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ When using the ``gthreads`` worker class, a main thread `handles the heartbeat <
46
46
Number of threads
47
47
~~~~~~~~~~~~~~~~~
48
48
49
-
Ensure your code is thread safe. Notably, `psycopg2 cursors are not thread safe <https://www.psycopg.org/docs/cursor.html>`__, though this isn't a concern for typical usage of `Django <https://docs.djangoproject.com/en/5.2/ref/databases/>`__.
49
+
Ensure your code is thread safe. Notably, `psycopg cursors are not thread safe <https://www.psycopg.org/psycopg3/docs/advanced/async.html>`__, though this isn't a concern for typical usage of `Django <https://docs.djangoproject.com/en/5.2/ref/databases/>`__.
50
50
51
51
`When using threads <https://docs.gunicorn.org/en/stable/design.html#how-many-threads>`__, the application is loaded by the worker and some memory is shared between its threads (thus consuming less memory than additional workers would).
Copy file name to clipboardExpand all lines: docs/docker/dockerfile.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,7 +96,7 @@ Set ``server_tokens off;`` to prevent false positives from penetration tests (Ub
96
96
System packages
97
97
---------------
98
98
99
-
Before installing a system package, check whether it's included in a base image. For example, the ``psycopg2`` Python package `requires <https://www.psycopg.org/install/>`__ the ``libpq-dev`` system package. To check whether it's included, when using the `python:3.14 image <https://hub.docker.com/_/python>`__:
99
+
Before installing a system package, check whether it's included in a base image. For example, the ``psycopg[c]`` Python package `requires <https://www.psycopg.org/psycopg3/docs/basic/install.html#local-installation>`__ the ``libpq-dev`` system package to build. To check whether it's included, when using the `python:3.14 image <https://hub.docker.com/_/python>`__:
100
100
101
101
#. Find the tag on the DockerHub page of the base image (the ``3.14`` tag is under *Shared Tags*)
Copy file name to clipboardExpand all lines: docs/python/preferences.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,11 +29,11 @@ Command-line interface
29
29
DataFrames
30
30
`Polars <https://pola.rs>`__, unless end-users are unfamiliar (`pandas <https://pandas.pydata.org/docs/>`__).
31
31
Object Relational Mapper (ORM)
32
-
Django. If you don't need an ORM, use `psycopg2<https://www.psycopg.org/docs/>`__. Do not use `SQLAlchemy <https://www.sqlalchemy.org/>`__, except with FastAPI or in low-level libraries with limited scope *where an ORM is needed*.
32
+
Django. If you don't need an ORM, use `psycopg<https://www.psycopg.org/psycopg3/docs/>`__. Do not use `SQLAlchemy <https://www.sqlalchemy.org/>`__, except with FastAPI or in low-level libraries with limited scope *where an ORM is needed*.
33
33
34
34
.. note::
35
35
36
-
Use ``psycopg2`` in production, not ``psycopg2-binary``, `as recommended <https://www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary>`__. :ref:`See instructions<requirements-psycopg2>`.
36
+
Use ``psycopg[c]`` in production and ``psycopg[binary]`` in development, `as recommended and preferred <https://www.psycopg.org/psycopg3/docs/basic/install.html#local-installation>`__. :ref:`See instructions<requirements-psycopg>`.
37
37
38
38
HTTP client
39
39
`Requests <https://docs.python-requests.org/en/latest/>`__ for synchronous code and `niquests <https://niquests.readthedocs.io/en/latest/>`__ for asynchronous code, unless a framework uses another, like Scrapy (Twisted).
@@ -97,20 +101,63 @@ Add the requirement in alphabetical order to the appropriate ``.in`` file. Then,
97
101
98
102
:doc:`preferences`
99
103
100
-
.. _requirements-psycopg2:
104
+
.. _requirements-psycopg:
105
+
106
+
psycopg
107
+
~~~~~~~
108
+
109
+
Use `psycopg <https://www.psycopg.org/psycopg3/docs/>`__ (psycopg 3), not the older ``psycopg2``. It is a single package with extras: use ``psycopg[c]`` (compiled against the system ``libpq``) in production, and ``psycopg[binary]`` (a self-contained wheel) in development, keeping the ``psycopg`` version in sync.
110
+
111
+
Unlike ``psycopg2`` and ``psycopg2-binary``, the extras install different modules, so you can't add the binary build on top of the production lock. Instead, share a locked base across three files:
112
+
113
+
``requirements_base.in``
114
+
The requirements shared by both environments (everything except psycopg).
115
+
``requirements.in``
116
+
``-r requirements_base.txt`` and ``psycopg[c]``.
117
+
``requirements_dev.in``
118
+
``-r requirements_base.txt``, ``psycopg[binary]`` and the development-only tools.
119
+
120
+
When you add or upgrade a requirement shared by both environments, edit ``requirements_base.in`` and compile base-first, so that the downstream locks pick up its versions:
``psycopg2`` is `recommended <https://www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary>`__ for production. However, installing ``psycopg2`` for development can be difficult on operating systems like macOS. In that case, you can:
146
+
Add ``requirements_base.in`` to the :ref:`requirements check<linting-ci>` in ``lint.yml``:
106
147
107
-
- Put ``psycopg2`` in ``requirements.in``
108
-
- Put ``psycopg2-binary`` in ``requirements_dev.in``
Copy file name to clipboardExpand all lines: docs/services/postgresql.rst
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,12 @@ Connect to a database
10
10
11
11
Connect to the database using a connection string stored in the ``DATABASE_URL`` environment variable.
12
12
13
-
In Python, connect to the database using `dj-database-url <https://github.com/kennethreitz/dj-database-url#readme>`__ if using :doc:`Django<../python/django>`, or `psycopg2<https://www.psycopg.org/docs/module.html#psycopg2.connect>`__ otherwise.
13
+
In Python, connect to the database using `dj-database-url <https://github.com/kennethreitz/dj-database-url#readme>`__ if using :doc:`Django<../python/django>`, or `psycopg<https://www.psycopg.org/psycopg3/docs/api/connections.html#psycopg.Connection.connect>`__ otherwise.
14
14
15
15
To set the search path for a PostgreSQL connection, append to the connection string:
Follow `best practices <https://www.psycopg.org/docs/usage.html#sql-injection>`__ to avoid accidental errors and `SQL injection <https://en.wikipedia.org/wiki/SQL_injection>`__. The code samples below use the psycopg2 Python package.
82
+
Follow `best practices <https://www.psycopg.org/psycopg3/docs/basic/params.html>`__ to avoid accidental errors and `SQL injection <https://en.wikipedia.org/wiki/SQL_injection>`__. The code samples below use the psycopg Python package.
83
83
84
-
- `Pass parameters to SQL queries <https://www.psycopg.org/docs/usage.html#passing-parameters-to-sql-queries>`__, using the second argument to the ``execute`` method. This adapts the Python value's type (like ``bool``, ``int``, ``str``) to the correct SQL representation:
84
+
- `Pass parameters to SQL queries <https://www.psycopg.org/psycopg3/docs/basic/params.html>`__, using the second argument to the ``execute`` method. This adapts the Python value's type (like ``bool``, ``int``, ``str``) to the correct SQL representation:
SELECT * FROM record WHERE collection_id = %s AND ocid = %s
132
132
""", (1, 1, 'ocds-213czf-1')) # AVOID
133
133
134
-
- If you are writing a query template in which you want to substitute column names or table names, use the ``format`` method and the ``SQL`` and ``Identifier`` classes (`documentation <https://www.psycopg.org/docs/sql.html>`__):
134
+
- If you are writing a query template in which you want to substitute column names or table names, use the ``format`` method and the ``SQL`` and ``Identifier`` classes (`documentation <https://www.psycopg.org/psycopg3/docs/api/sql.html>`__):
135
135
136
136
.. code-block:: python
137
137
138
-
frompsycopg2.sql importSQL, Identifier
138
+
frompsycopg.sql importSQL, Identifier
139
139
140
140
cur.execute(SQL("SELECT * FROM {table}").format(table=Identifier('collection')))
0 commit comments