stouputils.io package#

This module provides utilities for file management.

  • json_dump(): Writes the provided data to a JSON file with a specified indentation depth.

  • json_load(): Load a JSON file from the given path

  • csv_dump(): Writes data to a CSV file with customizable options

  • csv_load(): Load a CSV file from the given path

  • get_root_path(): Get the absolute path of the directory

  • relative_path(): Get the relative path of a file relative to a given directory

  • super_copy(): Copy a file (or a folder) from the source to the destination (always create the directory)

  • super_open(): Open a file with the given mode, creating the directory if it doesn’t exist (only if writing)

  • replace_tilde(): Replace the “~” by the user’s home directory

  • clean_path(): Clean the path by replacing backslashes with forward slashes and simplifying the path

  • copytree_with_progress(): Copy a directory tree with a colored progress bar

  • redirect_folder(): Move a folder and create a junction/symlink at the original location

  • safe_close(): Safely close a file descriptor or file object after flushing, ignoring any exceptions

import stouputils as stp

config = {"model": "resnet50", "layers": [64, 128, 256], "optimizer": {"name": "adam", "lr": 0.001}}

# Write the dictionary to a JSON file, creating the configs folder on the way
stp.json_dump(config, "configs/run.json")
stp.info("Content of configs/run.json:")
print(stp.read_file("configs/run.json"))

# Read it back
stp.info("Same data back:", stp.json_load("configs/run.json") == config)

# Copy it, creating the destination folders on the way
stp.info("Copied to", stp.super_copy("configs/run.json", "archive/2026/run.json"))

# Simplify a path
stp.info("Cleaned:", stp.clean_path("archive/2026/../2026/./run.json"))
Terminal output of the example, with the JSON file written

Submodules#