why use sqlalchemy declarative api?
Question: New to sqlalchemy and somewhat novice with programing and python. I had wanted
to query a table. It seems I can use the all() function when querying but
cannot filter without creating a class.

1.) Can I filter without creating a class and using the declarative api? Is
the filtering example stated below incorrect? 2.) When would it be appropriate
to use declarative api in sqlalchemy and when would it not be appropriate?

    
    
    import sqlalchemy as sql
    from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
    from sqlalchemy.orm import sessionmaker
    from sqlalchemy.orm import sessionmaker
    
    db = sql.create_engine('postgresql://postgres:password@localhost:5432/postgres')
    engine = db.connect()
    meta = MetaData(engine)
    session = sessionmaker(bind=engine)
    session = session()
    
    files = Table('files',meta,
    Column('file_id',Integer,primary_key=True),
    Column('file_name',String(256)),
    Column('query',String(256)),
    Column('results',Integer),
    Column('totalresults',Integer),
    schema='indeed')
    
    session.query(files).all() #ok
    session.query(files).filter(files.file_name = 'test.json') #not ok
    


Answer: Filter using declarative api this way:

    
    
    session.query(files).filter(files.file_name == 'test.json').all()
    

You can also use raw sql queries
([docs](http://docs.sqlalchemy.org/en/latest/core/connections.html#basic-
usage)).

Whether using declarative api or not may depend on your queries complexity,
because sometimes sqlalchemy doesn't optimize them right way.

