tmp_cleanup()

def tmp_cleanup(path) -> NoneType

Explicitly clean up a single registered temporary resource.

This function immediately deletes a temporary file or directory that was previously created and tracked. After calling this function, the resource is no longer tracked and cannot be cleaned up again.

Raises: Error: If the path is not tracked or the deletion fails

Args

  • path: string: The path string returned by tmp_dir(), tmp_dir_keep(), or tmp_file(). Raises an error if the path is not tracked.

Returns

None

tmp_cleanup_all()

def tmp_cleanup_all() -> NoneType

Clean up all registered temporary resources that are marked for cleanup.

This function deletes all temporary files and directories that were created with tmp_dir(), tmp_file(), etc. and are not marked with the keep flag. Resources created with tmp_dir_keep() are NOT deleted.

Call this function at the end of your script to ensure all temporary resources are properly cleaned up and don’t accumulate on the filesystem.

Raises: Error: If cleanup of any resource fails (cleanup continues for others)

Returns

None

tmp_dir()

def tmp_dir(prefix) -> string

Create a temporary directory and register it for automatic cleanup.

This function creates a temporary directory in the system’s default temp location with the specified prefix. The directory is automatically registered for cleanup, so it will be deleted when tmp_cleanup_all() is called or at script end (if cleanup is configured to run automatically).

Raises: Error: If the directory cannot be created

Args

  • prefix: string: Prefix for the directory name (default: “tmp-”)

Returns

str: The full path to the created temporary directory

tmp_dir_keep()

def tmp_dir_keep(prefix) -> string

Create a temporary directory that will NOT be automatically cleaned up.

This function creates a temporary directory in the system’s default temp location with the specified prefix. The directory is registered with the keep flag set to true, so it will NOT be deleted by tmp_cleanup_all(). This is useful for cache directories or persistent temporary storage.

Raises: Error: If the directory cannot be created

Args

  • prefix: string: Prefix for the directory name (default: “tmp-”)

Returns

str: The full path to the created temporary directory

tmp_file()

def tmp_file(suffix) -> string

Create a temporary file and register it for automatic cleanup.

This function creates a temporary file in the system’s default temp location with the specified suffix. The file is automatically registered for cleanup, so it will be deleted when tmp_cleanup_all() is called or at script end (if cleanup is configured to run automatically).

Raises: Error: If the file cannot be created

Args

  • suffix: string: Suffix for the file name (default: "" - no suffix) Examples: “.log”, “.txt”, “.json”, “.tmp”

Returns

str: The full path to the created temporary file (empty file)