session = scoped_session(sessionmaker(bind=engine))

@app.teardown_request
def remove_session(ex=None):
    session.remove()
Using SQLAlchemy session from Flask raises "SQLite objects created in a thread can only be used in that same thread"