Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ki_gen-1.0.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

ki_gen-1.0.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

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

Hashes for ki_gen-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dc025d08c0adfe039b5e3867e4cda37d77fb487be969e23e73352d83ca800b9e
MD5 44f4d4b4d1017aaae890feca7e90964d
BLAKE2b-256 b40c316ae0dc92866592fada3313b08cfd4e4fc61b8799594265ff7017db020c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ki_gen-1.0.0.tar.gz:

Publisher: ci.yml on importt-ant/ki-gen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for ki_gen-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1a37e3a4f3770c020f1ee955a50c81b59214b5a553c4459d3023bce9e9817dd
MD5 35b753f4e1a37c8c4940bee62ba14704
BLAKE2b-256 979de610995778b11653150b10ff5ccd4cadd79d7bf10f612e77e9da107d5732

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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