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
Sessionis bound.The “bind” is usually an instance of
Engine, except in the case where
theSessionhas been explicitly bound directly to aConnection.
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")