class Inspector(object):
Known subclasses: sqlalchemy.databases.postgresql.PGInspector
, sqlalchemy.databases.sybase.SybaseInspector
Performs database schema inspection.
The Inspector acts as a proxy to the reflection methods of the
~sqlalchemy.engine.interfaces.Dialect
, providing a
consistent interface as well as caching support for previously
fetched metadata.
A _reflection.Inspector
object is usually created via the
_sa.inspect
function, which may be passed an
_engine.Engine
or a _engine.Connection
:
from sqlalchemy import inspect, create_engine engine = create_engine('...') insp = inspect(engine)
Where above, the ~sqlalchemy.engine.interfaces.Dialect
associated
with the engine may opt to return an _reflection.Inspector
subclass that
provides additional methods specific to the dialect's target database.
Class Method | from_engine |
Construct a new dialect-specific Inspector object from the given engine or connection. |
Method | __init__ |
Initialize a new _reflection.Inspector . |
Method | get_check_constraints |
Return information about check constraints in table_name . |
Method | get_columns |
Return information about columns in table_name . |
Method | get_foreign_keys |
Return information about foreign_keys in table_name . |
Method | get_indexes |
Return information about indexes in table_name . |
Method | get_pk_constraint |
Return information about primary key constraint on table_name . |
Method | get_schema_names |
Return all schema names. |
Method | get_sequence_names |
Return all sequence names in schema . |
Method | get_sorted_table_and_fkc_names |
Return dependency-sorted table and foreign key constraint names in referred to within a particular schema. |
Method | get_table_comment |
Return information about the table comment for table_name. |
Method | get_table_names |
Return all table names in referred to within a particular schema. |
Method | get_table_options |
Return a dictionary of options specified when the table of the given name was created. |
Method | get_temp_table_names |
Return a list of temporary table names for the current bind. |
Method | get_temp_view_names |
Return a list of temporary view names for the current bind. |
Method | get_unique_constraints |
Return information about unique constraints in table_name . |
Method | get_view_definition |
Return definition for view_name . |
Method | get_view_names |
Return all view names in schema . |
Method | has_sequence |
Return True if the backend has a table of the given name. |
Method | has_table |
Return True if the backend has a table of the given name. |
Method | reflect_table |
Given a _schema.Table object, load its internal constructs based on introspection. |
Method | reflecttable |
See reflect_table. This method name is deprecated |
Class Method | _construct |
Undocumented |
Method | _connectable_insp |
Undocumented |
Method | _connection_insp |
Undocumented |
Method | _engine_insp |
Undocumented |
Method | _init_connection |
Undocumented |
Method | _init_engine |
Undocumented |
Method | _init_legacy |
Undocumented |
Method | _inspection_context |
Return an _reflection.Inspector from this one that will run all operations on a single connection. |
Method | _operation_context |
Return a context that optimizes for multiple operations on a single transaction. |
Method | _reflect_check_constraints |
Undocumented |
Method | _reflect_col_sequence |
Undocumented |
Method | _reflect_column |
Undocumented |
Method | _reflect_fk |
Undocumented |
Method | _reflect_indexes |
Undocumented |
Method | _reflect_pk |
Undocumented |
Method | _reflect_table_comment |
Undocumented |
Method | _reflect_unique_constraints |
Undocumented |
Class Variable | _index_sort_exprs |
Undocumented |
Instance Variable | _op_context_requires_connect |
Undocumented |
Instance Variable | bind |
Undocumented |
Instance Variable | dialect |
Undocumented |
Instance Variable | engine |
Undocumented |
Instance Variable | info_cache |
Undocumented |
Property | default_schema_name |
Return the default schema name presented by the dialect for the current engine's database user. |
Construct a new dialect-specific Inspector object from the given engine or connection.
This method differs from direct a direct constructor call of
_reflection.Inspector
in that the
~sqlalchemy.engine.interfaces.Dialect
is given a chance to
provide a dialect-specific _reflection.Inspector
instance,
which may
provide additional methods.
See the example at _reflection.Inspector
.
Parameters | |
bind | a ~sqlalchemy.engine.Connectable ,
which is typically an instance of
~sqlalchemy.engine.Engine or
~sqlalchemy.engine.Connection . |
sqlalchemy.databases.sybase.SybaseInspector
Initialize a new _reflection.Inspector
.
For a dialect-specific instance of _reflection.Inspector
, see
_reflection.Inspector.from_engine
Parameters | |
bind | a ~sqlalchemy.engine.Connectable ,
which is typically an instance of
~sqlalchemy.engine.Engine or
~sqlalchemy.engine.Connection . |
Return information about check constraints in table_name
.
Given a string table_name
and an optional string schema
, return
check constraint information as a list of dicts with these keys:
name - the check constraint's name
sqltext - the check constraint's SQL expression
dialect_options - may or may not be present; a dictionary with additional dialect-specific options for this CHECK constraint
New in version 1.3.8.
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
Return information about columns in table_name
.
Given a string table_name
and an optional string schema
, return
column information as a list of dicts with these keys:
name - the column's name
type - the type of this column; an instance of
~sqlalchemy.types.TypeEngine
nullable - boolean flag if the column is NULL or NOT NULL
default - the column's server default value - this is returned as a string SQL expression.
autoincrement - indicates that the column is auto incremented - this is returned as a boolean or 'auto'
comment - (optional) the comment on the column. Only some dialects return this key
computed - (optional) when present it indicates that this column is computed by the database. Only some dialects return this key. Returned as a dict with the keys:
New in version 1.3.16: - added support for computed reflection.
identity - (optional) when present it indicates that this column
is a generated always column. Only some dialects return this key.
For a list of keywords on this dict see _schema.Identity
.
New in version 1.4: - added support for identity column reflection.
dialect_options - (optional) a dict with dialect specific options
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
Returns | |
list of dictionaries, each representing the definition of a database column. |
Return information about foreign_keys in table_name
.
Given a string table_name
, and an optional string schema
, return
foreign key information as a list of dicts with these keys:
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
Return information about indexes in table_name
.
Given a string table_name
and an optional string schema
, return
index information as a list of dicts with these keys:
name - the index's name
column_names - list of column names in order
unique - boolean
column_sorting - optional dict mapping column names to tuple of sort keywords, which may include asc, desc, nulls_first, nulls_last.
New in version 1.3.5.
dialect_options - dict of dialect-specific index options. May not be present for all dialects.
New in version 1.0.0.
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
Return information about primary key constraint on table_name
.
Given a string table_name
, and an optional string schema
, return
primary key information as a dictionary with these keys:
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
schema
.Parameters | |
schema | Optional, retrieve names from a non-default schema.
For special quoting, use .quoted_name . |
Return dependency-sorted table and foreign key constraint names in referred to within a particular schema.
This will yield 2-tuples of (tablename, [(tname, fkname), (tname, fkname), ...]) consisting of table names in CREATE order grouped with the foreign key constraint names that are not detected as belonging to a cycle. The final element will be (None, [(tname, fkname), (tname, fkname), ..]) which will consist of remaining foreign key constraint names that would require a separate CREATE step after-the-fact, based on dependencies between tables.
See Also
_reflection.Inspector.get_table_names
.sort_tables_and_constraints
- similar method which works
with an already-given _schema.MetaData
.
Return information about the table comment for table_name.
Given a string table_name and an optional string schema, return table comment information as a dictionary with these keys:
Raises NotImplementedError for a dialect that does not support comments.
Return all table names in referred to within a particular schema.
The names are expected to be real tables only, not views.
Views are instead returned using the
_reflection.Inspector.get_view_names
method.
See Also
_reflection.Inspector.get_sorted_table_and_fkc_names
_schema.MetaData.sorted_tables
Parameters | |
schema | Schema name. If schema is left at None, the
database's default schema is
used, else the named schema is searched. If the database does not
support named schemas, behavior is undefined if schema is not
passed as None. For special quoting, use .quoted_name . |
Return a dictionary of options specified when the table of the given name was created.
This currently includes some options that apply to MySQL tables.
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
Return a list of temporary table names for the current bind.
This method is unsupported by most dialects; currently only SQLite implements it.
Return a list of temporary view names for the current bind.
This method is unsupported by most dialects; currently only SQLite implements it.
Return information about unique constraints in table_name
.
Given a string table_name
and an optional string schema
, return
unique constraint information as a list of dicts with these keys:
Parameters | |
table_name | string name of the table. For special quoting,
use .quoted_name . |
schema | string schema name; if omitted, uses the default schema
of the database connection. For special quoting,
use .quoted_name . |
**kw | Undocumented |
view_name
.Parameters | |
view_name | Undocumented |
schema | Optional, retrieve names from a non-default schema.
For special quoting, use .quoted_name . |
sqlalchemy.databases.postgresql.PGInspector
schema
.Parameters | |
schema | Optional, retrieve names from a non-default schema.
For special quoting, use .quoted_name . |
Return True if the backend has a table of the given name.
Parameters | |
sequence_name | name of the table to check |
schema | schema name to query, if not the default schema. |
Return True if the backend has a table of the given name.
.Inspector.has_table
method
replaces the _engine.Engine.has_table
method.Parameters | |
table_name | name of the table to check |
schema | schema name to query, if not the default schema. |
Given a _schema.Table
object, load its internal
constructs based on introspection.
This is the underlying method used by most dialects to produce table reflection. Direct usage is like:
from sqlalchemy import create_engine, MetaData, Table from sqlalchemy import inspect engine = create_engine('...') meta = MetaData() user_table = Table('user', meta) insp = inspect(engine) insp.reflect_table(user_table, None)
Parameters | |
table | a ~sqlalchemy.schema.Table instance. |
include_columns | a list of string column names to include in the reflection process. If None, all columns are reflected. |
exclude_columns | Undocumented |
resolve_fks | Undocumented |
_extend_on | Undocumented |
_reflection.Inspector
from this one that will run all
operations on a single connection.Return a context that optimizes for multiple operations on a single transaction.
This essentially allows connect()/close() to be called if we detected
that we're against an _engine.Engine
and not a
_engine.Connection
.
Undocumented
Undocumented
Undocumented
Undocumented