1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
.. _core_inspection_toplevel:
.. _inspection_toplevel:
Runtime Inspection API
======================
.. automodule:: sqlalchemy.inspection
.. autofunction:: sqlalchemy.inspect
Available Inspection Targets
----------------------------
Below is a listing of many of the most common inspection targets.
* :class:`.Connectable` (i.e. :class:`_engine.Engine`,
:class:`_engine.Connection`) - returns an :class:`_reflection.Inspector` object.
* :class:`_expression.ClauseElement` - all SQL expression components, including
:class:`_schema.Table`, :class:`_schema.Column`, serve as their own inspection objects,
meaning any of these objects passed to :func:`_sa.inspect` return themselves.
* ``object`` - an object given will be checked by the ORM for a mapping -
if so, an :class:`.InstanceState` is returned representing the mapped
state of the object. The :class:`.InstanceState` also provides access
to per attribute state via the :class:`.AttributeState` interface as well
as the per-flush "history" of any attribute via the :class:`.History`
object.
.. seealso::
:ref:`orm_mapper_inspection_instancestate`
* ``type`` (i.e. a class) - a class given will be checked by the ORM for a
mapping - if so, a :class:`_orm.Mapper` for that class is returned.
.. seealso::
:ref:`orm_mapper_inspection_mapper`
* mapped attribute - passing a mapped attribute to :func:`_sa.inspect`, such
as ``inspect(MyClass.some_attribute)``, returns a :class:`.QueryableAttribute`
object, which is the :term:`descriptor` associated with a mapped class.
This descriptor refers to a :class:`.MapperProperty`, which is usually
an instance of :class:`.ColumnProperty`
or :class:`.RelationshipProperty`, via its :attr:`.QueryableAttribute.property`
attribute.
* :class:`.AliasedClass` - returns an :class:`.AliasedInsp` object.
|