Runtime Inspection API
The inspect()
function is the entry point to SQLAlchemy’s public API for viewing the configuration and construction of in-memory objects. Depending on the type of object passed to , the return value will either be a related object which provides a known interface, or in many cases it will return the object itself.
The rationale for inspect()
is twofold. One is that it replaces the need to be aware of a large variety of “information getting” functions in SQLAlchemy, such as (deprecated in 1.4), instance_state()
, , and others. The other is that the return value of inspect()
is guaranteed to obey a documented API, thus allowing third party tools which build on top of SQLAlchemy configurations to be constructed in a forwards-compatible way.
function sqlalchemy.``inspect
(subject, raiseerr=True)
The returned value in some cases may be the same object as the one given, such as if a object is passed. In other cases, it will be an instance of the registered inspection type for the given object, such as if an Engine
is passed, an object is returned.
Parameters
raiseerr – When , if the given subject does not correspond to a known SQLAlchemy inspected type,
sqlalchemy.exc.NoInspectionAvailable
is raised. IfFalse
,None
is returned.
Below is a listing of many of the most common inspection targets.
object
- an object given will be checked by the ORM for a mapping - if so, an is returned representing the mapped state of the object. TheInstanceState
also provides access to per attribute state via the interface as well as the per-flush “history” of any attribute via theHistory
object.type
(i.e. a class) - a class given will be checked by the ORM for a mapping - if so, a for that class is returned.