Hub Python Library documentation

Managing local and online repositories

You are viewing v0.19.3 version. A newer version v0.27.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

< >

( 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

< >

( folder: typing.Union[str, pathlib.Path] ) β†’ bool

Parameters

  • folder (str) — The folder in which to run the command.

Returns

bool

True if the repository is part of a repository, False otherwise.

Check if the folder is the root or part of a git repository

huggingface_hub.repository.is_local_clone

< >

( folder: typing.Union[str, pathlib.Path] remote_url: str ) β†’ bool

Parameters

  • folder (str or Path) — The folder in which to run the command.
  • remote_url (str) — The url of a git repository.

Returns

bool

True if the repository is a local clone of the remote repository specified, False otherwise.

Check if the folder is a local clone of the remote_url

huggingface_hub.repository.is_tracked_with_lfs

< >

( filename: typing.Union[str, pathlib.Path] ) β†’ bool

Parameters

  • filename (str or Path) — The filename to check.

Returns

bool

True if the file passed is tracked with git-lfs, False otherwise.

Check if the file passed is tracked with git-lfs.

huggingface_hub.repository.is_git_ignored

< >

( filename: typing.Union[str, pathlib.Path] ) β†’ bool

Parameters

  • filename (str or Path) — The filename to check.

Returns

bool

True if the file passed is ignored by git, False otherwise.

Check if file is git-ignored. Supports nested .gitignore files.

huggingface_hub.repository.files_to_be_staged

< >

( pattern: str = '.' folder: typing.Union[str, pathlib.Path, NoneType] = None ) β†’ List[str]

Parameters

  • pattern (str or Path) — The pattern of filenames to check. Put . to get all files.
  • folder (str or Path) — The folder in which to run the command.

Returns

List[str]

List of files that are to be staged.

Returns a list of filenames that are to be staged.

huggingface_hub.repository.is_tracked_upstream

< >

( folder: typing.Union[str, pathlib.Path] ) β†’ bool

Parameters

  • folder (str or Path) — The folder in which to run the command.

Returns

bool

True if the current checked-out branch is tracked upstream, False otherwise.

Check if the current checked-out branch is tracked upstream.

huggingface_hub.repository.commits_to_push

< >

( folder: typing.Union[str, pathlib.Path] upstream: typing.Optional[str] = None ) β†’ int

Parameters

  • folder (str or Path) — The folder in which to run the command.
  • upstream (str, optional) —

Returns

int

Number of commits that would be pushed upstream were a git push to proceed.

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

< >

( 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

< >

( 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.