class documentation

class Mapped(QueryableAttribute, _Generic_T):

Known subclasses: sqlalchemy.orm.attributes.InstrumentedAttribute

View In Hierarchy

Represent an ORM mapped :term:`descriptor` attribute for typing purposes.

This class represents the complete descriptor interface for any class attribute that will have been :term:`instrumented` by the ORM _orm.Mapper class. When used with typing stubs, it is the final type that would be used by a type checker such as mypy to provide the full behavioral contract for the attribute.

Tip

The _orm.Mapped class represents attributes that are handled directly by the _orm.Mapper class. It does not include other Python descriptor classes that are provided as extensions, including :ref:`hybrids_toplevel` and the :ref:`associationproxy_toplevel`. While these systems still make use of ORM-specific superclasses and structures, they are not :term:`instrumented` by the _orm.Mapper and instead provide their own functionality when they are accessed on a class.

When using the :ref:`SQLAlchemy Mypy plugin <mypy_toplevel>`, the _orm.Mapped construct is used in typing annotations to indicate to the plugin those attributes that are expected to be mapped; the plugin also applies _orm.Mapped as an annotation automatically when it scans through declarative mappings in :ref:`orm_declarative_table` style. For more indirect mapping styles such as :ref:`imperative table <orm_imperative_table_configuration>` it is typically applied explicitly to class level attributes that expect to be mapped based on a given _schema.Table configuration.

_orm.Mapped is defined in the sqlalchemy2-stubs project as a PEP 484 generic class which may subscribe to any arbitrary Python type, which represents the Python type handled by the attribute:

class MyMappedClass(Base):
    __table_ = Table(
        "some_table", Base.metadata,
        Column("id", Integer, primary_key=True),
        Column("data", String(50)),
        Column("created_at", DateTime)
    )

    id : Mapped[int]
    data: Mapped[str]
    created_at: Mapped[datetime]

For complete background on how to use _orm.Mapped with pep-484 tools like Mypy, see the link below for background on SQLAlchemy's Mypy plugin.

New in version 1.4.

See Also

:ref:`mypy_toplevel` - complete background on Mypy integration

Method __delete__ Undocumented
Method __get__ Undocumented
Method __set__ Undocumented

Inherited from QueryableAttribute:

Method __clause​_element__ Undocumented
Method __getattr__ Undocumented
Method __init__ Undocumented
Method __reduce__ Undocumented
Method __str__ Undocumented
Method ​_bulk​_update​_tuples Return setter tuples for a bulk UPDATE.
Method ​_clone Undocumented
Method adapt​_to​_entity Return a copy of this PropComparator which will use the given .AliasedInsp to produce corresponding expressions.
Method and​_ Add additional criteria to the ON clause that's represented by this relationship attribute.
Method get​_history Undocumented
Method hasparent Undocumented
Method label Undocumented
Method of​_type Redefine this object in terms of a polymorphic subclass, _orm.with_polymorphic construct, or _orm.aliased construct.
Method operate Operate on an argument.
Method reverse​_operate Reverse operate on an argument.
Class Variable __visit​_name__ Undocumented
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable is​_attribute True if this object is a Python :term:`descriptor`.
Instance Variable ​_extra​_criteria Undocumented
Instance Variable ​_of​_type Undocumented
Instance Variable ​_parententity Undocumented
Instance Variable class​_ Undocumented
Instance Variable comparator Undocumented
Instance Variable impl Undocumented
Instance Variable key Undocumented
Property ​_annotations Undocumented
Property ​_entity​_namespace Undocumented
Property ​_from​_objects Undocumented
Property ​_impl​_uses​_objects Undocumented
Property ​_supports​_population Undocumented
Property expression The SQL expression object represented by this .QueryableAttribute.
Property info Return the 'info' dictionary for the underlying SQL element.
Property parent Return an inspection instance representing the parent.
Property property Return the .MapperProperty associated with this .QueryableAttribute.

Inherited from _MappedAttribute (via QueryableAttribute):

Class Variable __slots__ Undocumented

Inherited from InspectionAttr (via QueryableAttribute):

Class Variable __slots__ Undocumented
Class Variable ​_is​_internal​_proxy True if this object is an internal proxy object.
Class Variable is​_aliased​_class True if this object is an instance of .AliasedClass.
Class Variable is​_bundle True if this object is an instance of .Bundle.
Class Variable is​_clause​_element True if this object is an instance of _expression.ClauseElement.
Class Variable is​_instance True if this object is an instance of .InstanceState.
Class Variable is​_mapper True if this object is an instance of _orm.Mapper.
Class Variable is​_property True if this object is an instance of .MapperProperty.
Class Variable is​_selectable Return True if this object is an instance of _expression.Selectable.

Inherited from PropComparator (via QueryableAttribute):

Static Method any​_op Undocumented
Static Method has​_op Undocumented
Static Method of​_type​_op Undocumented
Method any Return true if this collection contains any member that meets the given criterion.
Method has Return true if this element references a member which meets the given criterion.
Class Variable __slots__ Undocumented
Instance Variable ​_adapt​_to​_entity Undocumented
Instance Variable prop Undocumented
Property ​_parentmapper legacy; this is renamed to _parententity to be compatible with QueryableAttribute.
Property ​_propagate​_attrs Undocumented
Property adapter Produce a callable that adapts column expressions to suit an aliased version of this comparator.

Inherited from ColumnOperators (via QueryableAttribute, PropComparator):

Method __add__ Implement the + operator.
Method __contains__ Undocumented
Method __div__ Implement the / operator.
Method __eq__ Implement the == operator.
Method __ge__ Implement the >= operator.
Method __getitem__ Implement the [] operator.
Method __gt__ Implement the > operator.
Method __le__ Implement the <= operator.
Method __lshift__ implement the << operator.
Method __lt__ Implement the < operator.
Method __mod__ Implement the % operator.
Method __mul__ Implement the * operator.
Method __ne__ Implement the != operator.
Method __neg__ Implement the - operator.
Method __radd__ Implement the + operator in reverse.
Method __rdiv__ Implement the / operator in reverse.
Method __rmod__ Implement the % operator in reverse.
Method __rmul__ Implement the * operator in reverse.
Method __rshift__ implement the >> operator.
Method __rsub__ Implement the - operator in reverse.
Method __rtruediv__ Implement the // operator in reverse.
Method __sub__ Implement the - operator.
Method __truediv__ Implement the // operator.
Method all​_ Produce an _expression.all_ clause against the parent object.
Method any​_ Produce an _expression.any_ clause against the parent object.
Method asc Produce a _expression.asc clause against the parent object.
Method between Produce a _expression.between clause against the parent object, given the lower and upper range.
Method collate Produce a _expression.collate clause against the parent object, given the collation string.
Method concat Implement the 'concat' operator.
Method contains Implement the 'contains' operator.
Method desc Produce a _expression.desc clause against the parent object.
Method distinct Produce a _expression.distinct clause against the parent object.
Method endswith Implement the 'endswith' operator.
Method ilike Implement the ilike operator, e.g. case insensitive LIKE.
Method in​_ Implement the in operator.
Method is​_ Implement the IS operator.
Method is​_distinct​_from Implement the IS DISTINCT FROM operator.
Method is​_not Implement the IS NOT operator.
Method is​_not​_distinct​_from Implement the IS NOT DISTINCT FROM operator.
Method like Implement the like operator.
Method match Implements a database-specific 'match' operator.
Method not​_ilike implement the NOT ILIKE operator.
Method not​_in implement the NOT IN operator.
Method not​_like implement the NOT LIKE operator.
Method nulls​_first Produce a _expression.nulls_first clause against the parent object.
Method nulls​_last Produce a _expression.nulls_last clause against the parent object.
Method regexp​_match Implements a database-specific 'regexp match' operator.
Method regexp​_replace Implements a database-specific 'regexp replace' operator.
Method startswith Implement the startswith operator.
Class Variable timetuple Hack, allows datetime objects to be compared on the LHS.

Inherited from Operators (via QueryableAttribute, PropComparator, ColumnOperators):

Method __and__ Implement the & operator.
Method __invert__ Implement the ~ operator.
Method __or__ Implement the | operator.
Method bool​_op Return a custom boolean operator.
Method op Produce a generic operator function.

Inherited from HasCopyInternals (via QueryableAttribute):

Method ​_copy​_internals Reassign internal elements to be clones of themselves.

Inherited from JoinTargetRole (via QueryableAttribute):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via QueryableAttribute, JoinTargetRole):

Class Variable allows​_lambda Undocumented

Inherited from UsesInspection (via QueryableAttribute, JoinTargetRole):

Class Variable ​_post​_inspect Undocumented
Class Variable uses​_inspection Undocumented

Inherited from SQLRole (via QueryableAttribute, JoinTargetRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from OnClauseRole (via QueryableAttribute):

Class Variable ​_role​_name Undocumented

Inherited from AllowsLambdaRole (via QueryableAttribute, OnClauseRole):

Class Variable allows​_lambda Undocumented

Inherited from SQLRole (via QueryableAttribute, OnClauseRole, StructuralRole):

Class Variable allows​_lambda Undocumented
Class Variable uses​_inspection Undocumented

Inherited from Immutable (via QueryableAttribute):

Method ​_copy​_internals Undocumented
Method params Undocumented
Method unique​_params Undocumented
Class Variable ​_is​_immutable Undocumented

Inherited from MemoizedHasCacheKey (via QueryableAttribute):

Method ​_generate​_cache​_key return a cache key.

Inherited from HasCacheKey (via QueryableAttribute, MemoizedHasCacheKey):

Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented
def __delete__(self, instance):
def __get__(self, instance, owner):
def __set__(self, instance, value):