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
Check out the source
Build a package
RPM: Run python setup.py clean bdist_rpm, results will be in dist/
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
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yamlreader-3.tar.gz | 5.5 kB | Without provenance | Details for yamlreader-3.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yamlreader-3-py2.7.egg | Legacy Egg format | - | - | Details for yamlreader-3-py2.7.egg |
| yamlreader-3-py2-none-any.whl | Python 2 | none | any | Details for yamlreader-3-py2-none-any.whl |
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 |
Security for yamlreader 3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.