Search code examples
sqlalchemypsycopg2psycopg3

sqlalchemy-citext is not compatible with psycopg(3)


I need to use sqlalchemy-citext extension to deal with my models but I can't get it to work with psycopg (v3).

App throws an ERROR on startup:

0.258 import psycopg2.extensions
0.258 ModuleNotFoundError: No module named 'psycopg2'

I've below packages installed:

[tool.poetry.dependencies]
...
psycopg = {extras = ["binary", "pool"], version = "3.1.13"}
sqlalchemy = {extras = ["asyncio"], version = "^2.0.31"}
sqlalchemy-citext = "^1.8.0"
...

According to info I've found sqlalchemy-citext == 1.8.0 is compatible with psycopg >= 3

I've also tried using DOCKER. The result is the same.

from python

RUN python -m pip install -U pip psycopg sqlalchemy-citext

RUN python -c "import citext"

Solution

  • sqlalchemy-citext has not been updated in over 3 years (March 2021).

    Native support for CITEXT was added in SQLAlchemy 2.0.7 and bug-fixed in 2.0.19.

    https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#sqlalchemy.dialects.postgresql.CITEXT