Managing local and online repositories
The Repository
class is a helper class that wraps git
and git-lfs
commands. It provides tooling adapted
for managing repositories which can be very large.
It is the recommended tool as soon as any git
operation is involved, or when collaboration will be a point
of focus with the repository itself.
The Repository class
huggingface_hub.Repository
< source >( local_dir: typing.Union[str, pathlib.Path] clone_from: typing.Optional[str] = None repo_type: typing.Optional[str] = None token: typing.Union[bool, str] = True git_user: typing.Optional[str] = None git_email: typing.Optional[str] = None revision: typing.Optional[str] = None skip_lfs_files: bool = False client: typing.Optional[huggingface_hub.hf_api.HfApi] = None )
Helper class to wrap the git and git-lfs commands.
The aim is to facilitate interacting with huggingface.co hosted model or dataset repos, though not a lot here (if any) is actually specific to huggingface.co.
Repository() is deprecated in favor of the http-based alternatives implemented in
HfApi. Given its large adoption in legacy code, the complete removal of
Repository() will only happen in release v1.0
. For more details, please read
https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http.
Helper methods
huggingface_hub.repository.is_git_repo
< source >( folder: typing.Union[str, pathlib.Path] ) β bool
Check if the folder is the root or part of a git repository
huggingface_hub.repository.is_local_clone
< source >( folder: typing.Union[str, pathlib.Path] remote_url: str ) β bool
Check if the folder is a local clone of the remote_url
huggingface_hub.repository.is_tracked_with_lfs
< source >( filename: typing.Union[str, pathlib.Path] ) β bool
Check if the file passed is tracked with git-lfs.
huggingface_hub.repository.is_git_ignored
< source >( filename: typing.Union[str, pathlib.Path] ) β bool
Check if file is git-ignored. Supports nested .gitignore files.
huggingface_hub.repository.files_to_be_staged
< source >( pattern: str = '.' folder: typing.Union[str, pathlib.Path, NoneType] = None ) β List[str]
Returns a list of filenames that are to be staged.
huggingface_hub.repository.is_tracked_upstream
< source >( folder: typing.Union[str, pathlib.Path] ) β bool
Check if the current checked-out branch is tracked upstream.
huggingface_hub.repository.commits_to_push
< source >( folder: typing.Union[str, pathlib.Path] upstream: typing.Optional[str] = None ) β int
Check the number of commits that would be pushed upstream
The name of the upstream repository with which the comparison should be made.
Following asynchronous commands
The Repository
utility offers several methods which can be launched asynchronously:
git_push
git_pull
push_to_hub
- The
commit
context manager
See below for utilities to manage such asynchronous methods.
huggingface_hub.Repository
< source >( local_dir: typing.Union[str, pathlib.Path] clone_from: typing.Optional[str] = None repo_type: typing.Optional[str] = None token: typing.Union[bool, str] = True git_user: typing.Optional[str] = None git_email: typing.Optional[str] = None revision: typing.Optional[str] = None skip_lfs_files: bool = False client: typing.Optional[huggingface_hub.hf_api.HfApi] = None )
Helper class to wrap the git and git-lfs commands.
The aim is to facilitate interacting with huggingface.co hosted model or dataset repos, though not a lot here (if any) is actually specific to huggingface.co.
Repository() is deprecated in favor of the http-based alternatives implemented in
HfApi. Given its large adoption in legacy code, the complete removal of
Repository() will only happen in release v1.0
. For more details, please read
https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http.
class huggingface_hub.repository.CommandInProgress
< source >( title: str is_done_method: typing.Callable status_method: typing.Callable process: Popen post_method: typing.Optional[typing.Callable] = None )
Utility to follow commands launched asynchronously.