hfutils.operate.duplicate
This module provides functionality for duplicating repositories on the Hugging Face Hub.
It includes a function to duplicate a repository, allowing users to create a copy of an existing repository with a new name and optional privacy settings. This module interacts with the Hugging Face API to perform the duplication process.
Note
Inspired by huggingface-projects/repo_duplicator provided by huggingface official team.
hf_repo_duplicate
- hfutils.operate.duplicate.hf_repo_duplicate(src_repo_id: str, dst_repo_id: str, repo_type: Literal['dataset', 'model', 'space'], private: bool = False, endpoint: str | None = None, hf_token: str | None = None)[source]
Duplicate a repository on the Hugging Face Hub.
This function creates a copy of an existing repository with a new name. It allows you to specify whether the new repository should be private or public.
- Parameters:
src_repo_id (str) – The ID of the source repository to duplicate.
dst_repo_id (str) – The ID for the new (destination) repository.
repo_type (RepoTypeTyping) – The type of the repository (e.g., ‘model’, ‘dataset’, ‘space’).
private (bool, optional) – Whether the new repository should be private. Defaults to False.
endpoint (str, optional) – The API endpoint to use. If None, the default endpoint will be used.
hf_token (str, optional) – The Hugging Face authentication token. If None, the default token will be used.
- Returns:
The JSON response from the API containing information about the duplicated repository.
- Return type:
dict
- Raises:
Raises an exception if the API request fails.
- Usage:
>>> result = hf_repo_duplicate("original-repo", "new-repo", "model", private=True) >>> print(result) # Prints information about the newly created repository