shared.io ========= .. py:module:: shared.io .. autoapi-nested-parse:: Input/output operations for JSON configuration files. Attributes ---------- .. autoapisummary:: shared.io.LOG Classes ------- .. autoapisummary:: shared.io.IO Module Contents --------------- .. py:class:: IO(file_path: Union[str, pathlib.Path]) Input/output class for JSON operations. .. py:method:: file_exists(file_path: Union[str, pathlib.Path]) -> bool :staticmethod: Check if the file exists. Args: file_path: Path to the file to check. Returns: bool: True if the file exists, False otherwise. .. py:method:: folder_check(checkpath: Union[str, pathlib.Path]) -> pathlib.Path :staticmethod: Check if the folder exists and create if it doesn't. Args: checkpath: File or folder path to check. Returns: Path: Passes checkpath input back as Path. .. py:method:: read(file_path: Optional[Union[str, pathlib.Path]] = None) -> Union[dict, list, str, int, float, bool] Read data from file. Args: file_path: If defined, data will be read from this file instead of the class variable. Defaults to None. Returns: dict | list | str | int | float | bool: Contents of the file if it exists. Returns False if the file does not exist. .. py:method:: set_file_path(new_path: Union[str, pathlib.Path]) -> None Set the file path. Args: new_path: File path to be set. Raises: Exception: If the extension is not defined. Exception: If the extension is not among valid extensions. .. py:method:: write(data: Any, file_path: Optional[Union[str, pathlib.Path]] = None) -> pathlib.Path Write data to the given or class-defined file_path. Args: data: Data to write. file_path: If defined, the data is written into the specified path rather than the class defined. Defaults to None. Returns: Path: Path to the file. Raises: Exception: If file path is not set. .. py:attribute:: file_path :type: Optional[pathlib.Path] :value: None .. py:attribute:: valid_extensions :value: ['.json'] .. py:data:: LOG