Skip to content

etlantic-sqlmodel API

Status: Available in ETLantic 0.41.0. SQLModel bridge helpers. Install narrative: package README. Hub: Optional packages API.

Setup

pip install 'etlantic-sqlmodel==0.41.0'
import etlantic_sqlmodel
print(etlantic_sqlmodel.__version__)

Failure modes

Topic Behavior
Model mismatch Type/bridge errors

Public API

etlantic_sqlmodel

etlantic-sqlmodel — ContractModel ↔ SQLModel bridge + CP1 reference stores.

AliasRow

Bases: SQLModel

Scoped alias pointing at an immutable revision.

EnvironmentRow

Bases: SQLModel

Deployment / promotion environment directory row.

LogicalIdentityRow

Bases: SQLModel

Stable logical identity preserved across revisions.

PromotionRow

Bases: SQLModel

Immutable promotion record preserving logical_id.

RevisionRow

Bases: SQLModel

Immutable append-only registry revision.

SecurityDomainRow

Bases: SQLModel

Security-domain directory row.

SQLModelDefinitionRepository

SQLModelDefinitionRepository(engine: Engine)

Workspace-scoped definition registry backed by SQLModel.

SqlModelEventStore

SqlModelEventStore(engine: Engine)

Minimal SQLModel-backed EventStore with tenant/workspace isolation.

SqlModelRegistryProvider dataclass

SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)

SQLModel :class:RegistryProvider with shared suspension checks.

SqlModelRevisionRegistry dataclass

SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)

Append-only SQLModel revision store with aliases and promotions.

SQLModelSubmissionStore

SQLModelSubmissionStore(engine: Engine)

Durable acceptance store with ADR-016 scoped idempotency and run observation.

SqlModelTenantDirectory dataclass

SqlModelTenantDirectory(engine: Engine)

SQLModel tenant directory with isolation and suspension fail-closed.

SqlModelWorkspaceDirectory dataclass

SqlModelWorkspaceDirectory(engine: Engine, tenants: SqlModelTenantDirectory | None = None)

SQLModel workspace directory keyed by (tenant_id, workspace_id).

TenantRow

Bases: SQLModel

Durable tenant directory row (CP2 / 040-P).

WorkspaceRow

Bases: SQLModel

Durable workspace directory row (tenant-owned).

SqlModelIntegrationPlugin

Schema bridge helpers without ORM sessions or migrations.

create_control_plane_tables

create_control_plane_tables(engine: Engine) -> None

Create CP reference tables.

Intended for tests and local demos — not a production migration path.

create_registry_tables

create_registry_tables(engine: Engine) -> None

Create CP2 registry tables.

Intended for tests and local demos — not a production migration path. Prefer :mod:etlantic_sqlmodel.migrations.

create_sqlite_engine

create_sqlite_engine(url: str = 'sqlite://', **kwargs: Any) -> Engine

Create an engine; use a file URL for restart durability tests.

make_session_factory

make_session_factory(engine: Engine)

Return a zero-arg factory that opens a short-lived Session.

request_scoped_session

request_scoped_session(engine: Engine)

FastAPI-compatible dependency generator for a request-scoped session.

Sessions stay in the API layer — never pass them into pipeline runtimes.

session_scope

session_scope(engine: Engine) -> Iterator[Session]

Yield a session that commits on success and rolls back on error.

apply_migrations

apply_migrations(engine: Engine) -> str | None

Upgrade to the latest migration (SQLite-friendly for tests).

current_version

current_version(engine: Engine) -> str | None

Return the applied migration version, or None on a fresh database.

downgrade

downgrade(engine: Engine, *, target: str | None = None) -> str | None

Roll back migrations down to target (None = empty schema).

upgrade

upgrade(engine: Engine, *, target: str | None = None) -> str | None

Apply pending migrations up to target (default: latest).

contract_to_sqlmodel

contract_to_sqlmodel(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> type[SQLModel]

Generate a SQLModel table class from a Data / ContractModel class.

contract_to_sqlmodel_source

contract_to_sqlmodel_source(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> str

Generate importable SQLModel source for a Data / ContractModel class.

sqlmodel_to_contract

sqlmodel_to_contract(model_cls: type[Any]) -> dict[str, Any]

Extract draft contract metadata from a SQLModel table class.

primary_key_fields

primary_key_fields(model_cls: type[Any]) -> list[str]

Return ordered primary-key column names from a SQLModel table class.

validate_model_primary_keys

validate_model_primary_keys(model_cls: type[Any], *, expected_keys: tuple[str, ...] | list[str] | None = None) -> ValidationReport

Fail closed when a SQLModel table lacks the expected primary key.

compare_metadata

compare_metadata(left: Any, right: Any) -> ValidationReport

Compare contract and SQLModel metadata; return a ValidationReport.

create_plugin

create_plugin() -> SqlModelIntegrationPlugin

Entry-point factory for tooling and conformance helpers.

run_conformance_checks

run_conformance_checks(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> ValidationReport

Round-trip contract → SQLModel → metadata and compare schemas.

control_plane

Optional SQLModel control-plane reference stores (CP1/CP2).

Persistence models are separate from HTTP response models. Sessions are request-scoped helpers and must not be passed into pipeline runtimes. create_control_plane_tables / create_registry_tables are for tests/demos — production must apply versioned migrations under etlantic_sqlmodel.migrations.

SQLModelDurableWorkStore

SQLModelDurableWorkStore(engine: Engine, *, admission_limit: int | None = None, store_id: str = 'default')

Transactional DurableWorkStore backed by a SQL snapshot row.

AliasRow

Bases: SQLModel

Scoped alias pointing at an immutable revision.

DurableSnapshotRow

Bases: SQLModel

Transactional CP3 durable-work snapshot (reference provider).

One logical store per engine; mutations load/save under a DB transaction so accept+outbox and fencing CAS share commit boundaries.

EnvironmentRow

Bases: SQLModel

Deployment / promotion environment directory row.

LogicalIdentityRow

Bases: SQLModel

Stable logical identity preserved across revisions.

PromotionRow

Bases: SQLModel

Immutable promotion record preserving logical_id.

RevisionRow

Bases: SQLModel

Immutable append-only registry revision.

SecurityDomainRow

Bases: SQLModel

Security-domain directory row.

TenantRow

Bases: SQLModel

Durable tenant directory row (CP2 / 040-P).

WorkspaceRow

Bases: SQLModel

Durable workspace directory row (tenant-owned).

BackupTranscript dataclass

BackupTranscript(schema: str, created_at: str, tenants: tuple[dict[str, Any], ...], workspaces: tuple[dict[str, Any], ...], revisions: tuple[dict[str, Any], ...], logicals: tuple[dict[str, Any], ...] = (), aliases: tuple[dict[str, Any], ...] = (), promotions: tuple[dict[str, Any], ...] = (), environments: tuple[dict[str, Any], ...] = (), security_domains: tuple[dict[str, Any], ...] = ())

Structured backup transcript (scope-preserving).

SqlModelRegistryProvider dataclass

SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)

SQLModel :class:RegistryProvider with shared suspension checks.

SqlModelRevisionRegistry dataclass

SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)

Append-only SQLModel revision store with aliases and promotions.

SqlModelTenantDirectory dataclass

SqlModelTenantDirectory(engine: Engine)

SQLModel tenant directory with isolation and suspension fail-closed.

SqlModelWorkspaceDirectory dataclass

SqlModelWorkspaceDirectory(engine: Engine, tenants: SqlModelTenantDirectory | None = None)

SQLModel workspace directory keyed by (tenant_id, workspace_id).

SQLModelDefinitionRepository

SQLModelDefinitionRepository(engine: Engine)

Workspace-scoped definition registry backed by SQLModel.

SqlModelEventStore

SqlModelEventStore(engine: Engine)

Minimal SQLModel-backed EventStore with tenant/workspace isolation.

SQLModelSubmissionStore

SQLModelSubmissionStore(engine: Engine)

Durable acceptance store with ADR-016 scoped idempotency and run observation.

create_durable_tables

create_durable_tables(engine: Engine) -> None

Create CP3 durable tables (tests/demos only).

backup_round_trip

backup_round_trip(source: Engine, destination: Engine) -> BackupTranscript

Dump source and load into destination; return the transcript.

dump_registry_sqlite

dump_registry_sqlite(engine: Engine) -> BackupTranscript

Dump tenants, workspaces, and revisions from a registry SQLite engine.

load_registry_sqlite

load_registry_sqlite(engine: Engine, transcript: BackupTranscript, *, create_tables: bool = True) -> SqlModelRegistryProvider

Restore tenants/workspaces/revisions into engine, preserving scope.

read_backup_transcript

read_backup_transcript(path: str | Path) -> BackupTranscript

Read a backup transcript JSON file.

write_backup_transcript

write_backup_transcript(path: str | Path, transcript: BackupTranscript) -> None

Write a backup transcript JSON file.

collect_revision_hits

collect_revision_hits(provider: SqlModelRegistryProvider, ctx: ControlPlaneContext, *, logical_id: str | None = None, kind: str | None = None) -> Sequence[RevisionSearchHit]

Return metadata-only hits for ctx scope (no content bodies).

create_registry_tables

create_registry_tables(engine: Engine) -> None

Create CP2 registry tables.

Intended for tests and local demos — not a production migration path. Prefer :mod:etlantic_sqlmodel.migrations.

create_sqlite_engine

create_sqlite_engine(url: str = 'sqlite://', **kwargs: Any) -> Engine

Create an engine; use a file URL for restart durability tests.

make_session_factory

make_session_factory(engine: Engine)

Return a zero-arg factory that opens a short-lived Session.

request_scoped_session

request_scoped_session(engine: Engine)

FastAPI-compatible dependency generator for a request-scoped session.

Sessions stay in the API layer — never pass them into pipeline runtimes.

session_scope

session_scope(engine: Engine) -> Iterator[Session]

Yield a session that commits on success and rolls back on error.

create_control_plane_tables

create_control_plane_tables(engine: Engine) -> None

Create CP reference tables.

Intended for tests and local demos — not a production migration path.

durable_stores

SQLModel-backed DurableWorkStore (CP3 / 041-P).

Reference provider: each mutating call loads the durable snapshot inside a database transaction, applies MemoryDurableWorkStore semantics, and writes the snapshot back with an optimistic payload_version check before commit.

Production note: apply versioned migrations — do not rely on create_durable_tables as the sole schema path.

SQLModelDurableWorkStore
SQLModelDurableWorkStore(engine: Engine, *, admission_limit: int | None = None, store_id: str = 'default')

Transactional DurableWorkStore backed by a SQL snapshot row.

create_durable_tables
create_durable_tables(engine: Engine) -> None

Create CP3 durable tables (tests/demos only).

models

SQLModel persistence tables for control-plane reference stores.

These are persistence models only — not HTTP response models and not ETLantic pipeline contracts.

TenantRow

Bases: SQLModel

Durable tenant directory row (CP2 / 040-P).

WorkspaceRow

Bases: SQLModel

Durable workspace directory row (tenant-owned).

LogicalIdentityRow

Bases: SQLModel

Stable logical identity preserved across revisions.

RevisionRow

Bases: SQLModel

Immutable append-only registry revision.

AliasRow

Bases: SQLModel

Scoped alias pointing at an immutable revision.

PromotionRow

Bases: SQLModel

Immutable promotion record preserving logical_id.

EnvironmentRow

Bases: SQLModel

Deployment / promotion environment directory row.

SecurityDomainRow

Bases: SQLModel

Security-domain directory row.

DurableSnapshotRow

Bases: SQLModel

Transactional CP3 durable-work snapshot (reference provider).

One logical store per engine; mutations load/save under a DB transaction so accept+outbox and fencing CAS share commit boundaries.

registry_backup

Registry SQLite backup/restore transcript helpers (CP2 / 040-O).

Dump and load tenants, workspaces, and revisions while preserving compound tenant/workspace scope. Content bodies are included for round-trip fidelity but histories/impact remain separate (metadata-only stores).

BackupTranscript dataclass
BackupTranscript(schema: str, created_at: str, tenants: tuple[dict[str, Any], ...], workspaces: tuple[dict[str, Any], ...], revisions: tuple[dict[str, Any], ...], logicals: tuple[dict[str, Any], ...] = (), aliases: tuple[dict[str, Any], ...] = (), promotions: tuple[dict[str, Any], ...] = (), environments: tuple[dict[str, Any], ...] = (), security_domains: tuple[dict[str, Any], ...] = ())

Structured backup transcript (scope-preserving).

dump_registry_sqlite
dump_registry_sqlite(engine: Engine) -> BackupTranscript

Dump tenants, workspaces, and revisions from a registry SQLite engine.

write_backup_transcript
write_backup_transcript(path: str | Path, transcript: BackupTranscript) -> None

Write a backup transcript JSON file.

read_backup_transcript
read_backup_transcript(path: str | Path) -> BackupTranscript

Read a backup transcript JSON file.

load_registry_sqlite
load_registry_sqlite(engine: Engine, transcript: BackupTranscript, *, create_tables: bool = True) -> SqlModelRegistryProvider

Restore tenants/workspaces/revisions into engine, preserving scope.

backup_round_trip
backup_round_trip(source: Engine, destination: Engine) -> BackupTranscript

Dump source and load into destination; return the transcript.

SQLModel-backed revision metadata search (CP2 / 040-O).

collect_revision_hits
collect_revision_hits(provider: SqlModelRegistryProvider, ctx: ControlPlaneContext, *, logical_id: str | None = None, kind: str | None = None) -> Sequence[RevisionSearchHit]

Return metadata-only hits for ctx scope (no content bodies).

registry_stores

SQLModel-backed RegistryProvider implementations (CP2 / 040-P).

Production deployments must apply versioned migrations — do not rely on create_all / create_registry_tables as the sole schema path.

SqlModelTenantDirectory dataclass
SqlModelTenantDirectory(engine: Engine)

SQLModel tenant directory with isolation and suspension fail-closed.

SqlModelWorkspaceDirectory dataclass
SqlModelWorkspaceDirectory(engine: Engine, tenants: SqlModelTenantDirectory | None = None)

SQLModel workspace directory keyed by (tenant_id, workspace_id).

SqlModelRevisionRegistry dataclass
SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)

Append-only SQLModel revision store with aliases and promotions.

SqlModelRegistryProvider dataclass
SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)

SQLModel :class:RegistryProvider with shared suspension checks.

create_registry_tables
create_registry_tables(engine: Engine) -> None

Create CP2 registry tables.

Intended for tests and local demos — not a production migration path. Prefer :mod:etlantic_sqlmodel.migrations.

session

Request-scoped SQLModel session helpers for control-plane stores.

create_sqlite_engine
create_sqlite_engine(url: str = 'sqlite://', **kwargs: Any) -> Engine

Create an engine; use a file URL for restart durability tests.

session_scope
session_scope(engine: Engine) -> Iterator[Session]

Yield a session that commits on success and rolls back on error.

make_session_factory
make_session_factory(engine: Engine)

Return a zero-arg factory that opens a short-lived Session.

request_scoped_session
request_scoped_session(engine: Engine)

FastAPI-compatible dependency generator for a request-scoped session.

Sessions stay in the API layer — never pass them into pipeline runtimes.

stores

SQLModel-backed DefinitionRepository and SubmissionStore implementations.

SQLModelDefinitionRepository
SQLModelDefinitionRepository(engine: Engine)

Workspace-scoped definition registry backed by SQLModel.

SQLModelSubmissionStore
SQLModelSubmissionStore(engine: Engine)

Durable acceptance store with ADR-016 scoped idempotency and run observation.

SqlModelEventStore
SqlModelEventStore(engine: Engine)

Minimal SQLModel-backed EventStore with tenant/workspace isolation.

create_control_plane_tables
create_control_plane_tables(engine: Engine) -> None

Create CP reference tables.

Intended for tests and local demos — not a production migration path.

migrations

Lightweight versioned migrations for etlantic-sqlmodel control-plane tables.

Production must apply these migrations (or an equivalent Alembic chain). Do not treat SQLModel.metadata.create_all / create_control_plane_tables / create_registry_tables as the sole production schema path.

current_version

current_version(engine: Engine) -> str | None

Return the applied migration version, or None on a fresh database.

upgrade

upgrade(engine: Engine, *, target: str | None = None) -> str | None

Apply pending migrations up to target (default: latest).

downgrade

downgrade(engine: Engine, *, target: str | None = None) -> str | None

Roll back migrations down to target (None = empty schema).

apply_migrations

apply_migrations(engine: Engine) -> str | None

Upgrade to the latest migration (SQLite-friendly for tests).

versions

Migration package versions.

001_registry_cp2

001 — CP2 registry directory and revision tables.

Production note: apply via etlantic_sqlmodel.migrations.upgrade (or an equivalent Alembic revision). create_all is for tests/demos only.

upgrade
upgrade(engine: Engine) -> None

Create CP2 registry tables.

downgrade
downgrade(engine: Engine) -> None

Drop CP2 registry tables (reverse of upgrade).

002_durable_cp3

002 — CP3 durable work snapshot tables.

Production note: apply via etlantic_sqlmodel.migrations.upgrade. create_all is for tests/demos only.

upgrade
upgrade(engine: Engine) -> None

Create CP3 durable tables.

downgrade
downgrade(engine: Engine) -> None

Drop CP3 durable tables.