Input/output functions.

Author: Parker Hicks Date: 2025-04

Last updated: 2026-04-10 by Parker Hicks

checkdir(path, is_file=False)

Check if directory exists. If not, creates it.

Parameters:
  • path (str | Path) –

    A path to a directory or file.

  • is_file (bool, default: False ) –

    If True will check the parent of the file path.

Returns:
  • Path

    A pathlib.Path object of path.

load_bson(file, **kwargs)

Load dictionary from compressed BSON.

Parameters:
  • file (str | Path) –

    Path to file.bson to load.

load_json(file, encoding='utf-8')

Load dictionary from JSON.

Parameters:
  • file (str | Path) –

    Path to file.json to load.

load_txt(file, cols=1, delimiter=',', encoding='utf-8')

Loads a .txt file.

Parameters:
  • file (str | Path) –

    Path to file.txt to load.

  • cols (int, default: 1 ) –

    The number of columns in file.

  • delimiter (str | None, default: ',' ) –

    Character to separate entries if the cols>1.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.

Returns: An list of strings.

load_txt_sections(file, delimiter, encoding='utf-8')

Load a .txt file in sections.

Parameters:
  • file (str | Path) –

    Path to .txt file to load in sections.

  • delimiter (str) –

    Pattern to split entries in the .txt file.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.

Returns:
  • list[str]

    Sections of the .txt file separated by the specified delimiter.

load_yaml(file, encoding='utf-8')

Load a YAML dictionary.

Parameters:
  • file (str | Path) –

    Path to .yaml file to load.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.

save_bson(data, file, **kwargs)

Save dictionary to compressed BSON.

Parameters:
  • data (dict) –

    Dictionary to compress and save.

  • file (str | Path) –

    Path to file.txt to save data.

save_json(data, file, encoding='utf-8')

Saves a dictionary to file in JSON format.

Parameters:
  • data (dict) –

    Dictionary to save.

  • file (str | Path) –

    Path to file.txt to save data.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.

save_txt(data, file, delimiter=None, encoding='utf-8')

Save an array or list to a .txt file.

Parameters:
  • data (StringArray | list[str]) –

    An array or list of string entries.

  • file (str | Path) –

    Path to file.txt to save data.

  • delimiter (str | None, default: None ) –

    Allows for multidimensional arrays to be saves as single dimension arrays by concatenating each element in each row by the passed delimiter.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.

save_plain_text(data, file, encoding='utf-8')

Save a single string to a .txt file.

Parameters:
  • data (str) –

    Any string.

  • file (str | Path) –

    Path to file.txt to save data.

  • encoding (str, default: 'utf-8' ) –

    Text encoding format.