Utilities

Utilities.

Functions

download(url, path, *[, force, ...])

Download a file from a given URL.

download_from_google(file_id, path[, force, ...])

Download a file from google drive.

download_from_s3(s3_bucket, s3_key, path[, ...])

Download a file from S3.

get_base(key[, ensure_exists])

Get the base directory for a module.

get_commit(org, repo[, provider])

Get last commit hash for the given repo.

get_df_io(df[, sep, index])

Get the dataframe as bytes.

get_hash_hexdigest(path, name, *[, chunk_size])

Get a hash digest for a single hash.

get_hashes(path, names, *[, chunk_size])

Calculate several hexdigests of hash algorithms for a file concurrently.

get_hexdigests_remote(hexdigests_remote[, ...])

Process hexdigests via URLs.

get_home([ensure_exists])

Get the PyStow home directory.

get_mode_pair(mode, interpretation)

Get the mode pair.

get_name()

Get the PyStow home directory name.

get_np_io(arr, **kwargs)

Get the numpy object as bytes.

get_offending_hexdigests(path[, chunk_size, ...])

Check a file for hash sums.

get_soup(url, *[, verify, timeout, user_agent])

Get a beautiful soup parsed version of the given web page.

getenv_path(envvar, default[, ensure_exists])

Get an environment variable representing a path, or use the default.

gunzip(source[, target, cleanup])

Unzip a file in the source to the target.

gzip_compress(source, *[, target, cleanup])

Compress a file, then delete the original.

is_url(s)

Check if the object is a URL.

iter_pydantic_jsonl(file, model_cls, *[, ...])

Read models to a file as JSONL.

iter_pydantic_tsv(path, model_cls, *[, ...])

Read models from a TSV file, iteratively.

iter_tarred_csvs(...)

Iterate over the lines from tarred CSV files.

iter_tarred_files(...)

Iterate over opened files in a tar archive in read mode.

iter_zipped_csvs(...)

Iterate over the lines from zipped CSV files.

iter_zipped_files(...)

Iterate over opened files in a zip file in read mode.

mkdir(path[, ensure_exists])

Make a directory (or parent directory if a file is given) if flagged with ensure_exists.

mock_envvar(envvar, value)

Mock the environment variable then delete it after the test is over.

mock_home()

Mock the PyStow home environment variable, yields the directory name.

model_dump_yaml(model, *[, exclude_none, ...])

Dump the model as YAML string.

n()

Get a random string for testing.

name_from_s3_key(key)

Get the filename from the S3 key.

name_from_url(url)

Get the filename from the end of the URL.

open_inner_zipfile(...)

Open a file inside an already opened zip archive.

open_tarfile(path, inner_path, *[, ...])

Open a tar file.

open_url(-> Generator[TextIO, None, None])

Get a file-like object from a URL.

open_zip_dict_reader(path, inner_path[, ...])

Read an inner CSV file from a zip archive.

open_zip_reader(path, inner_path[, delimiter])

Read an inner CSV file from a zip archive.

open_zip_writer(path, inner_path[, delimiter])

Open a writer for an inner CSV file from a zip archive.

open_zipfile(-> Generator[typing.TextIO, ...)

Open a zipfile.

path_to_sqlite(path)

Convert a path to a SQLite connection string.

raise_on_digest_mismatch(*, path[, ...])

Raise a HexDigestError if the digests do not match.

read_lzma_csv(path[, sep])

Read a dataframe from a lzma-compressed file.

read_pydantic_json(path_or_url, model_cls, *)

Read a JSON file into a model.

read_pydantic_jsonl(file, model_cls, **kwargs)

Read models from a file as JSONL.

read_pydantic_tsv(path, model, *[, process, ...])

Read models from a TSV file.

read_pydantic_yaml(path_or_url, model_cls, *)

Read a YAML file into a model.

read_rdf(path, **kwargs)

Read an RDF file with rdflib.

read_tarfile_csv(path, inner_path[, sep])

Read an inner CSV file from a tar archive.

read_tarfile_xml(path, inner_path, **kwargs)

Read an inner XML file from a tar archive.

read_zip_np(path, inner_path, **kwargs)

Read an inner numpy array-like from a zip archive.

read_zipfile_csv(path, inner_path[, sep])

Read an inner CSV file from a zip archive.

read_zipfile_rdf(path, inner_path, **kwargs)

Read an inner RDF file from a zip archive.

read_zipfile_xml(path, inner_path, **kwargs)

Read an inner XML file from a zip archive.

reyield(func, elements, *args, **kwargs)

Make a function that consumes an iterable yield its elements.

safe_open(-> Generator[typing.BinaryIO, ...)

Safely open a file for reading or writing text.

safe_open_dict_reader(f, *[, delimiter])

Open a CSV dictionary reader, wrapping csv.DictReader().

safe_open_dict_writer(f, fieldnames, *[, ...])

Open a CSV dictionary writer, wrapping csv.DictWriter().

safe_open_json(path_or_url, *[, encoding, ...])

Safely open a file and parse as JSON.

safe_open_reader(f, *[, delimiter])

Open a CSV reader, wrapping csv.reader().

safe_open_writer(f, *[, delimiter])

Open a CSV writer, wrapping csv.writer().

safe_open_yaml(path_or_url, *[, encoding, ...])

Safely open a file and parse as YAML.

safe_read_text(path, *[, encoding, newline])

Read text from a file.

safe_tarfile_open(tar_file)

Open a tar archive safely.

safe_write_text(s, path, *[, encoding, newline])

Write text to a file.

safe_zipfile_open(zip_file)

Open a zip archive safely.

stream_write_pydantic_jsonl(models, file, ...)

Write models to a file as JSONL and yield them.

tarfile_writestr(tar_file, filename, data)

Write to a tarfile.

use_appdirs()

Check if X Desktop Group (XDG) compatibility is requested.

write_json(data, path, *[, encoding, newline])

Write JSON to a file.

write_lzma_csv(df, path[, sep, index])

Write a dataframe as an lzma-compressed file.

write_pickle_gz(obj, path, **kwargs)

Write an object to a gzipped pickle.

write_pydantic_json(model, path, *[, ...])

Write a model to a JSON file.

write_pydantic_jsonl(models, file, **kwargs)

Write models to a file as JSONL.

write_pydantic_yaml(model, path, *[, ...])

Write a model to a YAML file.

write_tarfile_csv(df, path, inner_path[, ...])

Write a dataframe to an inner CSV file from a tar archive.

write_tarfile_xml(element_tree, path, ...)

Write an XML document a tar archive.

write_yaml(data, path, *[, encoding, newline])

Write YAML to a file.

write_zipfile_csv(df, path, inner_path[, ...])

Write a dataframe to an inner CSV file to a zip archive.

write_zipfile_np(arr, path, inner_path, **kwargs)

Write a dataframe to an inner CSV file to a zip archive.

write_zipfile_rdf(graph, path, inner_path, ...)

Read an inner RDF file from a zip archive.

write_zipfile_xml(element_tree, path, ...)

Write an XML element tree to an inner XML file to a zip archive.

Classes

DownloadError(backend, url, path, exc)

An error that wraps information from a requests or urllib download failure.

HeaderMismatchError(original, current)

Raised when the current header in an archive of CSVs is different than the original.

HexDigestError(offending_hexdigests)

Thrown if the hashsums do not match expected hashsums.

HexDigestMismatch(name, actual, expected)

Contains information about a hexdigest mismatch.

InvalidOperationError(operation)

Raised when passing an invalid operation.

InvalidRepresentationError(representation)

Raised when passing an invalid representation.

UnexpectedDirectory

Backwards compatible name

UnexpectedDirectoryError(path)

Thrown if a directory path is given where file path should have been.