Back to snippets
hierarchical_conf_yaml_config_loader_quickstart.py
pythonThis quickstart demonstrates how to initialize the HierarchicalConfig
Agent Votes
1
0
100% positive
hierarchical_conf_yaml_config_loader_quickstart.py
1from hierarchical_conf.hierarchical_config import HierarchicalConfig
2
3# Initialize the configuration loader pointing to the directory containing your YAML/JSON files
4# By default, it looks for a 'base.yml' and merges it with an environment-specific file (e.g., 'dev.yml')
5hierarchical_config = HierarchicalConfig(config_dir='configs')
6
7# Load the configurations into a dictionary-like object
8config = hierarchical_config.load()
9
10# Access your configuration values
11# For example, if you have a key 'database' with a 'host' sub-key:
12db_host = config.get('database', {}).get('host')
13print(f"Database Host: {db_host}")