title: python dynamodb construct dynamic queries combined with boolean operations
body: <p>The AWS examples of boto3's dynamodb are simplistic. I wanted to throw up a web form that allowed a user to pick any of the elements in a table and OR a number of options for any single field and AND all of the field filters together.</p>
  
  <p>To do this I need to construct a series of conditions to OR together then AND all the resultant Or combinations, something like:
  And([ Or([c1,c2,...]), Or([e1,e...]), Or([a1,a...]) ]) </p>
  
  <p>I do not know the number of terms for each Or, or the final And until runtime, so I need to be able to aggregate the filter terms together at runtime.</p>
  
  <p>For all the queries below, here's my set of FilterExpressions:</p>
  
  <pre><code>c1 = Attr('class').eq(2)
  c2 = Attr('class').eq(3)
  c = Or([c1, c2])
  
  e1 = Attr('exclusion').eq(0)
  
  a1 = Attr('action').eq(2)
  </code></pre>
  
  <p>I'm able to do simple And/Or queries:</p>
  
  <p>Combine 2 And conditions:</p>
  
  <pre><code>all = [a1, e1]
  request = {'ConsistentRead': False, 'FilterExpression': And(*all)}
  print ('dynamo scan params: {}'.format(request))
  response = table.scan(**request)
  print response['Count'], response['ScannedCount']
  dynamo scan params: {'FilterExpression': &lt;boto3.dynamodb.conditions.And object at 0x115d7d410&gt;, 'ConsistentRead': False}
  34 1166
  </code></pre>
  
  <p>Combine 2 Or conditions:</p>
  
  <pre><code>all = [c1,c2]
  request = {'ConsistentRead': False, 'FilterExpression': Or(*all)}
  print ('dynamo scan params: {}'.format(request))
  response = table.scan(**request)
  print response['Count'], response['ScannedCount']
  dynamo scan params: {'FilterExpression': &lt;boto3.dynamodb.conditions.Or object at 0x115d7dc90&gt;, 'ConsistentRead': False}
  51 1166
  </code></pre>
  
  <p>Combine multiple And and Or conditions:</p>
  
  <p>I expect the syntax here is incorrect, but I'm unable to find any examples of this on the AWS or boto documentation.</p>
  
  <pre><code>all = [And([a1,e1]), Or([c1,c2])]
  </code></pre>
  
  <p>And that's where I'm stuck. </p>