file_tools

Overview

Function

download_or_copy_file(url, local_path)

Download a file from a URL to a local file asynchronously

get_canonical_name(file_path)

Get the canonical name of a file, without the extension

get_max_path_length(path)

get the max file name for the current OS

get_max_remote_path_length()

Get the maximum length of a remote path

get_path_type(path)

Validate the path and return its type

get_safe_filename(filename)

-

is_valid_filename(filename)

Check if the provided string is a valid filename for the local file system.

is_valid_path(path)

Check if the path is valid: could be a local path or a remote one

url_exists(url)

Check if a URL exists somewhere on the internet or locally. To be superseded by a more

web_url_exists(url)

Check if a URL exists on the web

Attributes

TIMEOUT

-

Functions

async file_tools.download_or_copy_file(url, local_path)

Download a file from a URL to a local file asynchronously

Parameters:
  • url (str) -- The URL to download the file from

  • local_path (str) -- The filename to save the file to

Returns:

The filename of the downloaded file

Return type:

str

file_tools.get_canonical_name(file_path: str)

Get the canonical name of a file, without the extension

file_tools.get_max_path_length(path='.')

get the max file name for the current OS

params:

path: the file path

return: file name max length.

file_tools.get_max_remote_path_length()

Get the maximum length of a remote path

file_tools.get_path_type(path: str | os.PathLike | None) dict

Validate the path and return its type

Parameters:

path (str, os.PathLike,) -- The path to validate

Returns:

The path type and the path itself Path type can be local, http, https, s3, gs, None, undefined, error, error : message if the path is invalid, None if no error

Return type:

dict

file_tools.get_safe_filename(filename)
file_tools.is_valid_filename(filename: str) bool

Check if the provided string is a valid filename for the local file system.

Parameters:

filename (str) -- The filename to check.

Returns:

True if valid, False otherwise.

Return type:

bool

file_tools.is_valid_path(path: str | os.PathLike | None) bool

Check if the path is valid: could be a local path or a remote one (http, etc). We don’t test the actual access and credentials at this stage, just the path format.

Parameters:

path (str, os.PathLike) -- The path to validate

Returns:

True if the path is valid, False otherwise

Return type:

bool

file_tools.url_exists(url: str)

Check if a URL exists somewhere on the internet or locally. To be superseded by a more versatile and unified library in the future.

Parameters:

url (str) -- The URL to check

Returns:

True if the URL exists, False otherwise

Return type:

bool

file_tools.web_url_exists(url)

Check if a URL exists on the web

Attributes

file_tools.TIMEOUT = 10