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()\
    .add_provider(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: ConfigurationProvider

A ConfigurationProvider that populates configuration data from YAML.

Initialize a YamlConfigurationProvider instance.

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.

populate_configuration(configuration: Configuration) None

Populate the provided Configuration object using provider-specific methods.

populateConfiguration(configuration: Configuration) None

⚠️ DEPRECATED: use populate_configuration(...) instead.