directed_inputs_class.__main__
Module to handle directed inputs for the DirectedInputsClass library.
This module provides functionality for managing inputs from various sources (environment, stdin) and allows for dynamic merging, freezing, and thawing of inputs. It includes methods to decode inputs from JSON, YAML, and Base64 formats, as well as handling boolean and integer conversions.
Module Contents
Section titled “Module Contents”Classes
Section titled “Classes”DirectedInputsClass | A class to manage and process directed inputs from environment variables. |
|---|
class directed_inputs_class._main_.DirectedInputsClass(inputs: collections.abc.Mapping[str, Any] | None = None, from_environment: bool = True, from_stdin: bool = False, env_prefix: str | None = None, strip_env_prefix: bool = False)
Section titled “class directed_inputs_class._main_.DirectedInputsClass(inputs: collections.abc.Mapping[str, Any] | None = None, from_environment: bool = True, from_stdin: bool = False, env_prefix: str | None = None, strip_env_prefix: bool = False)”A class to manage and process directed inputs from environment variables.
stdin, or provided dictionaries.
Attributes: inputs (CaseInsensitiveDict): Dictionary to store inputs. frozen_inputs (CaseInsensitiveDict): Dictionary to store frozen inputs. from_stdin (bool): Flag indicating if inputs were read from stdin. merger (Merger): Object to manage deep merging of dictionaries.
Initialization
Section titled “Initialization”Initializes the DirectedInputsClass with the provided inputs.
Optionally loading additional inputs from environment variables and stdin.
Args: inputs (Mapping[str, Any] | None): Initial inputs to be processed. from_environment (bool): Whether to load inputs from environment variables. from_stdin (bool): Whether to load inputs from stdin. env_prefix (str | None): Optional prefix to filter environment variables. strip_env_prefix (bool): Whether to strip the prefix from environment keys.
static _normalize_inputs(inputs: collections.abc.Mapping[str, Any] | None) → dict[str, Any]
Section titled “static _normalize_inputs(inputs: collections.abc.Mapping[str, Any] | None) → dict[str, Any]”static _filtered_environment(env: collections.abc.Mapping[str, str], , env_prefix: str | None, strip_prefix: bool) → dict[str, str]
Section titled “static _filtered_environment(env: collections.abc.Mapping[str, str], , env_prefix: str | None, strip_prefix: bool) → dict[str, str]”_merge_inputs(base: collections.abc.Mapping[str, Any], incoming: collections.abc.Mapping[str, Any]) → dict[str, Any]
Section titled “_merge_inputs(base: collections.abc.Mapping[str, Any], incoming: collections.abc.Mapping[str, Any]) → dict[str, Any]”static _load_from_stdin() → dict[str, Any]
Section titled “static _load_from_stdin() → dict[str, Any]”static _coerce_text(value: Any) → Any
Section titled “static _coerce_text(value: Any) → Any”get_input(k: str, default: Any | None = None, required: bool = False, is_bool: bool = False, is_integer: bool = False, is_float: bool = False, is_path: bool = False, is_datetime: bool = False) → Any
Section titled “get_input(k: str, default: Any | None = None, required: bool = False, is_bool: bool = False, is_integer: bool = False, is_float: bool = False, is_path: bool = False, is_datetime: bool = False) → Any”Retrieves an input by key, with options for type conversion and default values.
This method leverages extended-data-types utilities for robust type conversions, including support for Path objects, datetime parsing, and numeric conversions.
Args: k (str): The key for the input. default (Any | None): The default value if the key is not found. required (bool): Whether the input is required. Raises an error if required and not found. is_bool (bool): Whether to convert the input to a boolean. is_integer (bool): Whether to convert the input to an integer. is_float (bool): Whether to convert the input to a float. is_path (bool): Whether to convert the input to a Path object. is_datetime (bool): Whether to convert the input to a datetime object.
Returns: Any: The retrieved input, potentially converted or defaulted.
decode_input(k: str, default: Any | None = None, required: bool = False, decode_from_json: bool = False, decode_from_yaml: bool = False, decode_from_base64: bool = False, allow_none: bool = True) → Any
Section titled “decode_input(k: str, default: Any | None = None, required: bool = False, decode_from_json: bool = False, decode_from_yaml: bool = False, decode_from_base64: bool = False, allow_none: bool = True) → Any”Decodes an input value, optionally from Base64, JSON, or YAML.
Args: k (str): The key for the input. default (Any | None): The default value if the key is not found. required (bool): Whether the input is required. Raises an error if required and not found. decode_from_json (bool): Whether to decode the input from JSON format. decode_from_yaml (bool): Whether to decode the input from YAML format. decode_from_base64 (bool): Whether to decode the input from Base64. allow_none (bool): Whether to allow None as a valid return value.
Returns: Any: The decoded input, potentially converted or defaulted.
freeze_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]
Section titled “freeze_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]”Freezes the current inputs, preventing further modifications until thawed.
Returns: CaseInsensitiveDict: The frozen inputs.
thaw_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]
Section titled “thaw_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]”Thaws the inputs, merging the frozen inputs back into the current inputs.
Returns: CaseInsensitiveDict: The thawed inputs.
merge_inputs(new_inputs: collections.abc.Mapping[str, Any] | None) → case_insensitive_dict.CaseInsensitiveDict[str, Any]
Section titled “merge_inputs(new_inputs: collections.abc.Mapping[str, Any] | None) → case_insensitive_dict.CaseInsensitiveDict[str, Any]”Merge new inputs into the current inputs using deep merge semantics.
Args: new_inputs (Mapping[str, Any] | None): Incoming values to merge.
Returns: CaseInsensitiveDict[str, Any]: The updated input mapping.
shift_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]
Section titled “shift_inputs() → case_insensitive_dict.CaseInsensitiveDict[str, Any]”Shifts between frozen and thawed inputs.
Returns: CaseInsensitiveDict: The resulting inputs after the shift.