class Mapped(QueryableAttribute, _Generic_T):
Known subclasses: sqlalchemy.orm.attributes.InstrumentedAttribute
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.
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 |
sqlalchemy.orm.attributes.InstrumentedAttribute
Undocumented
sqlalchemy.orm.attributes.InstrumentedAttribute
Undocumented
sqlalchemy.orm.attributes.InstrumentedAttribute
Undocumented