Currently, I'm instantiating a new engine and declarative automap base for 
each MySQL database I'd like to include in my session and then individually
mapping reflected tables to the relevant engines. Some sample code to 

report_engine = create_engine(URL(drivername='mysql', 
host='', port='3306', 
query={'read_default_file':'/srv/db.cnf'}, database='report'))
report_base = automap_base()
report_base.prepare(report_engine, reflect=True)

md_engine = create_engine(URL(drivername='mysql', 
host='', port='3306', 
query={'read_default_file':'/srv/db.cnf'}, database='md'))
md_base = automap_base()
md_base.prepare(md_engine, reflect=True)

# map tables to classes
user_practice_contacts = md_base.classes.user_practice_contacts
user_professional_details = md_base.classes.user_professional_details
users = report_base.classes.users
cities = report_base.classes.cities

sess = scoped_session(sessionmaker(twophase=True,
user_professional_details:md_engine, users:report_engine, 

This seems like a hack-ish approach so I'm wondering if there's a better 
way. Must a separate engine and base be created for each MySQL DB? Each DB 
resides on the same MySQL instance with the same host name. And must each 
table be explicitly bound in the session creation? Still learning the ropes 
of SQLAlchemy so forgive me if these are obvious questions. Thanks for your 

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
For more options, visit

Reply via email to