title: Parsing and constructing filtering queries similiar to SQL WHERE clause in Python/JavaScript
body: <p>I am building a query engine for a database which is pulling data from SQL and other sources. For normal use cases the users can use  a web form where the use can specify filtering parameters with select and ranged inputs. But for advanced use cases, I'd like to to specify a filtering equation box where the users could type</p>
  
  <ul>
  <li><p>AND, OR</p></li>
  <li><p>Nested parenthesis</p></li>
  <li><p>variable names</p></li>
  <li><blockquote>
    <p>, &lt;, =, != operators</p>
  </blockquote></li>
  </ul>
  
  <p>So the filtering equation could look something like:</p>
  
  <pre><code> ((age &gt; 50) or (weight &gt; 100)) and diabetes='yes'
  </code></pre>
  
  <p>Then this input would be parsed, input errors detected (non-existing variable name, etc) and SQL Alchemy queries built based on it.</p>
  
  <p>I saw an earlier post about the similar problem <a href="https://stackoverflow.com/a/1395854/315168">https://stackoverflow.com/a/1395854/315168</a> </p>
  
  <p>There seem to exist several language and mini-language parsers for Python <a href="http://navarra.ca/?p=538" rel="nofollow noreferrer">http://navarra.ca/?p=538</a></p>
  
  <p>However, does there exist any package which would be out of the box solution or near solution for my problem? If not what would be the simplest way to construct such query parser and constructor in Python? </p>