Skip to content

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.

DirectedInputsClassA class to manage and process directed inputs from environment variables.

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.

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.

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.

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.

Freezes the current inputs, preventing further modifications until thawed.

Returns: CaseInsensitiveDict: The frozen inputs.

Thaws the inputs, merging the frozen inputs back into the current inputs.

Returns: CaseInsensitiveDict: The thawed inputs.

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.

Shifts between frozen and thawed inputs.

Returns: CaseInsensitiveDict: The resulting inputs after the shift.