Configuration

Parse yaml file

It is a frequent practice to use yaml files for configuring Python applications. Though, the same is true for applications written in other programming languages. The code snippet below allows to parse a configuration file in yaml format and get values as a dictionary.

import yaml

def parse_configuration_file(file: str) -> dict:
    with open(file) as f:
        data = yaml.load(f, yaml.FullLoader)

    return data

configuration = parse_configuration_file("configuration.yaml")

In order for this snippet to work, the PyYAML package must be installed.