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.dev27.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.dev27-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyamlo-0.1.dev27.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.dev27.tar.gz
Algorithm Hash digest
SHA256 4f96637eeb14289bb05a556667d19f55e6a4357ccc7b710fd86cdfd8fe22b36f
MD5 a663ee02a57bd3835de31a663e097009
BLAKE2b-256 321d7209ad434dd9453d4c02bdbc45aa840ddbf3522539d834fd69b0c2f437c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyamlo-0.1.dev27-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.dev27-py3-none-any.whl
Algorithm Hash digest
SHA256 e3b00edd0d69d2d73477230a7e1a3f2a2f209c30f91b22591850943377ab79aa
MD5 c5b12e2bcbefa29822cc21ac5ffdf6be
BLAKE2b-256 dfeb1e92f39f54f573c184c33ac62ab9a8e22582d44b97d243de153cff8360f4

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