Skip to main content

ConfigurationView

A view over an applications configuration dictionaries.

Attributes

AttributeTypeDescription
prefixstrString prefix applied to keys during lookup to support namespace-specific configuration access.
_keysList[str]List of transformation functions or alternative keys used to resolve configuration values when the primary key is missing.

Constructor

Signature

def ConfigurationView(
changes: Mapping,
defaults: Mapping = None,
keys: List[str] = None,
prefix: str = None
) - > None

Parameters

NameTypeDescription
changesMappingA mapping containing configuration changes.
defaultsMapping = NoneA list of dictionaries containing the default configuration values.
keysList[str] = NoneA list of keys to be used for configuration lookups.
prefixstr = NoneAn optional string prefix to be applied to configuration keys.

Methods


first()

@classmethod
def first(
*keys: str
) - > Any

Returns the first non-null value found for a series of provided configuration keys.

Parameters

NameTypeDescription
*keysstrA variable number of configuration keys to check in order.

Returns

TypeDescription
AnyThe first available value from the provided keys, or None if none are found.

get()

@classmethod
def get(
key: str,
default: Any
) - > Any

Attempts to retrieve a configuration value, returning a default if the key is not found.

Parameters

NameTypeDescription
keystrThe configuration key to search for.
defaultAnyThe fallback value to return if the key does not exist in any mapping.

Returns

TypeDescription
AnyThe configuration value if found; otherwise, the provided default value.

clear()

@classmethod
def clear() - > null

Remove all changes, but keep defaults.

Returns

TypeDescription
null

swap_with()

@classmethod
def swap_with(
other: [ConfigurationView](configurationview.md?sid=celery_utils_collections_configurationview)
) - > null

Replaces the current configuration state, including changes and defaults, with the state of another ConfigurationView.

Parameters

NameTypeDescription
other[ConfigurationView](configurationview.md?sid=celery_utils_collections_configurationview)The other configuration view instance from which to copy the state.

Returns

TypeDescription
null