Hierarchical-conf is a Python library designed for loading settings from YAML files in a hierarchical manner. It processes a list of paths, loading configuration files and overwriting duplicated keys based on file precedence. The library supports Python 3.7+ and is currently at version 1.0.4, with releases appearing to be made as needed.
pip install hierarchical-confVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `hierarchical-conf` to load configurations based on the `ENVIRONMENT` variable. It creates two sample YAML files for 'dev' and 'production' environments, then loads and prints configuration values, showing how the `ENVIRONMENT` variable influences which settings are applied.
Always ensure the `ENVIRONMENT` environment variable is correctly set before initializing `HierarchicalConf`. Configuration files should follow the `[ENVIRONMENT]_conf.yml` naming convention.
Design your configuration hierarchy carefully. If a key needs to be consistent, define it once in the highest-precedence file. If it needs environment-specific overrides, ensure the environment-specific file is loaded later in the precedence.
Verify that the `conf_files_paths` list includes the absolute path to the directory containing your YAML files (e.g., `['/path/to/my/configs']`). Confirm that your configuration files are named `dev_conf.yml`, `production_conf.yml`, etc., matching the `ENVIRONMENT` variable.
Inspect all relevant `[ENVIRONMENT]_conf.yml` files for duplicate keys. Trace the loading order based on `conf_files_paths` and the `ENVIRONMENT` variable to understand which value has precedence. Adjust your configuration files or `conf_files_paths` order as needed.