Runtime Inspection API — SQLAlchemy 2.0.0b1 documentation

From Get docs

Runtime Inspection API

Available Inspection Targets

Below is a listing of many of the most common inspection targets.

  • Connectable (i.e. _engine.Engine, _engine.Connection) - returns an _reflection.Inspector object.
  • _expression.ClauseElement - all SQL expression components, including _schema.Table, _schema.Column, serve as their own inspection objects, meaning any of these objects passed to _sa.inspect() return themselves.
  • object - an object given will be checked by the ORM for a mapping - if so, an InstanceState is returned representing the mapped state of the object. The InstanceState also provides access to per attribute state via the AttributeState interface as well as the per-flush “history” of any attribute via the History object.
  • type (i.e. a class) - a class given will be checked by the ORM for a mapping - if so, a _orm.Mapper for that class is returned.
  • mapped attribute - passing a mapped attribute to _sa.inspect(), such as inspect(MyClass.some_attribute), returns a QueryableAttribute object, which is the descriptor associated with a mapped class. This descriptor refers to a MapperProperty, which is usually an instance of ColumnProperty or RelationshipProperty, via its attribute.
  • AliasedClass - returns an AliasedInsp object.