appsettings2.Configuration

class Configuration(normalize: bool = False, scrubkeys: bool = False)

The Configuration class is how applications access configuration data populated by ConfigurationProvider objects. It exposes configuration data through dynamic object attributes as well as a dictionary-like interface.

Initialize Configuration instance.

Parameters:
  • normalize – Option indicating whether or not attribute names should be normalized to upper-case on the resulting Configuration object, 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.

clear() None

Clear all configuration data.

static from_dict(source: dict, normalize: bool = False, scrubkeys: bool = False) Configuration

Construct a Configuration instance 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 Configuration object, 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 Configuration object derived from the source parameter.

static fromDictionary(source: dict, normalize: bool = False, scrubkeys: bool = False) Configuration

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

get(key: str, default: Any = None) Any

Get 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.

has_key(key: str) bool

Check for a specific configuration key.

items() list[tuple[str, Any]]

Get all key-value pairs as individal tuple items.

keys() list[str]

Get a list of all configuration keys.

pop(key: str) Any

Delete a specific configuration key.

set(key: str, value: Any) None

Set the configuration value for a configuration key.

Parameters:
  • key – The key to associate the configuration value.

  • value – The value to be associated with the configuration key.

to_dict() dict[str, Any]

Create 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.

toDictionary() dict[str, Any]

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

values() list[Any]

Get a list of all configuration values.