ClickHouse schema and migration toolkit for Python (port of chkit TS)
Project description
chkit-py
A Python port of chkit — ClickHouse schema management and migration toolkit, written in strict, imperative Python.
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 --strictandpyrightstrict 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 current schema 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 1:1 for the core surface:
the schema DSL, the canonicalization + diff + planner pipeline, the codec
parser/renderer, validation, and the five CLI commands above. The journal
lives in the same ClickHouse _chkit_migrations table as the TS version, so
both implementations can share a database without divergence.
What is 1:1 today (covered by 271 ported tests + manual E2E against ClickHouse 24.8):
chkit.coremodel, canonicalization, codec, planner, validation, snapshot, SQL rendering.chkit init— same scaffold filenames, schema location, config shape, next-steps message as TS.chkit generate— same SQL header format (chkit-migration-format,cli-version, etc.), per-operation comments,safe_name-based filenames, collision suffixes,--name/--migration-id/--dryrunflags.chkit migrate— plan-by-default,--apply/--execute,--allow-destructive(exit code 3 when blocked).chkit status— same output text, same fields in--json, same database-missing warning.chkit check --strict— same policy gates (failOnPending,failOnChecksumMismatch,failOnDrift).chkit drift— snapshot vs current-schema diff with TS-shape output.- Journal table schema (
_chkit_migrations,ReplacingMergeTree(applied_at) ORDER BY (name)),CHKIT_JOURNAL_TABLEoverride, checksum mismatch detection.
What is intentionally out of scope for this first base — these are recorded in PARITY.md and tracked for future releases:
- Plugins (
@chkit/plugin-codegen,plugin-pull,plugin-backfill,plugin-obsessiondb) and the plugin runtime. chkit queryandchkit plugincommands.--tablescope filter ongenerate/migrate/check/drift.- Rename mappings (
--rename-table,--rename-column). - Per-operation async tracking in the journal.
- Live-DB introspection in
drift(column diff, settings diff, engine mismatch detection). - Interactive confirm prompts in
migrate. - User profile config and ObsessionDB credentials layer.
See PARITY.md for the full TS-vs-Python matrix and the rationale behind each deferral.
Development
git clone https://github.com/obsessiondb/chkit
cd chkit_python
python -m venv .venv
.venv\Scripts\python.exe -m pip install -e ".[dev]"
.venv\Scripts\python.exe -m pytest
.venv\Scripts\python.exe -m mypy src
.venv\Scripts\python.exe -m ruff check src tests
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 suite requires a reachable ClickHouse
(defaults to http://localhost:8123 with no password — matches a fresh
docker run of clickhouse-server). Override via CLICKHOUSE_URL /
CLICKHOUSE_PASSWORD.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chkit_py-0.1.4.tar.gz.
File metadata
- Download URL: chkit_py-0.1.4.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
309cdb8c61c478b438a4472a7a405e8f3c9d99d373e7b9308164231248d76b65
|
|
| MD5 |
6d4668dc0e653129bd09925ada99112c
|
|
| BLAKE2b-256 |
9a95e3bb1ef0f01c71e74953dee6ade281bddf0f8b5aa2f1c16ec96dee894030
|
File details
Details for the file chkit_py-0.1.4-py3-none-any.whl.
File metadata
- Download URL: chkit_py-0.1.4-py3-none-any.whl
- Upload date:
- Size: 49.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39c218a02bd3728624c6cae0b5906d0d9f7f263aa929304abd97618fecfa6028
|
|
| MD5 |
47c05f281bec7cbe6baae1ed80f966e9
|
|
| BLAKE2b-256 |
ed77d690bf9ac88298db0d3a9708b02afc17392ee0eb5d0521609e09127cc142
|