Skip to main content

omegakit

Composable YAML configuration and Python object construction, powered by OmegaConf. Requires Python 3.12 or newer. The runtime dependencies are OmegaConf and typing_extensions.

Install with pip install omegakit. omegakit builds on OmegaConf but is not affiliated with or endorsed by the OmegaConf project.

from omegakit import instantiate, load_config

config = load_config("app.yaml", overrides=["worker.timeout=30"])
worker = instantiate(config.worker)
# defaults.yaml
timeout: 10
retries: 3
# app.yaml
worker:
  $base: ~import defaults.yaml
  $class: myapp.Worker
  timeout: 20

Configuration syntax

  • ~import file.yaml replaces a node with another file. Paths are relative to the importing file; ~import file.yaml#worker selects a subnode. Cycles are rejected.
  • $base merges a mapping or list of mappings underneath the current node. Later bases win over earlier bases; the current node wins over all bases.
  • $defaults supplies defaults to dict-valued siblings. Item values win.
  • $class imports and calls a Python class or callable with the node's arguments. Nested class nodes are instantiated recursively. A from_config method, if present, receives the materialized argument mapping instead of constructor keyword arguments.
  • $ref imports an object without calling it. It is supported inside an instantiated tree and cannot have sibling arguments (except $meta).
  • $partial: true returns a functools.partial; the value must be true or false. prepare(config) also defers the top-level call; nested objects are still built during preparation. Call-time arguments win over config arguments.
  • $meta is removed by default; load_config(..., keep_meta=True) preserves it. Instantiation always ignores metadata. keep_targets=False removes construction keys.
  • Every $-prefixed key is reserved. Loading keeps unknown ones, but instantiating a node with a $ key that is not allowed there raises.

Assembly runs imports, bases, and defaults, then applies overrides. Only structural references are resolved during assembly; other interpolations stay lazy and resolve against the assembled configuration. ??? can be filled by consumers and fails when accessed or instantiated if still missing. Overrides accept dictionaries, DictConfig, or OmegaConf key=value dotlists; they do not rerun structural assembly.

Errors raised by a constructor or from_config keep their type and get a note naming the failing node. The complete rules are in the configuration contracts.

Configurable provides a default from_config implementation. With a dataclass schema, class Model(Configurable[ModelConfig]), the config is validated and typed before from_config receives it; see the typed-configs guide. validate(cfg, schema=AppConfig) checks a loaded config without building anything; see the validation guide. omegakit json-schema turns the same dataclasses into a JSON Schema for YAML editors; see the editor-schemas guide. walk traverses mapping nodes depth-first, parents before children. The optional expected argument to instantiate and prepare is a typing hint, not runtime validation: with it, the result is typed as that class, and without it as Any. overrides is keyword-only.

Optional resolvers

Nothing is registered on import, and this library does not load .env files. Each resolver module carries its own dependencies, so omegakit.resolvers itself exports nothing; import from the module, such as omegakit.resolvers.paths.

from pathlib import Path
from omegakit.resolvers.paths import register_paths_resolver

register_paths_resolver({"data_dir": Path("/srv/data")})
# YAML: dataset: ${paths:data_dir}/training

Paths are copied as strings; relative paths remain relative and unknown keys return None. The caller defines the project layout.

from omegakit.resolvers.torch import register_torch_resolvers

register_torch_resolvers()
# YAML: dtype: ${dtype:float32}
# YAML: use_cuda: ${cuda_available:}

Install PyTorch separately for your platform before enabling these resolvers. It is not a package dependency. Importing the resolver module does not import Torch; registration without Torch raises an explanatory ImportError. Individual functions register_torch_dtype_resolver and register_cuda_available_resolver are available.

Register resolvers before loading configs. Registration is global to OmegaConf and refuses existing names unless replace=True is supplied. Resolver results are cached per config; replacing a resolver does not clear caches on existing configs.

Development

uv sync
uv run pytest
uv run ruff check
uv run ruff format --check
uv run pydoclint src
uv run pyright
uv run sphinx-build -W docs docs/_build
uv build

Tests that require a real Torch installation skip when it is absent.

This package imports and calls Python objects specified by configs, so configs must come from trusted sources. Assembly currently relies on private OmegaConf node APIs; the supported OmegaConf range is intentionally constrained to 2.3.x.

Metadata

Release files for omegakit 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omegakit 0.3.0
File Size Uploaded Provenance Actions
omegakit-0.3.0.tar.gz 18.8 kB Without provenance Details for omegakit-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for omegakit 0.3.0
File Interpreter ABI Platform Actions
omegakit-0.3.0-py3-none-any.whl Python 3 none any Details for omegakit-0.3.0-py3-none-any.whl

Total release size: 43.4 kB

Release files / omegakit-0.3.0.tar.gz

Download URL omegakit-0.3.0.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8965c2ac28d3cbe9828a669c2a274416018a204e1f8ace706c7d45f20881a601
BLAKE2b-256 checksum
How to use checksums
a763b3c34ab172e3e9970e9cbcc6e438dde101db8f52f98ea5238efb7a0265ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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 / omegakit-0.3.0-py3-none-any.whl

Download URL omegakit-0.3.0-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cb3f44562a1e71c99704ba958efa3fb0deb638198ffd5e6151cdb1baa01a13a
BLAKE2b-256 checksum
How to use checksums
52ede4748cae0bc68e2fa46670927fa793d2842b1814be984e8407f377fbc614
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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 omegakit 0.3.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page