It doesn't look too awkward to me - what sort of API would you prefer?
Note that and_ and or_ are available in the top-level "sqlalchemy"
namespace. Also, backslashes aren't necessary on the end of lines when
you're inside brackets, so your example could actually look like this:
import sqlalchemy as sa
criteria = (('male', 35), ('female', 35))
Useraccount = model.Useraccount
query = session.query(Useraccount)
ands = []
for gender, age in criteria:
ands.append(
sa.and_(
Useraccount.gender == gender,
Useraccount.age == age,
)
)
query = query.filter(sa.or_(*ands))
results= query.all()
It's entirely subjective, but I find that easier to read.
You can also use "&" and "|" but I think you have to be a little
careful with operator precedence. You can probably write this:
ands.append((Useraccount.gender == gender) & (Useraccount.age == age))
Simon