Skip to main content

YAML configuration loader with advanced features.

Project description

PYAMLO: YAML Configuration Loader

PyPI Tests License

PYAMLO 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: !@pyamlo.SystemInfo
  secondary: !@pyamlo.SystemInfo

hostdefault: !@pyamlo.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

from pyamlo 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.dev25.tar.gz (13.7 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.dev25-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyamlo-0.1.dev25.tar.gz
Algorithm Hash digest
SHA256 1131c91556a6954becdcd02f2c8d595433d98589cae9bd696437abd24f88ec77
MD5 da360987d4de0c647a2f1c121770dc25
BLAKE2b-256 9448faaa9ad7e7427ed520aa1c99d767bcfcc8a4debf2b452ee2a168c43b7b3c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyamlo-0.1.dev25-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.dev25-py3-none-any.whl
Algorithm Hash digest
SHA256 8b3f28aa3805e36439a740febde3162f53de2ae88fadfae00490596b123c3b32
MD5 7018d110cd7655b25b5bad2328511f3f
BLAKE2b-256 3ad038fb52cb655c8154032d836761d6de877b921684719b0399157af639a7e5

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