Zero-dependency generic seeded generator framework with dedup and SQLite persistence.
Project description
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.
Project details
Release history Release notifications | RSS feed
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 ki_gen-1.0.0.tar.gz.
File metadata
- Download URL: ki_gen-1.0.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc025d08c0adfe039b5e3867e4cda37d77fb487be969e23e73352d83ca800b9e
|
|
| MD5 |
44f4d4b4d1017aaae890feca7e90964d
|
|
| BLAKE2b-256 |
b40c316ae0dc92866592fada3313b08cfd4e4fc61b8799594265ff7017db020c
|
Provenance
The following attestation bundles were made for ki_gen-1.0.0.tar.gz:
Publisher:
ci.yml on importt-ant/ki-gen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ki_gen-1.0.0.tar.gz -
Subject digest:
dc025d08c0adfe039b5e3867e4cda37d77fb487be969e23e73352d83ca800b9e - Sigstore transparency entry: 1339184286
- Sigstore integration time:
-
Permalink:
importt-ant/ki-gen@193bf6c43a649abbf1b1ebb8cdc8e8a392917a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/importt-ant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@193bf6c43a649abbf1b1ebb8cdc8e8a392917a81 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ki_gen-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ki_gen-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a37e3a4f3770c020f1ee955a50c81b59214b5a553c4459d3023bce9e9817dd
|
|
| MD5 |
35b753f4e1a37c8c4940bee62ba14704
|
|
| BLAKE2b-256 |
979de610995778b11653150b10ff5ccd4cadd79d7bf10f612e77e9da107d5732
|
Provenance
The following attestation bundles were made for ki_gen-1.0.0-py3-none-any.whl:
Publisher:
ci.yml on importt-ant/ki-gen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ki_gen-1.0.0-py3-none-any.whl -
Subject digest:
b1a37e3a4f3770c020f1ee955a50c81b59214b5a553c4459d3023bce9e9817dd - Sigstore transparency entry: 1339184375
- Sigstore integration time:
-
Permalink:
importt-ant/ki-gen@193bf6c43a649abbf1b1ebb8cdc8e8a392917a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/importt-ant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@193bf6c43a649abbf1b1ebb8cdc8e8a392917a81 -
Trigger Event:
push
-
Statement type: