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, and instantiate runs the same check before it builds; see the validation guide. omegakit json-schema turns the same dataclasses into a JSON Schema for YAML editors; see the editor-schemas guide. omegakit check validates config files from a terminal or a pre-commit hook, and omegakit show prints a config as it is assembled; see the command-line 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 >=2.3,<2.5, and CI also tests the newest OmegaConf pre-release in that range.

Dependabot proposes dependency and GitHub Actions updates weekly, and patch and minor updates merge automatically once CI passes. The runtime bounds in pyproject.toml are changed by hand.

Metadata

Release files for omegakit 0.5.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.5.0
File Size Uploaded Provenance Actions
omegakit-0.5.0.tar.gz 24.0 kB Without provenance Details for omegakit-0.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 55.3 kB

Release files / omegakit-0.5.0.tar.gz

Download URL omegakit-0.5.0.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0fab1f11c96cffd6567f0b014e33a01ca8ab61750fdf49ce4efab159c19f7d1a
BLAKE2b-256 checksum
How to use checksums
8fd04fc5718068f1da6790a2d687d73eef8090654b0109718d3d57e623f3db03
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.5.0-py3-none-any.whl

Download URL omegakit-0.5.0-py3-none-any.whl
Size 31.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
040767d3e4ef129530515d1b8d40ea1c9dfdce79ed9c8602fb65a13952ba9f3a
BLAKE2b-256 checksum
How to use checksums
ee5a1f9bc13eb3faa6692a0758ba8c5564bed1600f34f5c1a6d2eecda6d4a9a9
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.5.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