Skip to main content

Merge YAML data from a directory, a list of files or a file glob. With a directory, the YAML files (*.yaml) are sorted alphabetically. The YAML files are expected to contain a complex key-value structure and merged with the following rules:

  • lists get appended

  • hashes get merged by key

  • scalars (numbers, strings) are overwritten

  • everything else will fail

The purpose is to allow several YAML files instead of a single YAML file. We use it to help our software read configuration data from an arbitrary amount of YAML files instead of a single YAML file.

Read the unit test to see some examples.

Building

  1. Check out the source

  2. Build a package

  1. RPM: Run python setup.py clean bdist_rpm, results will be in dist/

  2. DEB: Install python-stdeb and run python setup.py –command-packages=stdeb.command clean bdist_deb, results will be in deb_dist

Running

The package installs a command line script yamlreader that can be used to read one or many YAML files and dump the merge result as a YAML document.

Contributing

Create a new virtual environment:

virtualenv venv

Activate the virtual environment:

source venv/bin/activate

Install requirements using pip:

pip install -r requirements.txt

Now you are able to run the tests:

python setup.py test

Use it in your software

Wherever you had been using the safe_load function of PyYAML to read a single YAML file you can use the yamlreader.yaml_load function as a replacement to read all *.yaml files in a directory:

from yamlreader import *

defaultconfig = {
        "loglevel" : "error",
        "some" : "value"
}

config = yaml_load("/etc/myapp", defaultconfig)

load_yaml

def yaml_load(source,defaultdata=None):
    """merge YAML data from files found in source

    Always returns a dict. The YAML files are expected to contain some kind of
    key:value structures, possibly deeply nested. When merging, lists are
    appended and dict keys are replaced. The YAML files are read with the
    yaml.safe_load function.

    source can be a file, a dir, a list/tuple of files or a string containing
    a glob expression (with ?*[]).

    For a dir all *.yaml files will be read in alphabetical order.

    defaultdata can be used to initialize the data.
    """

Release files for yamlreader 3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yamlreader 3
File Size Uploaded
yamlreader-3.tar.gz 5.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for yamlreader 3
File Interpreter ABI Platform
yamlreader-3-py2.7.egg Legacy Egg format - - Details
yamlreader-3-py2-none-any.whl Python 2 none any Details

Total release size: 15.8 kB

Release files / yamlreader-3.tar.gz

Download URL yamlreader-3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c9615778ac6846cc25376474531fc2f9136100fe5523317a34a0b495fb4efbcc
BLAKE2b-256 checksum
How to use checksums
fcd0bb0ca3add150a2b54ac49f7fb894475b3d9896ea2af8812af0529299d33a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / yamlreader-3-py2.7.egg

Download URL yamlreader-3-py2.7.egg
Size 5.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
2374a90055b100dcb2d56839e79d0cb68563c12cc306eeb30e448ba17ee5442a
BLAKE2b-256 checksum
How to use checksums
0a8cd56273b0b2053a976fd745b9f942f86aa16181a9025134f9b9be8436f8f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / yamlreader-3-py2-none-any.whl

Download URL yamlreader-3-py2-none-any.whl
Size 4.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
cf283bb6079a281d3c8d8e0b6a2b963f985ca28c3581fff902e9e0178e58784c
BLAKE2b-256 checksum
How to use checksums
58a17cd2466b1307a30a14ba572f9c0b61fc3fc23f697e98ce1b3552699d7388
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.0.4

1 release file

3.0.3

1 release file

3.0.2

1 release file

3.0.1

3 release files

3.0.0

3 release files

This release

3 This release

3 release files

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