Skip to main content

chkit-py

The beta Python implementation of chkit — a ClickHouse schema management and migration toolkit, written in strict, imperative Python. Its API and CLI behavior may change between releases.

Install

pip install chkit-py
chkit --help

The package is named chkit-py on PyPI; the import name is chkit.

Design

  • Type safety first. Every public surface is annotated. Ships clean under mypy --strict and pyright strict mode.
  • Pydantic v2 models. Runtime validation, frozen, extra="forbid".
  • Imperative core. Pure functions over data; minimal classes outside of Pydantic models and the CLI shell.
  • No magic. No dynamic imports, no runtime introspection of user code beyond what Pydantic provides.

Layout

src/chkit/
  core/          Schema DSL, diff engine, planner, SQL rendering, validation
  clickhouse/    ClickHouse client wrapper
  cli/           Typer-based CLI (init, generate, migrate, status, check, drift)

Quickstart

In a fresh project:

pip install chkit-py
chkit init                           # scaffold clickhouse.config.py + example schema
chkit generate --name init           # diff schema vs snapshot -> writes migrations/*.sql
chkit migrate --apply                # apply pending, journal in ClickHouse _chkit_migrations
chkit status                         # show applied / pending counts
chkit check --strict                 # CI gate (pending, drift, checksum)
chkit drift                          # snapshot vs live database diff

clickhouse.config.py reads its credentials from os.environ.get(...) by default. Set CLICKHOUSE_URL, CLICKHOUSE_USER, CLICKHOUSE_PASSWORD, CLICKHOUSE_DB (or override directly in the config).

TypeScript parity

This port matches the upstream TypeScript chkit on every user-facing surface: schema DSL, canonicalization + diff + planner pipeline, codec parser/renderer, validation, all CLI commands, the plugin runtime + its hooks, and every first-party plugin. The journal lives in the same ClickHouse _chkit_migrations table as the TS version, so both implementations can share a database without divergence.

Covered — 1:1 with TS:

  • chkit.core — model, canonicalization, codec, planner, validation, snapshot, SQL rendering, apply_on_cluster_to_plan. Includes the Dictionary primitive (dictionary() — full lifecycle: DSL, validation, diff/replace planning, --rename-dictionary, pull introspection, codegen), index-only projections, and function expressions in primaryKey/orderBy.
  • All CLI commands: init, generate (incl. --empty), migrate (incl. --retry / --abandon), status, check, drift (with live-DB compare), snapshot rebuild, pull, query, plugin. Codegen runs automatically after chkit generate when the plugin is registered (via the on_plan_created hook).
  • Flag surface — --rename-table / --rename-column, --table <selector> on generate/migrate/status/check/drift, --dryrun / --json / --config, --strict, --apply / --execute / --allow-destructive (exit code 3 when blocked).
  • Plugin runtime + all hooks (on_config_loaded, on_schema_loaded, on_plan_created, on_before_apply, on_after_apply, on_check, on_check_report, on_before_plugin_command, on_pull_introspect, on_init, on_complete).
  • First-party plugins: chkit_plugin_codegen (Pydantic model generator, including dictionary attribute models), chkit_plugin_obsessiondb (auth, service management, remote executor, backfill routing, Shared*-engine rewrites), chkit_plugin_backfill (beta backfill engine: smart size-aware chunk planning, async submit/poll execution loop with checkpoint + resume, mv_replay detection, and the managed-job submit path via ObsessionDB).
  • Journal — _chkit_migrations table (schema + CHKIT_JOURNAL_TABLE override + checksum mismatch detection), per-operation async tracking, INSERT race condition retry, ON CLUSTER + ReplicatedReplacingMergeTree engine when cluster mode is enabled.
  • ON CLUSTER <name> support — set clickhouse.cluster and every generated DDL statement is stamped as a final plan post-pass.

Not ported by design — Python convention or ecosystem difference:

  • chkit skills proxy (no npx analogue), create-chkit separate scaffolder (use chkit init --example <name> instead), deps.ts auto-install (Python convention is explicit pip install), internal-plugins/skill-hint AI-agent detection.

See DRIFT.md for the append-only decision log covering every port choice, known limitation, and won't-port item.

Development

The repository's bun run verify runs the Python lint, type check, tests and wheel build through uv (dependencies pinned in uv.lock, Python version in .python-version). To run them directly:

git clone https://github.com/obsessiondb/chkit
cd chkit
bun run infra:up    # local ClickHouse test stack (Docker)
cd chkit_python
uv run --locked --extra dev pytest
uv run --locked --extra dev mypy src
uv run --locked --extra dev ruff check src tests tests_cluster tests_workbench_api
bash scripts/build.sh   # sdist + wheel, twine check, wheel smoke test

Tests under tests/test_*_parity.py and tests/test_sql_validation_e2e.py are direct ports of the TS suites in packages/core/src/*.test.ts. The E2E tests target the local test stack (http://localhost:$CHKIT_TEST_PORT, default 8123, started by bun run infra:up) unless CLICKHOUSE_URL or CLICKHOUSE_HOST is set; a remote target also needs CLICKHOUSE_PASSWORD.

Metadata

Release files for chkit-py 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chkit-py 0.3.0
File Size Uploaded Provenance Actions
chkit_py-0.3.0.tar.gz 859.0 kB Without provenance Details for chkit_py-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chkit-py 0.3.0
File Interpreter ABI Platform Actions
chkit_py-0.3.0-py3-none-any.whl Python 3 none any Details for chkit_py-0.3.0-py3-none-any.whl

Total release size: 1.3 MB

Release files / chkit_py-0.3.0.tar.gz

Download URL chkit_py-0.3.0.tar.gz
Size 859.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c152e7181150b7fe979ff68670c0f24f4edbfd3607a71c204dae860433c09277
BLAKE2b-256 checksum
How to use checksums
d0d8d2b3674f67b5562542ca378fec30e9ddde200acf0bfa064258ca44551528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / chkit_py-0.3.0-py3-none-any.whl

Download URL chkit_py-0.3.0-py3-none-any.whl
Size 429.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e528448c857bef5a73aaa86a1291f42936d33270d41e10b4fbda25e9670fa738
BLAKE2b-256 checksum
How to use checksums
44948f43daff07b2d5c679f7cd48aab0019dd6cdd2f39d29cb979128ab9e5ef6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for chkit-py 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page