hfutils.operate.download

download_file_to_file

hfutils.operate.download.download_file_to_file(local_file: str, repo_id: str, file_in_repo: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', resume_download: bool = True, hf_token: str | None = None)[source]

Download a file from a Hugging Face repository and save it to a local file.

Parameters:
  • local_file (str) – The local file path to save the downloaded file.

  • repo_id (str) – The identifier of the repository.

  • file_in_repo (str) – The file path within the repository.

  • repo_type (RepoTypeTyping) – The type of the repository (‘dataset’, ‘model’, ‘space’).

  • revision (str) – The revision of the repository (e.g., branch, tag, commit hash).

  • resume_download (bool) – Resume the existing download.

  • hf_token (str, optional) – Huggingface token for API client, use HF_TOKEN variable if not assigned.

download_archive_as_directory

hfutils.operate.download.download_archive_as_directory(local_directory: str, repo_id: str, file_in_repo: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', password: str | None = None, hf_token: str | None = None)[source]

Download an archive file from a Hugging Face repository and extract it to a local directory.

Parameters:
  • local_directory (str) – The local directory path to extract the downloaded archive.

  • repo_id (str) – The identifier of the repository.

  • file_in_repo (str) – The file path within the repository.

  • repo_type (RepoTypeTyping) – The type of the repository (‘dataset’, ‘model’, ‘space’).

  • revision (str) – The revision of the repository (e.g., branch, tag, commit hash).

  • password (str, optional) – The password of the archive file.

  • hf_token (str, optional) – Huggingface token for API client, use HF_TOKEN variable if not assigned.

download_directory_as_directory

hfutils.operate.download.download_directory_as_directory(local_directory: str, repo_id: str, dir_in_repo: str = '.', pattern: str = '**/*', repo_type: ~typing.Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', silent: bool = False, ignore_patterns: ~typing.List[str] = <object object>, resume_download: bool = True, max_workers: int = 8, max_retries: int = 5, hf_token: str | None = None)[source]

Download all files in a directory from a Hugging Face repository to a local directory.

Parameters:
  • local_directory (str) – The local directory path to save the downloaded files.

  • repo_id (str) – The identifier of the repository.

  • dir_in_repo (str) – The directory path within the repository.

  • pattern (str) – Patterns for filtering.

  • repo_type (RepoTypeTyping) – The type of the repository (‘dataset’, ‘model’, ‘space’).

  • revision (str) – The revision of the repository (e.g., branch, tag, commit hash).

  • silent (bool) – If True, suppress progress bar output.

  • ignore_patterns (List[str]) – List of file patterns to ignore.

  • max_workers (int) – Max workers when downloading. Default is 8.

  • max_retries (int) – Max retry times when downloading. Default is 5.

  • resume_download (bool) – Resume the existing download.

  • hf_token (str, optional) – Huggingface token for API client, use HF_TOKEN variable if not assigned.