Skip to main content

YAML configuration loader with advanced features.

Project description

Yamlo: YAML Configuration Loader

PyPI - Version PyPI - Python Version Tests License

yamlo is a YAML configuration loader for Python, designed for advanced configuration scenarios. It supports file inclusion, deep merging, environment variable injection, variable interpolation, and direct Python object instantiation from YAML and object instance referencing including their properties.

Features

  • Includes: Merge multiple YAML files using _includes.
  • Merging: Deep merge dictionaries, extend lists (!extend), and patch/replace dictionaries (!patch).
  • Environment Variables: Substitute values using !env VAR_NAME or !env {var: NAME, default: ...}.
  • Variable Interpolation: Reference other configuration values using ${path.to.value} syntax.
  • Object Instantiation: Create Python objects directly from YAML using !@module.path.ClassName or !@module.path.func
  • Instance Referencing: Use ${instance} to reference instantiated objects and their properties. Or ${instance.attr} to reference attributes of instantiated objects.

Example

_includes:
  - examples/base.yml
  - examples/override.yml

testenv: !env MY_TEST_VAR

app:
  name: TestApp
  version: "2.0"

paths:
  base: !@pathlib.Path /opt/${app.name}
  data: !@pathlib.Path
    - ${paths.base}
    - data

services:
  main: !@yamlo.SystemInfo
  secondary: !@yamlo.SystemInfo

hostdefault: !@yamlo.call "${services.main.as_dict}" 

pipeline:
  composite:
    first: ${services.main.host}
    second: ${services.secondary}

logs:
  - !@pathlib.Path /logs/${app.name}/main.log
  - !@pathlib.Path /logs/${app.name}/${services.main.host}.log

Installation

# Using uv (recommended)
uv pip install .[test,docs]

# Using pip
pip install .[test,docs]

Usage

After installation, you can use the CLI:

yamlo examples/test_config.yaml

Or use as a Python library:

from yamlo import load_config

config = load_config("examples/test_config.yaml")
print(config)

Development

  • Run tests:
    pytest

  • Build docs:
    mkdocs serve

  • Build package:
    hatch build

License

See LICENSE.

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

pyamlo-0.1.dev17.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

pyamlo-0.1.dev17-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pyamlo-0.1.dev17.tar.gz.

File metadata

  • Download URL: pyamlo-0.1.dev17.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for pyamlo-0.1.dev17.tar.gz
Algorithm Hash digest
SHA256 6f477369213091e683f198d067acf3c00556301aa8ecdd2be0a5eaf4bf449e19
MD5 8d4455035877b4924b55835c77b66e68
BLAKE2b-256 5e1a19ccd436c90ad3209bbdfec29e65ca2027abab243a48d03cd06416bdac70

See more details on using hashes here.

File details

Details for the file pyamlo-0.1.dev17-py3-none-any.whl.

File metadata

  • Download URL: pyamlo-0.1.dev17-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for pyamlo-0.1.dev17-py3-none-any.whl
Algorithm Hash digest
SHA256 ecee242297d56c9b57a6e36218a9546f8ef091fb1fdcd10fd0141a0dfe1c3d87
MD5 998a80dba31abaea5e45ac9239d51402
BLAKE2b-256 f9435819efb477a5e8bed353fafabbc7182be9ed367f096906504eff15e739c2

See more details on using hashes here.

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