Kroft
A Python library for generating synthetic data and simulating schema evolution — useful for testing ETL pipelines, CDC workflows, and application behaviour under realistic data change scenarios.
Features
- Four composable scenarios — insert only, insert + update, insert + update + delete, schema evolution
- No forced complexity — opt into only what your test needs
- Configurable mutations — control fractions and probabilities per operation
- Schema evolution — add or drop columns at runtime while data keeps flowing
- Registry pattern — define reusable column generators with decorators
- 42 tests, 92% coverage — well-tested core with clear separation of concerns
Installation
pip install kroft
Or with uv:
uv add kroft
Quick start
import uuid, random, psycopg2
from kroft import ColumnDefinition, SchemaManager, BatchGenerator, MutationEngine
columns = {
"id": ColumnDefinition("id", "UUID", lambda: str(uuid.uuid4()), constraints="PRIMARY KEY"),
"item": ColumnDefinition("item", "TEXT", lambda: random.choice(["shoes", "shirt", "hat"])),
"price": ColumnDefinition("price", "FLOAT", lambda: round(random.uniform(10, 100), 2)),
"updated_at": ColumnDefinition("updated_at", "TIMESTAMP", lambda: "now()", protected=True),
"discount": ColumnDefinition("discount", "FLOAT", lambda: 0.0, reserved=True),
}
conn = psycopg2.connect("dbname=kroft_test user=postgres host=localhost")
manager = SchemaManager(conn, "public", "sales", columns)
manager.drop_table()
manager.create_table()
generator = BatchGenerator(schema=manager.get_active_columns())
engine = MutationEngine(
conn=conn, schema="public", table_name="sales",
primary_key="id", update_column="updated_at", generator=generator,
)
for _ in range(10):
generator.schema = manager.get_active_columns()
rows = generator.generate_batch(batch_size=100)
inserted_ids = engine.insert_batch(rows)
engine.update_batch(inserted_ids, fraction=0.2, probability=0.8)
print(engine.get_counters())
Supported scenarios
| Scenario | How |
|---|---|
| Insert only | engine.insert_batch(rows) |
| Insert + Update | insert_batch() + update_batch(ids, fraction=0.2) |
| Insert + Update + Delete | insert_batch() + update_batch() + delete_batch() |
| Schema evolution | EvolutionController.evolve(batch_num) |
Each scenario is independently composable — you are not forced into mutations or schema evolution unless you opt in.
Components
| Component | Role |
|---|---|
ColumnDefinition |
Defines a column: name, SQL type, generator function, and flags (reserved, protected) |
SchemaManager |
Manages table schema — CREATE/ALTER/DROP DDL, active vs reserved columns, version history |
BatchGenerator |
Generates synthetic rows from a column schema |
MutationEngine |
Performs insert, update, and delete operations against a live database |
EvolutionController |
Controls when and how the schema evolves during a simulation |
SimulationRunner |
Orchestrates a full simulation loop — generate, mutate, evolve |
Documentation
- Crash Course — walk through all four scenarios step by step
- Advanced Usage — registry pattern, custom loops, logging, schema history
- API Reference — full class and method documentation
Development
git clone https://github.com/JesuFemi-O/kroft
cd kroft
uv sync --extra dev
uv run pytest
License
MIT
Metadata
Release files for kroft 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kroft-0.1.1.tar.gz | 74.4 kB | Without provenance | Details for kroft-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kroft-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for kroft-0.1.1-py3-none-any.whl |
Total release size: 86.0 kB
Release files / kroft-0.1.1.tar.gz
| Download URL | kroft-0.1.1.tar.gz |
|---|---|
| Size | 74.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
057eeb3a2bf50818d610b02eb7b20ee86d83b836af8eff2071235122ae74fa57
|
|
BLAKE2b-256 checksum How to use checksums |
fb46798c5a92287d99adcf9154f9d4e55d4663666c588a0a863e961b51b8e0d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / kroft-0.1.1-py3-none-any.whl
| Download URL | kroft-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da7b7750783c688df221709416cb376cdace9580e85b7afc006158fb829bc3cd
|
|
BLAKE2b-256 checksum How to use checksums |
934b26d2a143611e5a6ad50ae899a1913bf6d1bd9d9ed5ad9097a2506c38fcfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for kroft 0.1.1
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.