YamlConfigurationProvider
The YamlConfigurationProvider class allows you to load configuration data from a YAML file, YAML string, or YAML stream. Consider the following YAML:
logging:
default: Debug
ConnectionStrings:
SampleDb: my_cxn_string
When loaded using YamlConfigurationProvider the resulting Configuration object will have attribute names and a structure which matches the YAML, consider the following (where “example.yaml” contains the above YAML):
from appsettings2 import *
from appsettings2.providers import *
config = ConfigurationBuilder()\
.addProvider(YamlConfigurationProvider('example.yaml'))\
.build()
print(config['LOGGING_DEFAULT']) # outputs: "Debug"
print(config.ConnectionStrings.SampleDb) # outputs: "my_cxn_string"
- class YamlConfigurationProvider(filepath: str | None = None, *, yaml: str | None = None, fd: int | None = None, required: bool = True)
Bases:
ConfigurationProviderPopulates structured configuration data from YAML.
The filepath, yaml, and fd parameters are mutually exclusive.
- Parameters:
filepath – Optional path to a YAML file used as a configuration source, defaults to None.
yaml – Optional YAML string used as a configuration source, defaults to None.
fd – Optional file descriptor (int) to be used as a configuration source, defaults to None.
required – Optional parameter indicating whether the configuration source will raise ConfigurationException if the specified configuration source is missing, defaults to True.
- populateConfiguration(configuration: Configuration)
Populates the provided
Configurationobject using provider-specific methods.