Skip to main content

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

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

Metadata

Release files for yamlreader 3.0.1

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.1
File Size Uploaded
yamlreader-3.0.1.tar.gz 7.7 kB Details

Built distributions (wheels)

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

Total release size: 21.7 kB

Release files / yamlreader-3.0.1.tar.gz

Download URL yamlreader-3.0.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7a12335b49601084b4778854366c66a60ecb2fabf659ed86ceb343e04610250f
BLAKE2b-256 checksum
How to use checksums
b208e352fb9b4d34d3ec4852d9302ebf573c904466b60593dafef85735d8214d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL yamlreader-3.0.1-py2.7.egg
Size 7.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
be0a267fb8995e34e45c087badcff689cb2a7876c31db7358d65d85b5ba4ee1b
BLAKE2b-256 checksum
How to use checksums
098f4ddf114dda45191b7d2064c0e1e92b49456ad4f3bc5936dcd6a0c0a508e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL yamlreader-3.0.1-py2-none-any.whl
Size 6.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
f54fc40fe358bf5c8407a15d21a2e64ff92aa664c27609a2452ae05ea54accf8
BLAKE2b-256 checksum
How to use checksums
33419bd4cb0fdfc0ef186487724fb4abb13e5866d8358ff5cdceca925d90207b
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

This release

3.0.1 This release

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