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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyamlo-0.1.dev26.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.dev26.tar.gz
Algorithm Hash digest
SHA256 4e0fee7b8b15fc57f383c84a08ad546d50f46eebcc08f2204b435205e25ef28d
MD5 17773815d42425ed92ee9dc02a52909c
BLAKE2b-256 625d72df24a24d3dd9c5ede35ac4f98e8601a4e015bbe4236151f8b3107b0274

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyamlo-0.1.dev26-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.dev26-py3-none-any.whl
Algorithm Hash digest
SHA256 7642df83eff77dd5ae495db01016031cd9ecc134976b8ea326e64de6ac98932f
MD5 b2fad91592765bdd64712eef68f3eaed
BLAKE2b-256 ad1c57baef917db4141a03f551b5abbba2a074c2d07a41a5ae6e581c82c9be2f

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