sure, you'd write a loop. I'm not sure if you're looking for core Table objects or declarative classes, I'm guessing declarative classes:
from sqlalchemy.engine.reflection import Inspector
insp = Inspector.from_engine(engine)
class MyClass(Base):
__abstract__ = True
id = Column(Integer, primary_key=True)
foobar = Column(String)
cls_by_table = {}
for table_name in insp.get_table_names():
cls_by_table[table_name] = type(table_name, (MyClass, ), {'__tablename__':table_name})
or if you want them in the module space (like from mymodule import tablename):
from mypackage import mymod as mod
for table_name in insp.get_table_names():
cls = type(table_name, (MyClass, ), {'__tablename__':table_name})
setattr(mod, table_name, cls)
another option if you're just looking for quick and dirty mappings is to use SQLSoup:
with this one, you just pull out an attribute name, and you have a mapped class, but it will reflect the whole thing:
for table_name in insp.get_table_names():
setattr(mod, sqlsoup.entity(table_name))