title: Conditionally Filtering in SQLAlchemy
body: <p>Is there a way to conditionally add <code>filter</code> arguments to a query in the SQL Alchemy ORM?</p>
  
  <p>For example imagine, I have the following:</p>
  
  <pre><code>q = session.query(X)
  if a:
   q.filter(X.y == 'a')
  elif b:
   q.filter(X.y == 'a', X.z == 'b')
  elif c:
   q.filter(X.y == 'a', X.p == 'd') 
  </code></pre>
  
  <p>Is there a way to say just add </p>
  
  <p><code>X.z == 'b'</code> if <code>b</code> </p>
  
  <p>without having to readd <code>(X.y == 'a')</code> in every filter.</p>
  
  <p>It seems that I could do </p>
  
  <p><code>q.filter(X.y == 'a').filter(X.y == 'b')</code></p>
  
  <p>but this changes the query that is being performed.</p>