1# dialects/postgresql/psycopg2cffi.py
2# Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3# <see AUTHORS file>
4#
5# This module is part of SQLAlchemy and is released under
6# the MIT License: https://www.opensource.org/licenses/mit-license.php
7# mypy: ignore-errors
8
9r"""
10.. dialect:: postgresql+psycopg2cffi
11 :name: psycopg2cffi
12 :dbapi: psycopg2cffi
13 :connectstring: postgresql+psycopg2cffi://user:password@host:port/dbname[?key=value&key=value...]
14 :url: https://pypi.org/project/psycopg2cffi/
15
16``psycopg2cffi`` is an adaptation of ``psycopg2``, using CFFI for the C
17layer. This makes it suitable for use in e.g. PyPy. Documentation
18is as per ``psycopg2``.
19
20.. seealso::
21
22 :mod:`sqlalchemy.dialects.postgresql.psycopg2`
23
24""" # noqa
25
26from .psycopg2 import PGDialect_psycopg2
27from ... import util
28
29
30class PGDialect_psycopg2cffi(PGDialect_psycopg2):
31 driver = "psycopg2cffi"
32 supports_unicode_statements = True
33 supports_statement_cache = True
34
35 # psycopg2cffi's first release is 2.5.0, but reports
36 # __version__ as 2.4.4. Subsequent releases seem to have
37 # fixed this.
38
39 FEATURE_VERSION_MAP = dict(
40 native_json=(2, 4, 4),
41 native_jsonb=(2, 7, 1),
42 sane_multi_rowcount=(2, 4, 4),
43 array_oid=(2, 4, 4),
44 hstore_adapter=(2, 4, 4),
45 )
46
47 @classmethod
48 def import_dbapi(cls):
49 return __import__("psycopg2cffi")
50
51 @util.memoized_property
52 def _psycopg2_extensions(cls):
53 root = __import__("psycopg2cffi", fromlist=["extensions"])
54 return root.extensions
55
56 @util.memoized_property
57 def _psycopg2_extras(cls):
58 root = __import__("psycopg2cffi", fromlist=["extras"])
59 return root.extras
60
61
62dialect = PGDialect_psycopg2cffi