database is also available. This is known as the "Inspector"::
from sqlalchemy import create_engine
- from sqlalchemy.engine import reflection
+ from sqlalchemy import inspect
engine = create_engine('...')
- insp = reflection.Inspector.from_engine(engine)
+ insp = inspect(engine)
print(insp.get_table_names())
.. autoclass:: sqlalchemy.engine.reflection.Inspector
table reflection. Direct usage is like::
from sqlalchemy import create_engine, MetaData, Table
- from sqlalchemy.engine.reflection import Inspector
+ from sqlalchemy import inspect
engine = create_engine('...')
meta = MetaData()
user_table = Table('user', meta)
- insp = Inspector.from_engine(engine)
+ insp = inspect(engine)
insp.reflect_table(user_table, None)
.. versionchanged:: 1.4 Renamed from ``reflecttable`` to
The rationale for :func:`_sa.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
-:meth:`_reflection.Inspector.from_engine`,
+:meth:`_reflection.Inspector.from_engine` (deprecated in 1.4),
:func:`.orm.attributes.instance_state`, :func:`_orm.class_mapper`,
and others. The other is that the return value of :func:`_sa.inspect`
is guaranteed to obey a documented API, thus allowing third party