appsettings2.Configuration
- class Configuration(*, normalize: bool = False, scrubkeys: bool = False)
The
Configurationclass is how applications access configuration data populated byConfigurationProviderobjects. It exposes configuration data through dynamic object attributes as well as a dictionary-like interface.- 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.
- bind(target: object, key: str | None = None) Any
Binds the configuration values into the target object. Can optionally specify a configuration key to bind from.
- Parameters:
target – The object to bind configuration data into.
key – An optional confguration key to bind to, defaults to None which binds to the configuration root.
- Returns:
The original target object, modified in-place.
- static fromDictionary(source: dict, *, normalize: bool = False, scrubkeys: bool = False) Configuration
Constructs a
Configurationinstance from the supplied dictionary source.- Parameters:
source – The dictionary object to populate from.
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.
- Returns:
A
Configurationobject derived from the source parameter.
- get(key: str, default: Any = None) Any
Gets the configuration data associated with the specified key.
- Parameters:
key – The configuration key to get data for. Supports __ and : hierarchical delimiters.
default – The value to be returned if key does not exist, defaults to None
- Returns:
The configuration data associated with key, otherwise default.
- set(key: str, value: Any) None
Sets the configuration data for the specified key.
- Parameters:
key – The key to associate the configuration data.
value – The configuration data so be associated with key.
- toDictionary() dict[str, Any]
Creates a dictionary from the Configuration object.
- Returns:
A dictionary containing all keys and their associated values, in a structure that mimics the structure if the data contained within the Configuration object.