Skip to main content

Synthetic data generation and schema evolution simulation for testing data pipelines

Project description

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

Development

git clone https://github.com/JesuFemi-O/kroft
cd kroft
uv sync --extra dev
uv run pytest

License

MIT

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

kroft-0.1.1.tar.gz (74.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kroft-0.1.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file kroft-0.1.1.tar.gz.

File metadata

  • Download URL: kroft-0.1.1.tar.gz
  • Upload date:
  • Size: 74.4 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for kroft-0.1.1.tar.gz
Algorithm Hash digest
SHA256 057eeb3a2bf50818d610b02eb7b20ee86d83b836af8eff2071235122ae74fa57
MD5 ef71ef6cd6cb2769a4396ce043656bde
BLAKE2b-256 fb46798c5a92287d99adcf9154f9d4e55d4663666c588a0a863e961b51b8e0d3

See more details on using hashes here.

File details

Details for the file kroft-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kroft-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for kroft-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da7b7750783c688df221709416cb376cdace9580e85b7afc006158fb829bc3cd
MD5 cf727f4fe8a8093967f2498cccb5ffca
BLAKE2b-256 934b26d2a143611e5a6ad50ae899a1913bf6d1bd9d9ed5ad9097a2506c38fcfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page