Session Manager

class falcon_sqla.Manager(engine, session_cls=<class 'falcon_sqla.session.RequestSession'>, binds=None)

A manager for SQLAlchemy sessions.

This manager allows registering multiple SQLAlchemy engines, specifying if they are read-write or read-only or write-only capable.

add_engine(engine, role=EngineRole.READ)

Adds a new engine with the specified role.

  • engine (Engine) – An instance of a SQLAlchemy Engine.

  • role (EngineRole) –

    The role of the provided engine. Defaults to READ.


    In early versions of this library, role used to take string values: 'r', 'w', 'rw'. These values will continue to be supported in the foreseeable future for backwards compatibility, but new code should prefer passing enum constants instead.

close_session(session, succeeded, req=None, resp=None)

Close a session obtained via get_session().


There is no need to invoke this method manually if you are using the session_scope() context manager, or if you are using middleware.

get_bind(req, resp, session, mapper, clause)

Choose the appropriate bind for the given request session.

This method is not used directly, it’s called by the session instance if multiple engines are defined.

get_session(req=None, resp=None)

Returns a new session object.

property middleware

Create a new Middleware instance connected to this manager.

property read_engines

A tuple of read capable engines.

session_scope(req=None, resp=None)

Provide a transactional scope around a series of operations.

The session is obtained via get_sesion(), and finalized using close_session() upon exiting the context manager.

Based on the session_scope() recipe from

property write_engines

A tuple of write capable engines.