I've read "Multiple database connections with Python + Pylons + SQLAlchemy" and I get how to create multiple engines using that technique, but now I'm looking for advice on how to handle the creation of Session
s for these engines. Right now, the Session
in my project is defined as per Pylons convention: myapp.model.meta.Session = scoped_session(sessionmaker())
and imported as myapp.model.Session
. This works fine if there's only one engine.
What's a good, maintainable approach to defining this for multiple engines? The set of engines may change at runtime, for what it's worth, so I'd need the ability to create new Session
s on the fly, without hard coding them into the model.