hfutils.utils.download
download_file
- hfutils.utils.download.download_file(url: str, filename: str, expected_size: int | None = None, desc: str | None = None, session: Session | None = None, silent: bool = False, **kwargs) str [source]
Download a file from the given URL and save it to the specified filename.
This function uses the requests library to download a file from the given URL and provides a progress bar using tqdm. It also performs checks to ensure that the downloaded file has the expected size.
- Parameters:
url (str) – The URL of the file to download.
filename (str) – The local path where the file should be saved.
expected_size (int, optional) – The expected size of the file in bytes (optional).
desc (str, optional) – Description for the tqdm progress bar (optional).
session (requests.Session, optional) – An optional requests.Session object to use for the download.
silent (bool) – If True, suppress tqdm output, otherwise display it.
kwargs – Additional keyword arguments to pass to requests.get().
- Returns:
The path to the downloaded file.
- Return type:
str