Python Overview (beta)
Use chkit-py to define ClickHouse schemas and run the chkit migration workflow in Python. Python support is in beta; its API and CLI behavior may change between releases.
Install
Section titled “Install”pip install chkit-pychkit --helpThe package is named chkit-py on PyPI; the import name is chkit.
Quickstart
Section titled “Quickstart”pip install chkit-pychkit init # scaffold clickhouse.config.py + example schemachkit generate --name init # diff schema vs snapshot, write migrations/*.sqlchkit migrate --json # inspect the pending plan without applyingchkit migrate --apply # apply pending migrationschkit status # show applied / pending countschkit check --strict # CI gate (pending, drift, checksum)Use the CLI Reference for shared commands, flags, exit codes, and --json output. chkit --help and chkit <command> --help print the same help as the TypeScript CLI, listing chkit-py’s own commands and flags. chkit-py declares the ObsessionDB plugin flags on its commands, so --help-plugins lists them without loading the config. See the TypeScript-only features below. Config lives in clickhouse.config.py instead of clickhouse.config.ts, and schema files are Python modules instead of TypeScript modules.
Design
Section titled “Design”- Type checking. Public APIs have type annotations checked with
mypy --strictand pyright strict mode. - Pydantic v2 models. Schema objects are frozen. Pydantic validates them at construction and rejects unknown fields.
- Imperative core. Pure functions over data; minimal classes outside of Pydantic models and the CLI shell.
Interoperability with TypeScript chkit
Section titled “Interoperability with TypeScript chkit”Both implementations produce the same artifacts, so a project (or a team) can mix them:
- Snapshots: models serialize with the same camelCase JSON field names as
@chkit/core, sochkit/meta/snapshot.jsonis readable by either implementation. - Journal: migrations are recorded in the same ClickHouse
_chkit_migrationstable with the same schema and checksums. - SQL: the planner and renderer emit the same DDL statements for the same schema, including
ON CLUSTERstamping whenclickhouse.clusteris set.
Differences from the TypeScript version
Section titled “Differences from the TypeScript version”The schema/migration CLI and backfill engine share the TypeScript workflow. The following features are TypeScript-only:
chkit skillsproxy and thecreate-chkitscaffolder: usechkit initinstead.deps.ts-style dependency auto-install: install packages explicitly withpip.- The project
entrymodule: useschemaglobs to select Python schema files.
These pages
Section titled “These pages”Use the Core API to load and validate definitions, plan diffs, manage snapshots, and render SQL from Python. Use the Python tabs in the Schema DSL Reference for schema definitions.
Related
Section titled “Related”- Schema DSL Reference:
table(),view(),materialized_view(),dictionary()with TypeScript/Python tabs. - CLI Reference: commands and flags, shared by both implementations.
- Configuration Overview: config keys with tabbed examples, identical modulo file extension.