pyyamlsettings

A Flyweight pattern for loading yaml files


License
MIT
Install
pip install pyyamlsettings==0.0.4

Documentation

Build Status Build Status Code style: black Coverage Status PyPI version BCH compliance

pyyamlsettings

A Flyweight pattern for loading yaml files in Python.

Installation

pyyamlsettings is python 2 and 3 compatible.

pip install pyyamlsettings

Overview

There is a YamlSettings class exposed by the package that allows you to load and query yaml files. Suppose we have a yaml file with the structure:

att1: 42
att2: "This is a string"

level1:
    a: 1
    b: 2
    level2:
        a: 3
        b: 4

We can load this file:

import os
import pyyamlsettings

yaml_file_path = os.path.join("tests", "test_yaml_file.yaml")
settings = pyyamlsettings.YamlSettings(yaml_file_path)

And read particular items with:

result = settings.get("att1")
print(result) # 42

result = settings.get("level1", "level2", "b")
print(result) # 4

Notes

Due to a deprecation message yaml.load was modified slightly.

yaml.load(input, Loader=yaml.FullLoader)

Users may have issues installing PyYAML as a dependency with the error message:

Cannot uninstall 'PyYAML'. It is a distutils installed project and ...

One way around this is to run:

pip install --ignore-installed PyYAML