mach.io.utils.download_file

Contents

mach.io.utils.download_file#

mach.io.utils.download_file(
url: str,
output_path: str | Path,
timeout: int = 30,
chunk_size: int = 1048576,
*,
overwrite: bool = False,
expected_hash: str | None = None,
digest: None | str | Callable[[], hashlib._Hash] = None,
expected_size: int | None = None,
show_progress: bool = True,
) Path#

Download a file from a URL with optional progress bar and integrity verification.

Parameters:
  • url – URL to download

  • output_path – Path where the file will be saved

  • timeout – Connection timeout in seconds

  • chunk_size – Size of chunks to download

  • overwrite – Whether to overwrite existing files

  • expected_hash – Expected hash value for integrity verification

  • digest – Hash algorithm to use (default: “sha1”)

  • expected_size – Expected file size in bytes

  • show_progress – Whether to show progress bar (requires tqdm)

Returns:

Path to the downloaded file

Raises:
  • RuntimeError – If download fails or integrity check fails

  • ImportError – If show_progress=True but tqdm is not installed