pip install pyyaml
# config.yaml
database:
host: localhost
username: myuser
password: mypassword
# read_config.py
import yaml
def init_config_dict(config_file_path) -> dict:
with open('config.yaml', 'r') as f:
conf = yaml.safe_load(f)
return conf
conf_file_name = "config.yaml"
config = init_config_dict(conf_file_name)
print(config)
print(config["database"]["host"])