1. Mike Bayer
  2. sqlalchemy


Clone wiki

sqlalchemy / UsageRecipes / DeclarativeReflection


The default method of reflecting tables is to use the autoload=True method at the point at which a Table object is created. This operation requires that an engine be available.

When an application defines it's domain model, usually the Engine isn't created yet, as this is typically a concern for reading a config file or similar after the application has otherwise assembled itself into memory. So Declarative now has the capability to allow for explicit construction of reflection-oriented models without the usage of an Engine. When the Engine is available, a second "mapping" function is provided which will reflect all necessary tables and complete the class mappings.

As of SQLAlchemy 0.8, this capability is built in, as described at Using Reflection with Declarative.

For SQLAlchemy 0.7, an example case is provided instead - see Declarative Reflection.