Configuration Module#

SPDX-FileCopyrightText: 2025 DESY and the Constellation authors SPDX-License-Identifier: EUPL-1.2

Configuration class

class core.configuration.Configuration(root_dictionary: dict[str, Any] | None = None)#

Bases: Section

assemble() → bytes#
static disassemble(frame: bytes) → Configuration#
to_string(group: ConfigurationGroup) → str#
exception core.configuration.ConfigurationError(what: str)#

Bases: RuntimeError

class core.configuration.ConfigurationGroup(*values)#

Bases: Enum

ALL = 1#
INTERNAL = 3#
USER = 2#
exception core.configuration.InvalidTypeError(config: Section, key: str, vtype: str, ttype: str | None = None, reason: str | None = None)#

Bases: ConfigurationError

exception core.configuration.InvalidUpdateError(config: Section, key: str, reason: str)#

Bases: ConfigurationError

exception core.configuration.InvalidValueError(config: Section, key: str, reason: str)#

Bases: ConfigurationError

exception core.configuration.MissingKeyError(config: Section, key: str)#

Bases: ConfigurationError

class core.configuration.Section(prefix: str, dictionary: dict[str, Any])#

Bases: object

Class to access a section in the configuration

count(keys: list[str]) → int#

Check how many of the given keys are defined

get(key: str, default_value: Any | None = None, return_type: type[T] | Callable[[Any], T] | None = None) → T | Any#

Get value of a key in requested type

get_array(key: str, default_value: list[T] | None = None, element_type: type | Callable[[Any], T] | None = None) → list[T]#

Get list with uniform type

get_bool(key: str, default_value: bool | None = None) → bool#

Get value of key as string

get_enum(enum: type[T_E], key: str, default_value: T_E | None = None) → T_E#

Get value of key as enum

Note: this assumes that enum keys are case-insensitive

get_float(key: str, default_value: float | None = None, min_val: float | None = None, max_val: float | None = None) → float#

Get value of key as float

get_int(key: str, default_value: int | None = None, min_val: int | None = None, max_val: int | None = None) → int#

Get value of key as integer

get_keys() → list[str]#

Get the keys of the configuration section

get_num(key: str, default_value: int | float | None = None, return_type: type[int] | type[float] | None = None, min_val: int | float | None = None, max_val: int | float | None = None) → int | float#

Get value of key as number

get_path(key: str, default_value: Path | None = None, check_exists: bool = False) → Path#

Get value of key as path

get_section(key: str, default_value: dict[str, Any] | None = None) → Section#

Get nested configuration section

get_set(key: str, default_value: set[T] | None = None, element_type: type | Callable[[Any], T] | None = None) → set[T]#

Get set with uniform type

get_str(key: str, default_value: str | None = None) → str#

Get value of key as string

has(key: str) → bool#

Check if key is defined

set_alias(new_key: str, old_key: str) → None#

Set alias name for an already existing key

set_default(key: str, value: Any) → None#

Set default value for a key only if it is not defined yet

core.configuration.absolute_path_type(check_exists: bool) → Callable[[Any], Path]#

Return type function for absolute paths

core.configuration.enum_type(enum: type[T_E]) → Callable[[Any], T_E]#

Return type function for enum types

Note: this assumes that enum keys are case-insensitive

core.configuration.num_type(return_type: type[int] | type[float] | None, min_val: int | float | None, max_val: int | float | None) → Callable[[Any], int | float]#

Return type function for numeric types

core.configuration.resolve_env_variable(match: Match[str]) → str#

Resolve a variable name against environment variables

core.configuration.validate_dictionary_for_configuration(dictionary: Any, prefix: str = '') → None#