from functools import reduce
if arg1 == 'x':
    queries.append(db.table.field == x)
if arg2 == 'y':
    queries.append(db.table.otherfield == y)
query = reduce(lambda a, b: a & b, queries)
db(query).select()
web2py - test for row with combination of two field values