is it possible to retrieve engine value from a sql alchemy session

Sessions have the .get_bind() method which in your case will return your Engine instance.

Relevant excerpt from the sqlalchemy docs:

Return a “bind” to which this Session is bound.

The “bind” is usually an instance of Engine, except in the case where
the Session has been explicitly bound directly to a Connection.

Thus your example() function could do something like:

def example(session):
   print("you created a session!")
   engine = session.get_bind()
   print("the engine is retrieved from session")

Leave a Comment