SQLAlchemy 2.1
Last reviewed Oct 15, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- SQLAlchemy 2.179 lines · 3.8K tokens
Total234 lines · 7.6K tokens
CWE Coverage
- 15
- 20
- 23
- 36
- 59
- 78
- 89
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 295
- 319
- 328
- 338
- 347
- 362
- 367
- 379
- 409
- 416
- 426
- 427
- 470
- 488
- 502
- 532
- 611
- 639
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 862
- 915
- 916
- 918
- 1104
- 1333
- 1395
Prompt Preview
Apply these rules to SQLAlchemy 2.1 Core and ORM after the Python baseline; they were checked against 2.1.4. Use a maintained Python release at or above 3.11; Python template-string examples require 3.14 or later. Apply the deployed database and DBAPI driver's security requirements as well.
Runtime and connection configuration
- Install
SQLAlchemy[asyncio]when usingAsyncEngineorAsyncSession; 2.1 no longer installs the requiredgreenletdependency by default. Select a compatible asynchronous DBAPI forcreate_async_engine(). - Specify the DBAPI explicitly in connection URLs and test its authentication, TLS, and transaction settings. In 2.1, bare
postgresql://selects psycopg 3 and bareoracle://selects python-oracledb; usepostgresql+psycopg2ororacle+cx_oracleexplicitly when those drivers are intentional. - Construct credentials with
URL.create()and unescaped field values instead of assembling a URL string. Keep the driver, host, database, URL query parameters,connect_args, and engine plugins under trusted configuration; URL parsing and quoting do not authorize a destination or neutralize driver options. - Configure certificate and hostname verification through the selected driver's connection arguments. For psycopg/libpq TCP connections, use
sslmode=verify-fullwith a trustedsslrootcert;preferpermits plaintext fallback, andrequirealone does not verify the hostname. Test rejected certificates and hostnames with the deployed driver.
SQL construction and binding
- Pass data through SQLAlchemy expressions or named