@JustMe, I wound up here looking for an answer to the same question (so it wasn't just you). I suspect you've either found your answer by now or moved on, but I'll share what I found in case it might help someone else.
I found this bindparam
example in the SqlAlchemy documentation for Using UPDATE and DELETE Statements, but found this syntax to work for SELECT
statements as well.
First, bindparam
needs to added to the sqlalchemy
imports.
from sqlalchemy import bindparam
Then, it can be used in to create the placeholder in the WHERE
clause.
sql = select(User).where(User.c.first_name == bindparam("username"), User.c.age == bindparam("age"))
Then, a dictionary that maps the value to the placeholder gets passed to the execute
function:
user = session.execute(sql, {"username": "Tester", "age": 18})