class documentation

class AutomapBase(object):

View In Hierarchy

Base class for an "automap" schema.

The .AutomapBase class can be compared to the "declarative base" class that is produced by the .declarative.declarative_base function. In practice, the .AutomapBase class is always used as a mixin along with an actual declarative base.

A new subclassable .AutomapBase is typically instantiated using the .automap_base function.

Class Method prepare Extract mapped classes and relationships from the _schema.MetaData and perform mappings.
Class Variable classes An instance of .util.Properties containing classes.
Class Method ​_sa​_raise​_deferred​_config Undocumented
Class Variable __abstract__ Undocumented
Class Variable ​_sa​_decl​_prepare Indicate that the mapping of classes should be deferred.
@classmethod
@util.deprecated_params(engine=('2.0', 'The :paramref:`_automap.AutomapBase.prepare.engine` parameter is deprecated and will be removed in a future release. Please use the :paramref:`_automap.AutomapBase.prepare.autoload_with` parameter.'), reflect=('2.0', 'The :paramref:`_automap.AutomapBase.prepare.reflect` parameter is deprecated and will be removed in a future release. Reflection is enabled when :paramref:`_automap.AutomapBase.prepare.autoload_with` is passed.'))
def prepare(cls, autoload_with=None, engine=None, reflect=False, schema=None, classname_for_table=None, collection_class=None, name_for_scalar_relationship=None, name_for_collection_relationship=None, generate_relationship=None, reflection_options=util.EMPTY_DICT):
Extract mapped classes and relationships from the _schema.MetaData and perform mappings.
Parameters
autoload​_withUndocumented
enginean _engine.Engine or _engine.Connection with which to perform schema reflection, if specified. If the :paramref:`.AutomapBase.prepare.reflect` argument is False, this object is not used.
reflectif True, the _schema.MetaData.reflect method is called on the _schema.MetaData associated with this .AutomapBase. The _engine.Engine passed via :paramref:`.AutomapBase.prepare.engine` will be used to perform the reflection if present; else, the _schema.MetaData should already be bound to some engine else the operation will fail.
schema

When present in conjunction with the :paramref:`.AutomapBase.prepare.reflect` flag, is passed to _schema.MetaData.reflect to indicate the primary schema where tables should be reflected from. When omitted, the default schema in use by the database connection is used.

New in version 1.1.
classname​_for​_tablecallable function which will be used to produce new class names, given a table name. Defaults to .classname_for_table.
collection​_classthe Python collection class that will be used when a new _orm.relationship object is created that represents a collection. Defaults to list.
name​_for​_scalar​_relationshipcallable function which will be used to produce relationship names for scalar relationships. Defaults to .name_for_scalar_relationship.
name​_for​_collection​_relationshipcallable function which will be used to produce relationship names for collection-oriented relationships. Defaults to .name_for_collection_relationship.
generate​_relationshipcallable function which will be used to actually generate _orm.relationship and .backref constructs. Defaults to .generate_relationship.
reflection​_options

When present, this dictionary of options will be passed to _schema.MetaData.reflect to supply general reflection-specific options like only and/or dialect-specific options like oracle_resolve_synonyms.

New in version 1.4.
classes =

An instance of .util.Properties containing classes.

This object behaves much like the .c collection on a table. Classes are present under the name they were given, e.g.:

Base = automap_base()
Base.prepare(engine=some_engine, reflect=True)

User, Address = Base.classes.User, Base.classes.Address
@classmethod
def _sa_raise_deferred_config(cls):

Undocumented

__abstract__: bool =

Undocumented

_sa_decl_prepare: bool =

Indicate that the mapping of classes should be deferred.

The presence of this attribute name indicates to declarative that the call to mapper() should not occur immediately; instead, information about the table and attributes to be mapped are gathered into an internal structure called _DeferredMapperConfig. These objects can be collected later using classes_for_base(), additional mapping decisions can be made, and then the map() method will actually apply the mapping.

The only real reason this deferral of the whole thing is needed is to support primary key columns that aren't reflected yet when the class is declared; everything else can theoretically be added to the mapper later. However, the _DeferredMapperConfig is a nice interface in any case which exists at that not usually exposed point at which declarative has the class and the Table but hasn't called mapper() yet.