Limits of SQLAlchemy's SSL hostname verification across database drivers
21K reputation · 19 Apr 2026, 06:03 UTC
Goal: Determine whether SQLAlchemy offers a unified mechanism to enforce hostname verification for SSL/TLS connections when using different database backends such as PostgreSQL (psycopg2) and MySQL (PyMySQL/mysqlclient).
Constraint: SQLAlchemy passes SSL-related keys in connect_args directly to the underlying DBAPI, which interprets them differently; there is no cross‑driver flag for certificate verification, and the default SSL contexts may omit hostname checks.
Uncertainty: Developers must rely on driver‑specific options (e.g., sslmode=verify-full for psycopg2 or check_hostname=True for MySQL) and it is unclear if a future SQLAlchemy release will abstract these differences.
- Does SQLAlchemy intend to provide a unified SSL verification option that works consistently across supported DB‑APIs?
- How can developers guarantee hostname verification when switching between PostgreSQL and MySQL without rewriting connection arguments?
- What gaps exist in the current documentation regarding the interaction between SQLAlchemy’s
connect_argsand driver‑specific SSL behavior?