ki 🧬❗: ki-gen
Generic seeded generator framework with dedup and SQLite persistence.
Install
pip install ki-gen
# With Sobol quasi-random engine (optional)
pip install ki-gen[sobol]
Requires Python 3.12+.
Quick start
from kigen import Blueprint, Enum, Generator, Key, Param
# 1. Define a Key with typed fields
class SoundKey(Key):
pitch = Param(min=20, max=20_000)
sample_rate = Param(min=8000, max=96_000)
osc = Enum("sine", "square", "sawtooth", "triangle")
# 2. Create a Blueprint — configure overrides or pin static values
bp = (
Blueprint(SoundKey)
.configure("sample_rate", 44_100) # always 44100
.configure("pitch", Param(min=1000, max=2000)) # narrow range
)
# 3. Run the generator
gen = Generator(bp, seed=42)
key = gen.generate()
# SoundKey(id='...', pitch=1427, sample_rate=44100, osc='sine')
Core concepts
Key
A Key subclass is a structured parameter container. Declare fields using descriptors:
| Field | Description |
|---|---|
Param |
Numeric with optional min, max, step. Validated on assignment. |
Enum |
Categorical — options fixed at class definition. |
Pool |
Categorical — options populated once at runtime, then frozen. |
Field |
Abstract base — subclass for custom field types. |
class ToneKey(Key):
pitch = Param(min=40, max=20_000)
amplitude = Param(min=0.0, max=1.0, step=0.01)
osc = Enum("sine", "square", "sawtooth")
key = ToneKey(pitch=440, amplitude=0.8, osc="sine")
key.pitch = 99_999 # ValueError: above maximum
Blueprint
A Blueprint describes how each field should be produced — narrowed bounds, restricted choices, or pinned to a static value. It's engine-agnostic and reusable.
bp = Blueprint(ToneKey).configure("pitch", Param(min=200, max=800))
Recorder
Recorder handles dedup and persistence. It can be used directly as a recorder:
from kigen import Recorder, Store
with Store("my.db") as store:
recorder = Recorder(name="api-ingest", store=store)
key = ToneKey(pitch=440, amplitude=0.8, osc="sine")
is_new = recorder.record(key) # True (first time)
is_dup = recorder.record(key) # False (duplicate)
recorder.flush()
Generator
Generator combines a Blueprint with a pluggable Rengine (RNG engine) and adds the generate/dedup loop:
from kigen import Generator, Store
with Store("my.db") as store:
gen = Generator(bp, seed=42, store=store)
keys = gen.generate_many(100)
gen.flush()
Rengine
The RNG engine protocol. Two built-in implementations:
| Engine | Description |
|---|---|
RandomRengine |
stdlib random.Random — default when no engine is specified. |
SobolRengine |
Quasi-random Sobol sequence (requires scipy). O(1) fast-forward on resume. |
from kigen import SobolRengine
gen = Generator(bp, seed=42, rengine=SobolRengine(seed=42, dimensions=8))
Persistence
Store is a SQLite-backed store. Generators auto-resume from where they left off:
with Store("my.db") as store:
gen = Generator(bp, seed=42, store=store)
keys = gen.generate_many(50)
gen.flush()
# Later — resumes at key 51
with Store("my.db") as store:
gen = Generator(bp, seed=42, store=store)
more = gen.generate_many(50)
gen.flush()
Project structure
src/kigen/
├── __init__.py
├── blueprint.py # Blueprint — field randomization plan
├── key.py # Key — structured parameter container
├── store.py # Store — SQLite persistence
├── fields/
│ ├── field.py # Field (base descriptor)
│ ├── param.py # Param (numeric min/max/step)
│ ├── enum.py # Enum (categorical, class-time)
│ └── pool.py # Pool (categorical, runtime-populated)
├── recorders/
│ ├── recorder.py # Recorder (dedup + persistence)
│ └── generator.py # Generator (generation loop)
└── rengines/
├── protocol.py # Rengine protocol + FastForwardNotSupported
├── random.py # RandomRengine (stdlib)
└── sobol.py # SobolRengine (scipy)
API reference
See docs/index.md.
Metadata
Release files for ki-gen 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ki_gen-1.0.0.tar.gz | 26.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ki_gen-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.1 kB
Release files / ki_gen-1.0.0.tar.gz
| Download URL | ki_gen-1.0.0.tar.gz |
|---|---|
| Size | 26.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc025d08c0adfe039b5e3867e4cda37d77fb487be969e23e73352d83ca800b9e
|
|
BLAKE2b-256 checksum How to use checksums |
b40c316ae0dc92866592fada3313b08cfd4e4fc61b8799594265ff7017db020c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.
Transparency logRelease files / ki_gen-1.0.0-py3-none-any.whl
| Download URL | ki_gen-1.0.0-py3-none-any.whl |
|---|---|
| Size | 24.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1a37e3a4f3770c020f1ee955a50c81b59214b5a553c4459d3023bce9e9817dd
|
|
BLAKE2b-256 checksum How to use checksums |
979de610995778b11653150b10ff5ccd4cadd79d7bf10f612e77e9da107d5732
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 18, 2026.
Transparency log