appsettings2.ConfigurationBuilder
- class ConfigurationBuilder(*, normalize: bool = False, scrubkeys: bool = False)
Builds a
Configurationobject from one or moreConfigurationProviderinstances.- Parameters:
normalize – Option indicating whether or not attribute names should be normalized to upper-case on the resulting
Configurationobject, defaults to False.scrubkeys – Option indicating whether or not attribute names should be scrubbed to be compatible with the Python lexer, defaults to False.
- addProvider(provider: ConfigurationProvider) ConfigurationBuilder
Adds the specified ConfigurationProvider object to the builder. Can be called multiple times to add multiple providers.
- Parameters:
provider – A class implementing the ConfigurationProvider abstract class.
- Returns:
Returns
ConfigurationBuilderfor method chaining.
- addCommandLine(argv=None) ConfigurationBuilder
Adds a
CommandLineConfigurationProvider, optionally overridingargv.- Parameters:
argv – Optional override of
sys.argv, defaults to None.- Returns:
Returns
ConfigurationBuilderfor method chaining.
- addEnvironment() ConfigurationBuilder
Adds a
EnvironmentConfigurationProvider.- Returns:
Returns
ConfigurationBuilderfor method chaining.
- addJson(filepath: str | None = None, *, json: str | None = None, fd: int | None = None, required: bool = True) ConfigurationBuilder
Adds a
JsonConfigurationProvider. The filepath, json, and fd parameters are mutually exclusive.- Parameters:
filepath – Optional path to a JSON file used as a configuration source, defaults to None.
json – Optional JSON 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.
- Returns:
Returns
ConfigurationBuilderfor method chaining.
- addToml(filepath: str | None = None, *, toml: str | None = None, fd: int | None = None, required: bool = True) ConfigurationBuilder
Adds a
TomlConfigurationProvider. 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.
- Returns:
Returns
ConfigurationBuilderfor method chaining.
- addYaml(filepath: str | None = None, *, yaml: str | None = None, fd: int | None = None, required: bool = True) ConfigurationBuilder
Adds a
YamlConfigurationProvider. 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.
- Returns:
Returns
ConfigurationBuilderfor method chaining.
- build() Configuration
Builds a Configuration object using the providers which have been added to the builder.
- Returns:
A Configuration object, populated with configuration data.