Skip to content

Runtime Introspection & DDL Synthesis

Runtime introspection, DDL extraction, and column profiling methods provided by driver.data_dictionary on SyncDriverAdapterBase and AsyncDriverAdapterBase.

Synchronous Introspection

SyncDataDictionaryBase

Bases: DataDictionaryDialectMixin, DataDictionaryMixin

Base class for synchronous data dictionary implementations.

Uses Python-compatible class layouts for cross-module inheritance. Child classes define dialect as a class attribute.

get_ddl

get_ddl(
    driver,
    object_name,
    schema=None,
    *,
    object_type="table",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get object DDL or an explicit unsupported DDL result.

Public alias of :meth:get_object_ddl that accepts schema positionally.

get_object_ddl

get_object_ddl(
    driver,
    object_name,
    *,
    schema=None,
    object_type="table",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get one object's DDL or an explicit unsupported DDL result.

object_name and schema are caller input and follow the dialect's identifier normalization (quote a name to match it exactly). Native catalog DDL is preferred; table DDL is synthesized from catalog metadata when prefer_native is False, when a target_dialect is requested, or when native DDL is unavailable.

Parameters:

Name Type Description Default
driver Any

Database driver instance.

required
object_name str

Object name.

required
schema str | None

Schema name, or None for the dialect default.

None
object_type str

Object kind such as table, view, or sequence.

'table'
include_dependencies bool

Whether native helpers should report dependencies.

True
prefer_native bool

Prefer native catalog DDL over synthesized DDL.

True
redact bool

Whether native helpers should redact sensitive values.

True
target_dialect str | None

Dialect to render or transpile the DDL into.

None

Returns:

Type Description
DDLResult

DDL result for the object.

get_schema_ddl

get_schema_ddl(
    driver,
    schema=None,
    *,
    include_domains=None,
    exclude_domains=None,
    exclude_tables=(),
    direction="create",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get schema DDL items in topological dependency order.

When prefer_native is set and no target_dialect is requested, adapters with a native schema DDL source supply the objects; tables whose native DDL is not faithful are synthesized from catalog metadata. Otherwise types, sequences, tables, and views are collected, and tables are synthesized from schema-wide catalog queries. direction="drop" only collects object identities and dependency edges; it never synthesizes table DDL. Domains that cannot be collected are reported in the result warnings.

Parameters:

Name Type Description Default
driver Any

Database driver instance.

required
schema str | None

Schema name, or None for the dialect default.

None
include_domains Sequence[str] | None

Domains to include (tables, views, sequences, types, ...).

None
exclude_domains Sequence[str] | None

Domains to exclude.

None
exclude_tables Sequence[str] | None

Table names to omit, matched as bare, unquoted, case-insensitive names with any schema qualification stripped.

()
direction Literal['create', 'drop']

create for CREATE statements in dependency order, drop for DROP ... IF EXISTS statements in reverse dependency order.

'create'
include_dependencies bool

Collect foreign keys and dependencies to order the output.

True
prefer_native bool

Prefer native catalog DDL over synthesized DDL.

True
redact bool

Whether native helpers should redact sensitive values.

True
target_dialect str | None

Dialect to render or transpile the DDL into.

None

Returns:

Type Description
MetadataResult

Schema DDL result.

get_table_profile

get_table_profile(
    driver, table, schema=None, *, sample_size=1000, target_dialect=None
)

Profile live table columns and infer refined SQL types from existing data.

Query failures (for example missing privileges) propagate to the caller.

infer_table_ddl_from_data

infer_table_ddl_from_data(
    driver,
    table,
    schema=None,
    *,
    target_table=None,
    target_dialect=None,
    sample_size=1000,
    primary_key=None,
)

Synthesize a refined table DDLResult by profiling live table data.

Asynchronous Introspection

AsyncDataDictionaryBase

Bases: DataDictionaryDialectMixin, DataDictionaryMixin

Base class for asynchronous data dictionary implementations.

Uses Python-compatible class layouts for cross-module inheritance. Child classes define dialect as a class attribute.

get_ddl

get_ddl(
    driver,
    object_name,
    schema=None,
    *,
    object_type="table",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get object DDL or an explicit unsupported DDL result.

Public alias of :meth:get_object_ddl that accepts schema positionally.

get_object_ddl

get_object_ddl(
    driver,
    object_name,
    *,
    schema=None,
    object_type="table",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get one object's DDL or an explicit unsupported DDL result.

object_name and schema are caller input and follow the dialect's identifier normalization (quote a name to match it exactly). Native catalog DDL is preferred; table DDL is synthesized from catalog metadata when prefer_native is False, when a target_dialect is requested, or when native DDL is unavailable.

Parameters:

Name Type Description Default
driver Any

Database driver instance.

required
object_name str

Object name.

required
schema str | None

Schema name, or None for the dialect default.

None
object_type str

Object kind such as table, view, or sequence.

'table'
include_dependencies bool

Whether native helpers should report dependencies.

True
prefer_native bool

Prefer native catalog DDL over synthesized DDL.

True
redact bool

Whether native helpers should redact sensitive values.

True
target_dialect str | None

Dialect to render or transpile the DDL into.

None

Returns:

Type Description
DDLResult

DDL result for the object.

get_schema_ddl

get_schema_ddl(
    driver,
    schema=None,
    *,
    include_domains=None,
    exclude_domains=None,
    exclude_tables=(),
    direction="create",
    include_dependencies=True,
    prefer_native=True,
    redact=True,
    target_dialect=None,
)

Get schema DDL items in topological dependency order.

When prefer_native is set and no target_dialect is requested, adapters with a native schema DDL source supply the objects; tables whose native DDL is not faithful are synthesized from catalog metadata. Otherwise types, sequences, tables, and views are collected, and tables are synthesized from schema-wide catalog queries. direction="drop" only collects object identities and dependency edges; it never synthesizes table DDL. Domains that cannot be collected are reported in the result warnings.

Parameters:

Name Type Description Default
driver Any

Database driver instance.

required
schema str | None

Schema name, or None for the dialect default.

None
include_domains Sequence[str] | None

Domains to include (tables, views, sequences, types, ...).

None
exclude_domains Sequence[str] | None

Domains to exclude.

None
exclude_tables Sequence[str] | None

Table names to omit, matched as bare, unquoted, case-insensitive names with any schema qualification stripped.

()
direction Literal['create', 'drop']

create for CREATE statements in dependency order, drop for DROP ... IF EXISTS statements in reverse dependency order.

'create'
include_dependencies bool

Collect foreign keys and dependencies to order the output.

True
prefer_native bool

Prefer native catalog DDL over synthesized DDL.

True
redact bool

Whether native helpers should redact sensitive values.

True
target_dialect str | None

Dialect to render or transpile the DDL into.

None

Returns:

Type Description
MetadataResult

Schema DDL result.

get_table_profile

get_table_profile(
    driver, table, schema=None, *, sample_size=1000, target_dialect=None
)

Profile live table columns and infer refined SQL types from existing data.

Query failures (for example missing privileges) propagate to the caller.

infer_table_ddl_from_data

infer_table_ddl_from_data(
    driver,
    table,
    schema=None,
    *,
    target_table=None,
    target_dialect=None,
    sample_size=1000,
    primary_key=None,
)

Synthesize a refined table DDLResult by profiling live table data.