SQLAlchemy and Alembic 2 · Updating and raw SQL
Run raw SQL safely
Use text() with bound parameters, never string formatting.
from sqlalchemy import text
rows = session.execute(text("SELECT * FROM users WHERE name = :name"), {"name": "Ada"}).all()
Official SQLAlchemy and Alembic 2 documentation
More updating and raw sql commands
All updating and raw sql commands · SQLAlchemy and Alembic 2 cheatsheet