title: How to dynamically use select with SQLAlchemy?
body: <p>I am trying to create a function which can filter a sql table using SQLAlchemy, with optional parameters.</p>
  <p>The function is</p>
  <pre><code>def fetch_new_requests(status, request_type, request_subtype, engine, id_r=None):
          table = Table('Sample_Table', metadata, autoload=True,
                             autoload_with=engine)
          
          query = session.query(load_requests).filter_by(status = status, 
                                                        request_type = request_type, 
                                                        request_subtype = request_subtype, 
                                                        id_r = id_r)
          return pd.read_sql((query).statement,session.bind)
  </code></pre>
  <p>But it returns every time an empty table if I do not define id_r variable</p>
  <p>I have googled but cannot find a woraround</p>
  <p>The I have tried to use **kwargs, but it is not what I really need, I mean here I have to explicitly define column names and again come to the issue with id_r</p>
  <pre><code>def fetch_new_requests(**kwargs):
      
      for x in kwargs.values():
          query = session.query(load_requests).filter_by(status=x)
      return pd.read_sql((query).statement,session.bind)
  </code></pre>
  <p>My ideal result</p>
  <pre><code>def fetch_new_requests(any column names, values of the columns):
      
      for x in kwargs.values():
          query = session.query(load_requests).filter_by(column_name=column_value)
      return pd.read_sql((query).statement,session.bind)
  </code></pre>
  <p>In theorie I can use 2 lists or a dict but if there is another solution would be happy to hear</p>