TomlConfigurationProvider
The TomlConfigurationProvider class allows you to load configuration data from a TOML file, TOML string, or TOML stream. Consider the following TOML:
[logging]
default = "Debug"
[ConnectionStrings]
SampleDb = "my_cxn_string"
When loaded using TomlConfigurationProvider the resulting Configuration object will have attribute names and a structure which matches the TOML, consider the following (where “example.toml” contains the above TOML):
from appsettings2 import *
from appsettings2.providers import *
config = ConfigurationBuilder()\
.add_provider(TomlConfigurationProvider('example.toml'))\
.build()
print(config['LOGGING_DEFAULT']) # outputs: "Debug"
print(config.ConnectionStrings.SampleDb) # outputs: "my_cxn_string"
- class TomlConfigurationProvider(filepath: str | None = None, toml: str | None = None, fd: int | None = None, required: bool = True)
Bases:
ConfigurationProviderA
ConfigurationProviderthat populates configuration data from TOML.Initialize a
TomlConfigurationProviderinstance.The filepath, toml, and fd parameters are mutually exclusive.
- Parameters:
filepath – Optional path to a TOML file used as a configuration source, defaults to None.
toml – Optional TOML 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
Configurationobject using provider-specific methods.
- populateConfiguration(configuration: Configuration) None
⚠️ DEPRECATED: use
populate_configuration(...)instead.