Skip to main content
Travis build status image

yamlreader

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 and Installation

Using pip

yamlreader is available with pip:

pip install yamlreader

Manual build and installation

If you want to make changes or use e.g. fpm for packaging this, you need to prepare the development environment to make further steps.

Prepare the source

git clone https://github.com/ImmobilienScout24/yamlreader.git
cd yamlreader
virtualenv venv
source venv/bin/activate
pip install pybuilder
pyb install_dependencies

Running tests

pyb verify

Generating a setup.py

pyb
cd target/dist/yamlreader-<VERSION>
./setup.py <whatever you want>

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.

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 yaml_load

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

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

yaml_load

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.0.4

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.0.4
File Size Uploaded
yamlreader-3.0.4.tar.gz 4.6 kB Details

Release files / yamlreader-3.0.4.tar.gz

Download URL yamlreader-3.0.4.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
765688036d57104ac26e4500ab088d42f4f2d06687ce3daa26543d7ae38c2470
BLAKE2b-256 checksum
How to use checksums
844b3af5480c26b3235dcd0984b9664b48115c2308c8c4f22e7162322be4ec0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

3.0.4 This release

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

3

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