# BOINC AI Hub API

## BaApi Client

Below is the documentation for the `BaApi` class, which serves as a Python wrapper for the BOINC AI Hub’s API.

All methods from the `BaApi` are also accessible from the package’s root directly. Both approaches are detailed below.

Using the root method is more straightforward but the [BaApi](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi) class gives you more flexibility. In particular, you can pass a token that will be reused in all HTTP calls. This is different than `boinc ai-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login) as the token is not persisted on the machine. It is also possible to provide a different endpoint or configure a custom user-agent.

Copied

```
from boincai_hub import HfApi, list_models

# Use root method
models = list_models()

# Or configure a HfApi client
hf_api = HfApi(
    endpoint="https://boincai.com", # Can be a Private Hub endpoint.
    token="hf_xxx", # Token is not persisted on the machine.
)
models = hf_api.list_models()
```

### HfApi

#### class boincai\_hub.HfApi

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L975)

( endpoint: Optional\[str] = Nonetoken: Optional\[str] = Nonelibrary\_name: Optional\[str] = Nonelibrary\_version: Optional\[str] = Noneuser\_agent: Union\[Dict, str, None] = None )

**add\_collection\_item**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6234)

( collection\_slug: stritem\_id: stritem\_type: CollectionItemType\_Tnote: Optional\[str] = Noneexists\_ok: bool = Falsetoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection to update. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **item\_id** (`str`) — ID of the item to add to the collection. It can be the ID of a repo on the Hub (e.g. `"facebook/bart-large-mnli"`) or a paper id (e.g. `"2307.09288"`).
* **item\_type** (`str`) — Type of the item to add. Can be one of `"model"`, `"dataset"`, `"space"` or `"paper"`.
* **note** (`str`, _optional_) — A note to attach to the item in the collection. The maximum size for a note is 500 characters.
* **exists\_ok** (`bool`, _optional_) — If `True`, do not raise an error if item already exists.
* **token** (`str`, _optional_) — BOINC AI token. Will default to the locally saved token if not provided.

Add an item to a collection on the Hub.

Returns: [Collection](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.Collection)



Example:

Copied

```
>>> from boincai_hub import add_collection_item
>>> collection = add_collection_item(
...     collection_slug="davanstrien/climate-64f99dc2a5067f6b65531bab",
...     item_id="pierre-loic/climate-news-articles",
...     item_type="dataset"
... )
>>> collection.items[-1].item_id
"pierre-loic/climate-news-articles"
# ^item got added to the collection on last position

# Add item with a note
>>> add_collection_item(
...     collection_slug="davanstrien/climate-64f99dc2a5067f6b65531bab",
...     item_id="datasets/climate_fever",
...     item_type="dataset"
...     note="This dataset adopts the FEVER methodology that consists of 1,535 real-world claims regarding climate-change collected on the internet."
... )
(...)
```

**add\_space\_secret**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5522)

( repo\_id: strkey: strvalue: strdescription: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **key** (`str`) — Secret key. Example: `"GITHUB_API_KEY"`
* **value** (`str`) — Secret value. Example: `"your_github_api_key"`.
* **description** (`str`, _optional_) — Secret description. Example: `"Github API key to access the Github API"`.
* **token** (`str`, _optional_) — BOINC AI token. Will default to the locally saved token if not provided.

Adds or updates a secret in a Space.

Secrets allow to set secret keys or tokens to a Space without hardcoding them. For more details, see [https://boincai.com/docs/hub/spaces-overview#managing-secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets).

**add\_space\_variable**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5595)

( repo\_id: strkey: strvalue: strdescription: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **key** (`str`) — Variable key. Example: `"MODEL_REPO_ID"`
* **value** (`str`) — Variable value. Example: `"the_model_repo_id"`.
* **description** (`str`) — Description of the variable. Example: `"Model Repo ID of the implemented model"`.
* **token** (`str`, _optional_) — BOINC AI token. Will default to the locally saved token if not provided.

Adds or updates a variable in a Space.

Variables allow to set environment variables to a Space without hardcoding them. For more details, see [https://boincai.com/docs/hub/spaces-overview#managing-secrets-and-environment-variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables)

**change\_discussion\_status**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5276)

( repo\_id: strdiscussion\_num: intnew\_status: Literal\[('open', 'closed')]token: Optional\[str] = Nonecomment: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionStatusChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionStatusChange)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **new\_status** (`str`) — The new status for the discussion, either `"open"` or `"closed"`.
* **comment** (`str`, _optional_) — An optional comment to post with the status change.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionStatusChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionStatusChange)

the status change event

Closes or re-opens a Discussion or Pull Request.



Examples:

Copied

```
>>> new_title = "New title, fixing a typo"
>>> HfApi().rename_discussion(
...     repo_id="username/repo_name",
...     discussion_num=34
...     new_title=new_title
... )
# DiscussionStatusChange(id='deadbeef0000000', type='status-change', ...)
```

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**comment\_discussion**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5133)

( repo\_id: strdiscussion\_num: intcomment: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **comment** (`str`) — The content of the comment to create. Comments support markdown formatting.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

the newly created comment

Creates a new comment on the given Discussion.



Examples:

Copied

```
>>> comment = """
... Hello @otheruser!
...
... # This is a title
...
... **This is bold**, *this is italic* and ~this is strikethrough~
... And [this](http://url) is a link
... """

>>> HfApi().comment_discussion(
...     repo_id="username/repo_name",
...     discussion_num=34
...     comment=comment
... )
# DiscussionComment(id='deadbeef0000000', type='comment', ...)
```

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**create\_branch**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4536)

( repo\_id: strbranch: strrevision: Optional\[str] = Nonetoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Noneexist\_ok: bool = False )

Parameters

* **repo\_id** (`str`) — The repository in which the branch will be created. Example: `"user/my-cool-model"`.
* **branch** (`str`) — The name of the branch to create.
* **revision** (`str`, _optional_) — The git revision to create the branch from. It can be a branch name or the OID/SHA of a commit, as a hexadecimal string. Defaults to the head of the `"main"` branch.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if creating a branch on a dataset or space, `None` or `"model"` if tagging a model. Default is `None`.
* **exist\_ok** (`bool`, _optional_, defaults to `False`) — If `True`, do not raise an error if branch already exists.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError) or [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError) — If invalid reference for a branch. Ex: `refs/pr/5` or ‘refs/foo/bar’.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — If the branch already exists on the repo (error 409) and `exist_ok` is set to `False`.

Create a new branch for a repo on the Hub, starting from the specified revision (defaults to `main`). To find a revision suiting your needs, you can use [list\_repo\_refs()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_repo_refs) or [list\_repo\_commits()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_repo_commits).

**create\_collection**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6066)

( title: strnamespace: Optional\[str] = Nonedescription: Optional\[str] = Noneprivate: bool = Falseexists\_ok: bool = Falsetoken: Optional\[str] = None )

Parameters

* **title** (`str`) — Title of the collection to create. Example: `"Recent models"`.
* **namespace** (`str`, _optional_) — Namespace of the collection to create (username or org). Will default to the owner name.
* **description** (`str`, _optional_) — Description of the collection to create.
* **private** (`bool`, _optional_) — Whether the collection should be private or not. Defaults to `False` (i.e. public collection).
* **exists\_ok** (`bool`, _optional_) — If `True`, do not raise an error if collection already exists.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Create a new Collection on the Hub.

Returns: [Collection](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.Collection)



Example:

Copied

```
>>> from huggingface_hub import create_collection
>>> collection = create_collection(
...     title="ICCV 2023",
...     description="Portfolio of models, papers and demos I presented at ICCV 2023",
... )
>>> collection.slug
"username/iccv-2023-64f9a55bb3115b4f513ec026"
```

**create\_commit**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2952)

( repo\_id: stroperations: Iterable\[CommitOperation]commit\_message: strcommit\_description: Optional\[str] = Nonetoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Nonenum\_threads: int = 5parent\_commit: Optional\[str] = Nonerun\_as\_future: bool = False ) → [CommitInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitInfo) or `Future`

Parameters

* **repo\_id** (`str`) — The repository in which the commit will be created, for example: `"username/custom_transformers"`
*   **operations** (`Iterable` of `CommitOperation()`) — An iterable of operations to include in the commit, either:

    * [CommitOperationAdd](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd) to upload a file
    * [CommitOperationDelete](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationDelete) to delete a file
    * [CommitOperationCopy](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationCopy) to copy a file

    Operation objects will be mutated to include information relative to the upload. Do not reuse the same objects for multiple commits.
* **commit\_message** (`str`) — The summary (first line) of the commit that will be created.
* **commit\_description** (`str`, _optional_) — The description of the commit that will be created
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **create\_pr** (`boolean`, _optional_) — Whether or not to create a Pull Request with that commit. Defaults to `False`. If `revision` is not set, PR is opened against the `"main"` branch. If `revision` is set and is a branch, PR is opened against this branch. If `revision` is set and is not a branch name (example: a commit oid), an `RevisionNotFoundError` is returned by the server.
* **num\_threads** (`int`, _optional_) — Number of concurrent threads for uploading files. Defaults to 5. Setting it to 2 means at most 2 files will be uploaded concurrently.
* **parent\_commit** (`str`, _optional_) — The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`. If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`. Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.
* **run\_as\_future** (`bool`, _optional_) — Whether or not to run this method in the background. Background jobs are run sequentially without blocking the main thread. Passing `run_as_future=True` will return a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects) object. Defaults to `False`.

Returns

[CommitInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitInfo) or `Future`

Instance of [CommitInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitInfo) containing information about the newly created commit (commit hash, commit url, pr url, commit message,…). If `run_as_future=True` is passed, returns a Future object which will contain the result when executed.

Raises

`ValueError` or [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError)

* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If commit message is empty.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If parent commit is not a valid commit OID.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If the Hub API returns an HTTP 400 error (bad request)
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If `create_pr` is `True` and revision is neither `None` nor `"main"`.
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.

Creates a commit in the given repo, deleting & uploading files as needed.

The input list of `CommitOperation` will be mutated during the commit process. Do not reuse the same objects for multiple commits.

`create_commit` assumes that the repo already exists on the Hub. If you get a Client error 404, please make sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create it first using [create\_repo()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo).

`create_commit` is limited to 25k LFS files and a 1GB payload for regular files.

**create\_commits\_on\_pr**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L3173)

( repo\_id: straddition\_commits: List\[List\[CommitOperationAdd]]deletion\_commits: List\[List\[CommitOperationDelete]]commit\_message: strcommit\_description: Optional\[str] = Nonetoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonemerge\_pr: bool = Truenum\_threads: int = 5verbose: bool = False ) → `str`

Parameters

* **repo\_id** (`str`) — The repository in which the commits will be pushed. Example: `"username/my-cool-model"`.
*   **addition\_commits** (`List` of `List` of [CommitOperationAdd](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd)) — A list containing lists of [CommitOperationAdd](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd). Each sublist will result in a commit on the PR.

    deletion\_commits — A list containing lists of [CommitOperationDelete](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationDelete). Each sublist will result in a commit on the PR. Deletion commits are pushed before addition commits.
* **commit\_message** (`str`) — The summary (first line) of the commit that will be created. Will also be the title of the PR.
* **commit\_description** (`str`, _optional_) — The description of the commit that will be created. The description will be added to the PR.
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **merge\_pr** (`bool`) — If set to `True`, the Pull Request is merged at the end of the process. Defaults to `True`.
* **num\_threads** (`int`, _optional_) — Number of concurrent threads for uploading files. Defaults to 5.
* **verbose** (`bool`) — If set to `True`, process will run on verbose mode i.e. print information about the ongoing tasks. Defaults to `False`.

Returns

`str`

URL to the created PR.

Raises

`MultiCommitException`

* `MultiCommitException` — If an unexpected issue occur in the process: empty commits, unexpected commits in a PR, unexpected PR description, etc.

Push changes to the Hub in multiple commits.

Commits are pushed to a draft PR branch. If the upload fails or gets interrupted, it can be resumed. Progress is tracked in the PR description. At the end of the process, the PR is set as open and the title is updated to match the initial commit message. If `merge_pr=True` is passed, the PR is merged automatically.

All deletion commits are pushed first, followed by the addition commits. The order of the commits is not guaranteed as we might implement parallel commits in the future. Be sure that your are not updating several times the same file.

`create_commits_on_pr` is experimental. Its API and behavior is subject to change in the future without prior notice.

`create_commits_on_pr` assumes that the repo already exists on the Hub. If you get a Client error 404, please make sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create it first using [create\_repo()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo).



Example:

Copied

```
>>> from huggingface_hub import HfApi, plan_multi_commits
>>> addition_commits, deletion_commits = plan_multi_commits(
...     operations=[
...          CommitOperationAdd(...),
...          CommitOperationAdd(...),
...          CommitOperationDelete(...),
...          CommitOperationDelete(...),
...          CommitOperationAdd(...),
...     ],
... )
>>> HfApi().create_commits_on_pr(
...     repo_id="my-cool-model",
...     addition_commits=addition_commits,
...     deletion_commits=deletion_commits,
...     (...)
...     verbose=True,
... )
```

**create\_discussion**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4960)

( repo\_id: strtitle: strtoken: Optional\[str] = Nonedescription: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonepull\_request: bool = False )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **title** (`str`) — The title of the discussion. It can be up to 200 characters long, and must be at least 3 characters long. Leading and trailing whitespaces will be stripped.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))
* **description** (`str`, _optional_) — An optional description for the Pull Request. Defaults to `"Discussion opened with the huggingface_hub Python library"`
* **pull\_request** (`bool`, _optional_) — Whether to create a Pull Request or discussion. If `True`, creates a Pull Request. If `False`, creates a discussion. Defaults to `False`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.

Creates a Discussion or Pull Request.

Pull Requests created programmatically will be in `"draft"` status.

Creating a Pull Request with changes can also be done at once with [HfApi.create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit).

Returns: [DiscussionWithDetails](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionWithDetails)

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**create\_pull\_request**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5049)

( repo\_id: strtitle: strtoken: Optional\[str] = Nonedescription: Optional\[str] = Nonerepo\_type: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **title** (`str`) — The title of the discussion. It can be up to 200 characters long, and must be at least 3 characters long. Leading and trailing whitespaces will be stripped.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))
* **description** (`str`, _optional_) — An optional description for the Pull Request. Defaults to `"Discussion opened with the huggingface_hub Python library"`
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.

Creates a Pull Request . Pull Requests created programmatically will be in `"draft"` status.

Creating a Pull Request with changes can also be done at once with [HfApi.create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit);

This is a wrapper around [HfApi.create\_discussion()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_discussion).

Returns: [DiscussionWithDetails](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionWithDetails)

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**create\_repo**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2612)

( repo\_id: strtoken: Optional\[str] = Noneprivate: bool = Falserepo\_type: Optional\[str] = Noneexist\_ok: bool = Falsespace\_sdk: Optional\[str] = Nonespace\_hardware: Optional\[SpaceHardware] = Nonespace\_storage: Optional\[SpaceStorage] = Nonespace\_sleep\_time: Optional\[int] = Nonespace\_secrets: Optional\[List\[Dict\[str, str]]] = Nonespace\_variables: Optional\[List\[Dict\[str, str]]] = None ) → [RepoUrl](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.RepoUrl)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))
* **private** (`bool`, _optional_, defaults to `False`) — Whether the model repo should be private.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **exist\_ok** (`bool`, _optional_, defaults to `False`) — If `True`, do not raise an error if repo already exists.
* **space\_sdk** (`str`, _optional_) — Choice of SDK to use if repo\_type is “space”. Can be “streamlit”, “gradio”, “docker”, or “static”.
* **space\_hardware** (`SpaceHardware` or `str`, _optional_) — Choice of Hardware if repo\_type is “space”. See [SpaceHardware](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceHardware) for a complete list.
* **space\_storage** (`SpaceStorage` or `str`, _optional_) — Choice of persistent storage tier. Example: `"small"`. See [SpaceStorage](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceStorage) for a complete list.
* **space\_sleep\_time** (`int`, _optional_) — Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don’t want your Space to sleep (default behavior for upgraded hardware). For free hardware, you can’t configure the sleep time (value is fixed to 48 hours of inactivity). See [https://huggingface.co/docs/hub/spaces-gpus#sleep-time](https://huggingface.co/docs/hub/spaces-gpus#sleep-time) for more details.
* **space\_secrets** (`List[Dict[str, str]]`, _optional_) — A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets).
* **space\_variables** (`List[Dict[str, str]]`, _optional_) — A list of public environment variables to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables).

Returns

[RepoUrl](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.RepoUrl)

URL to the newly created repo. Value is a subclass of `str` containing attributes like `endpoint`, `repo_type` and `repo_id`.

Create an empty repo on the HuggingFace Hub.

**create\_tag**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4652)

( repo\_id: strtag: strtag\_message: Optional\[str] = Nonerevision: Optional\[str] = Nonetoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Noneexist\_ok: bool = False )

Parameters

* **repo\_id** (`str`) — The repository in which a commit will be tagged. Example: `"user/my-cool-model"`.
* **tag** (`str`) — The name of the tag to create.
* **tag\_message** (`str`, _optional_) — The description of the tag to create.
* **revision** (`str`, _optional_) — The git revision to tag. It can be a branch name or the OID/SHA of a commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. Defaults to the head of the `"main"` branch.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if tagging a dataset or space, `None` or `"model"` if tagging a model. Default is `None`.
* **exist\_ok** (`bool`, _optional_, defaults to `False`) — If `True`, do not raise an error if tag already exists.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) or [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) — If revision is not found (error 404) on the repo.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — If the branch already exists on the repo (error 409) and `exist_ok` is set to `False`.

Tag a given commit of a repo on the Hub.

**dataset\_info**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1871)

( repo\_id: strrevision: Optional\[str] = Nonetimeout: Optional\[float] = Nonefiles\_metadata: bool = Falsetoken: Optional\[Union\[bool, str]] = None ) → [hf\_api.DatasetInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.DatasetInfo)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **revision** (`str`, _optional_) — The revision of the dataset repository from which to get the information.
* **timeout** (`float`, _optional_) — Whether to set a timeout for the request to the Hub.
* **files\_metadata** (`bool`, _optional_) — Whether or not to retrieve metadata for files in the repository (size, LFS metadata, etc). Defaults to `False`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

[hf\_api.DatasetInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.DatasetInfo)

The dataset repository information.

Get info on one specific dataset on huggingface.co.

Dataset can be private if you pass an acceptable token.

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.

**delete\_branch**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4603)

( repo\_id: strbranch: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — The repository in which a branch will be deleted. Example: `"user/my-cool-model"`.
* **branch** (`str`) — The name of the branch to delete.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if creating a branch on a dataset or space, `None` or `"model"` if tagging a model. Default is `None`.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — If trying to delete a protected branch. Ex: `main` cannot be deleted.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — If trying to delete a branch that does not exist.

Delete a branch from a repo on the Hub.

**delete\_collection**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6196)

( collection\_slug: strmissing\_ok: bool = Falsetoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection to delete. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **missing\_ok** (`bool`, _optional_) — If `True`, do not raise an error if collection doesn’t exists.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Delete a collection on the Hub.



Example:

Copied

```
>>> from huggingface_hub import delete_collection
>>> collection = delete_collection("username/useless-collection-64f9a55bb3115b4f513ec026", missing_ok=True)
```

This is a non-revertible action. A deleted collection cannot be restored.

**delete\_collection\_item**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6354)

( collection\_slug: stritem\_object\_id: strmissing\_ok: bool = Falsetoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection to update. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **item\_object\_id** (`str`) — ID of the item in the collection. This is not the id of the item on the Hub (repo\_id or paper id). It must be retrieved from a [CollectionItem](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.CollectionItem) object. Example: `collection.items[0]._id`.
* **missing\_ok** (`bool`, _optional_) — If `True`, do not raise an error if item doesn’t exists.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Delete an item from a collection.



Example:

Copied

```
>>> from huggingface_hub import get_collection, delete_collection_item

# Get collection first
>>> collection = get_collection("TheBloke/recent-models-64f9a55bb3115b4f513ec026")

# Delete item based on its ID
>>> delete_collection_item(
...     collection_slug="TheBloke/recent-models-64f9a55bb3115b4f513ec026",
...     item_object_id=collection.items[-1].item_object_id,
... )
```

**delete\_file**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4070)

( path\_in\_repo: strrepo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecommit\_message: Optional\[str] = Nonecommit\_description: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Noneparent\_commit: Optional\[str] = None )

Parameters

* **path\_in\_repo** (`str`) — Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"`
* **repo\_id** (`str`) — The repository from which the file will be deleted, for example: `"username/custom_transformers"`
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if the file is in a dataset or space, `None` or `"model"` if in a model. Default is `None`.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **commit\_message** (`str`, _optional_) — The summary / title / first line of the generated commit. Defaults to `f"Delete {path_in_repo} with huggingface_hub"`.
* **commit\_description** (`str` _optional_) — The description of the generated commit
* **create\_pr** (`boolean`, _optional_) — Whether or not to create a Pull Request with that commit. Defaults to `False`. If `revision` is not set, PR is opened against the `"main"` branch. If `revision` is set and is a branch, PR is opened against this branch. If `revision` is set and is not a branch name (example: a commit oid), an `RevisionNotFoundError` is returned by the server.
* **parent\_commit** (`str`, _optional_) — The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`. If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`. Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.

Deletes a file in the given repo.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.
* [EntryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.EntryNotFoundError) If the file to download cannot be found.

**delete\_folder**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4158)

( path\_in\_repo: strrepo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecommit\_message: Optional\[str] = Nonecommit\_description: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Noneparent\_commit: Optional\[str] = None )

Parameters

* **path\_in\_repo** (`str`) — Relative folder path in the repo, for example: `"checkpoints/1fec34a"`.
* **repo\_id** (`str`) — The repository from which the folder will be deleted, for example: `"username/custom_transformers"`
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if the folder is in a dataset or space, `None` or `"model"` if in a model. Default is `None`.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **commit\_message** (`str`, _optional_) — The summary / title / first line of the generated commit. Defaults to `f"Delete folder {path_in_repo} with huggingface_hub"`.
* **commit\_description** (`str` _optional_) — The description of the generated commit.
* **create\_pr** (`boolean`, _optional_) — Whether or not to create a Pull Request with that commit. Defaults to `False`. If `revision` is not set, PR is opened against the `"main"` branch. If `revision` is set and is a branch, PR is opened against this branch. If `revision` is set and is not a branch name (example: a commit oid), an `RevisionNotFoundError` is returned by the server.
* **parent\_commit** (`str`, _optional_) — The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`. If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`. Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.

Deletes a folder in the given repo.

Simple wrapper around [create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit) method.

**delete\_repo**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2747)

( repo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonemissing\_ok: bool = False )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model.
* **missing\_ok** (`bool`, _optional_, defaults to `False`) — If `True`, do not raise an error if repo does not exist.

Raises

*
*
  * — [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to delete from cannot be found and `missing_ok` is set to False (default).

Delete a repo from the HuggingFace Hub. CAUTION: this is irreversible.

**delete\_space\_secret**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5553)

( repo\_id: strkey: strtoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **key** (`str`) — Secret key. Example: `"GITHUB_API_KEY"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Deletes a secret from a Space.

Secrets allow to set secret keys or tokens to a Space without hardcoding them. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets).

**delete\_space\_storage**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5997)

( repo\_id: strtoken: Optional\[str] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about a Space including Space stage and hardware.

Raises

`BadRequestError`

* `BadRequestError` — If space has no persistent storage.

Delete persistent storage for a Space.

**delete\_space\_variable**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5627)

( repo\_id: strkey: strtoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **key** (`str`) — Variable key. Example: `"MODEL_REPO_ID"`
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Deletes a variable from a Space.

Variables allow to set environment variables to a Space without hardcoding them. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables)

**delete\_tag**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4723)

( repo\_id: strtag: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — The repository in which a tag will be deleted. Example: `"user/my-cool-model"`.
* **tag** (`str`) — The name of the tag to delete.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if tagging a dataset or space, `None` or `"model"` if tagging a model. Default is `None`.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) — If tag is not found.

Delete a tag from a repo on the Hub.

**duplicate\_space**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5846)

( from\_id: strto\_id: Optional\[str] = Noneprivate: Optional\[bool] = Nonetoken: Optional\[str] = Noneexist\_ok: bool = Falsehardware: Optional\[SpaceHardware] = Nonestorage: Optional\[SpaceStorage] = Nonesleep\_time: Optional\[int] = Nonesecrets: Optional\[List\[Dict\[str, str]]] = Nonevariables: Optional\[List\[Dict\[str, str]]] = None ) → [RepoUrl](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.RepoUrl)

Parameters

* **from\_id** (`str`) — ID of the Space to duplicate. Example: `"pharma/CLIP-Interrogator"`.
* **to\_id** (`str`, _optional_) — ID of the new Space. Example: `"dog/CLIP-Interrogator"`. If not provided, the new Space will have the same name as the original Space, but in your account.
* **private** (`bool`, _optional_) — Whether the new Space should be private or not. Defaults to the same privacy as the original Space.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.
* **exist\_ok** (`bool`, _optional_, defaults to `False`) — If `True`, do not raise an error if repo already exists.
* **hardware** (`SpaceHardware` or `str`, _optional_) — Choice of Hardware. Example: `"t4-medium"`. See [SpaceHardware](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceHardware) for a complete list.
* **storage** (`SpaceStorage` or `str`, _optional_) — Choice of persistent storage tier. Example: `"small"`. See [SpaceStorage](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceStorage) for a complete list.
* **sleep\_time** (`int`, _optional_) — Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don’t want your Space to sleep (default behavior for upgraded hardware). For free hardware, you can’t configure the sleep time (value is fixed to 48 hours of inactivity). See [https://huggingface.co/docs/hub/spaces-gpus#sleep-time](https://huggingface.co/docs/hub/spaces-gpus#sleep-time) for more details.
* **secrets** (`List[Dict[str, str]]`, _optional_) — A list of secret keys to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets](https://huggingface.co/docs/hub/spaces-overview#managing-secrets).
* **variables** (`List[Dict[str, str]]`, _optional_) — A list of public environment variables to set in your Space. Each item is in the form `{"key": ..., "value": ..., "description": ...}` where description is optional. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables).

Returns

[RepoUrl](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.RepoUrl)

URL to the newly created repo. Value is a subclass of `str` containing attributes like `endpoint`, `repo_type` and `repo_id`.

Raises

*
*
  * — [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
*
  * — [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If one of `from_id` or `to_id` cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

Duplicate a Space.

Programmatically duplicate a Space. The new Space will be created in your account and will be in the same state as the original Space (running or paused). You can duplicate a Space no matter the current state of a Space.



Example:

Copied

```
>>> from huggingface_hub import duplicate_space

# Duplicate a Space to your account
>>> duplicate_space("multimodalart/dreambooth-training")
RepoUrl('https://huggingface.co/spaces/nateraw/dreambooth-training',...)

# Can set custom destination id and visibility flag.
>>> duplicate_space("multimodalart/dreambooth-training", to_id="my-dreambooth", private=True)
RepoUrl('https://huggingface.co/spaces/nateraw/my-dreambooth',...)
```

**edit\_discussion\_comment**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5404)

( repo\_id: strdiscussion\_num: intcomment\_id: strnew\_content: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **comment\_id** (`str`) — The ID of the comment to edit.
* **new\_content** (`str`) — The new content of the comment. Comments support markdown formatting.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

the edited comment

Edits a comment on a Discussion / Pull Request.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**file\_exists**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2111)

( repo\_id: strfilename: strrepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **filename** (`str`) — The name of the file to check, for example: `"config.json"`
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space, `None` or `"model"` if getting repository info from a model. Default is `None`.
* **revision** (`str`, _optional_) — The revision of the repository from which to get the information. Defaults to `"main"` branch.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Checks if a file exists in a repository on the Hugging Face Hub.



Examples:

Copied

```
>>> from huggingface_hub import file_exists
>>> file_exists("bigcode/starcoder", "config.json")
True
>>> file_exists("bigcode/starcoder", "not-a-file")
False
>>> file_exists("bigcode/not-a-repo", "config.json")
False
```

**get\_collection**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6029)

( collection\_slug: strtoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection of the Hub. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Gets information about a Collection on the Hub.

Returns: [Collection](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.Collection)



Example:

Copied

```
>>> from huggingface_hub import get_collection
>>> collection = get_collection("TheBloke/recent-models-64f9a55bb3115b4f513ec026")
>>> collection.title
'Recent models'
>>> len(collection.items)
37
>>> collection.items[0]
CollectionItem: {
    {'item_object_id': '6507f6d5423b46492ee1413e',
    'item_id': 'TheBloke/TigerBot-70B-Chat-GPTQ',
    'author': 'TheBloke',
    'item_type': 'model',
    'lastModified': '2023-09-19T12:55:21.000Z',
    (...)
}}
```

**get\_dataset\_tags**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1114)

( )

List all valid dataset tags as a nested namespace object.

**get\_discussion\_details**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4884)

( repo\_id: strdiscussion\_num: intrepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Fetches a Discussion’s / Pull Request ‘s details from the Hub.

Returns: [DiscussionWithDetails](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionWithDetails)

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**get\_full\_repo\_name**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4769)

( model\_id: strorganization: Optional\[str] = Nonetoken: Optional\[Union\[bool, str]] = None ) → `str`

Parameters

* **model\_id** (`str`) — The name of the model.
* **organization** (`str`, _optional_) — If passed, the repository name will be in the organization namespace instead of the user namespace.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`str`

The repository name in the user’s namespace ({username}/{model\_id}) if no organization is passed, and under the organization namespace ({organization}/{model\_id}) otherwise.

Returns the repository name for a given model ID and optional organization.

**get\_model\_tags**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1104)

( )

List all valid model tags as a nested namespace object

**get\_repo\_discussions**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4807)

( repo\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None ) → `Iterator[Discussion]`

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if fetching from a dataset or space, `None` or `"model"` if fetching from a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token)).

Returns

`Iterator[Discussion]`

An iterator of [Discussion](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.Discussion) objects.

Fetches Discussions and Pull Requests for the given repo.

Example:



Collecting all discussions of a repo in a list:

Copied

```
>>> from huggingface_hub import get_repo_discussions
>>> discussions_list = list(get_repo_discussions(repo_id="bert-base-uncased"))
```



Iterating over discussions of a repo:

Copied

```
>>> from huggingface_hub import get_repo_discussions
>>> for discussion in get_repo_discussions(repo_id="bert-base-uncased"):
...     print(discussion.num, discussion.title)
```

**get\_space\_runtime**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5652)

( repo\_id: strtoken: Optional\[str] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about a Space including Space stage and hardware.

Gets runtime information about a Space.

**get\_space\_variables**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5575)

( repo\_id: strtoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — ID of the repo to query. Example: `"bigcode/in-the-stack"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Gets all variables from a Space.

Variables allow to set environment variables to a Space without hardcoding them. For more details, see [https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables](https://huggingface.co/docs/hub/spaces-overview#managing-secrets-and-environment-variables)

**get\_token\_permission**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1085)

( token: Optional\[str] = None ) → `Literal["read", "write", None]`

Parameters

* **token** (`str`, _optional_) — The token to check for validity. Defaults to the one saved locally.

Returns

`Literal["read", "write", None]`

Permission granted by the token (“read” or “write”). Returns `None` if no token passed or token is invalid.

Check if a given `token` is valid and return its permissions.

For more details about tokens, please refer to [https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens](https://huggingface.co/docs/hub/security-tokens#what-are-user-access-tokens).

**hf\_hub\_download**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4223)

( repo\_id: strfilename: strsubfolder: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecache\_dir: Union\[str, Path, None] = Nonelocal\_dir: Union\[str, Path, None] = Nonelocal\_dir\_use\_symlinks: Union\[bool, Literal\['auto']] = 'auto'force\_download: bool = Falseforce\_filename: Optional\[str] = Noneproxies: Optional\[Dict] = Noneetag\_timeout: float = 10resume\_download: bool = Falsetoken: Optional\[Union\[str, bool]] = Nonelocal\_files\_only: bool = Falselegacy\_cache\_layout: bool = False )

Parameters

* **repo\_id** (`str`) — A user or an organization name and a repo name separated by a `/`.
* **filename** (`str`) — The name of the file in the repo.
* **subfolder** (`str`, _optional_) — An optional value corresponding to a folder inside the model repo.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if downloading from a dataset or space, `None` or `"model"` if downloading from a model. Default is `None`.
* **revision** (`str`, _optional_) — An optional Git revision id which can be a branch name, a tag, or a commit hash.
* **endpoint** (`str`, _optional_) — Hugging Face Hub base url. Will default to [https://huggingface.co/](https://huggingface.co/). Otherwise, one can set the `HF_ENDPOINT` environment variable.
* **cache\_dir** (`str`, `Path`, _optional_) — Path to the folder where cached files are stored.
* **local\_dir** (`str` or `Path`, _optional_) — If provided, the downloaded file will be placed under this directory, either as a symlink (default) or a regular file (see description for more details).
* **local\_dir\_use\_symlinks** (`"auto"` or `bool`, defaults to `"auto"`) — To be used with `local_dir`. If set to “auto”, the cache directory will be used and the file will be either duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if already exists) or downloaded from the Hub and not cached. See description for more details.
* **force\_download** (`bool`, _optional_, defaults to `False`) — Whether the file should be downloaded even if it already exists in the local cache.
* **proxies** (`dict`, _optional_) — Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
* **etag\_timeout** (`float`, _optional_, defaults to `10`) — When fetching ETag, how many seconds to wait for the server to send data before giving up which is passed to `requests.request`.
* **resume\_download** (`bool`, _optional_, defaults to `False`) — If `True`, resume a previously interrupted download.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.
* **local\_files\_only** (`bool`, _optional_, defaults to `False`) — If `True`, avoid downloading the file and return the path to the local cached file if it exists.
* **legacy\_cache\_layout** (`bool`, _optional_, defaults to `False`) — If `True`, uses the legacy file cache layout i.e. just call [hf\_hub\_url()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/file_download#huggingface_hub.hf_hub_url) then `cached_download`. This is deprecated as the new cache layout is more powerful.

Download a given file if it’s not already present in the local cache.

The new cache file layout looks like this:

* The cache directory contains one subfolder per repo\_id (namespaced by repo type)
* inside each repo folder:
  * refs is a list of the latest known revision => commit\_hash pairs
  * blobs contains the actual file blobs (identified by their git-sha or sha256, depending on whether they’re LFS files or not)
  * snapshots contains one subfolder per commit, each “commit” contains the subset of the files that have been resolved at that particular commit. Each filename is a symlink to the blob at that particular commit.

If `local_dir` is provided, the file structure from the repo will be replicated in this location. You can configure how you want to move those files:

* If `local_dir_use_symlinks="auto"` (default), files are downloaded and stored in the cache directory as blob files. Small files (<5MB) are duplicated in `local_dir` while a symlink is created for bigger files. The goal is to be able to manually edit and save small files without corrupting the cache while saving disk space for binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD` environment variable.
* If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`. This is optimal in term of disk usage but files must not be manually edited.
* If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the local dir. This means disk usage is not optimized.
* Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the files are downloaded and directly placed under `local_dir`. This means if you need to download them again later, they will be re-downloaded entirely.

Copied

```
[  96]  .
└── [ 160]  models--julien-c--EsperBERTo-small
    ├── [ 160]  blobs
    │   ├── [321M]  403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
    │   ├── [ 398]  7cb18dc9bafbfcf74629a4b760af1b160957a83e
    │   └── [1.4K]  d7edf6bd2a681fb0175f7735299831ee1b22b812
    ├── [  96]  refs
    │   └── [  40]  main
    └── [ 128]  snapshots
        ├── [ 128]  2439f60ef33a0d46d85da5001d52aeda5b00ce9f
        │   ├── [  52]  README.md -> ../../blobs/d7edf6bd2a681fb0175f7735299831ee1b22b812
        │   └── [  76]  pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
        └── [ 128]  bbc77c8132af1cc5cf678da3f1ddf2de43606d48
            ├── [  52]  README.md -> ../../blobs/7cb18dc9bafbfcf74629a4b760af1b160957a83e
            └── [  76]  pytorch_model.bin -> ../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
```

Raises the following errors:

* [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError) if `token=True` and the token cannot be found.
* [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if ETag cannot be determined.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.
* [EntryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.EntryNotFoundError) If the file to download cannot be found.
* [LocalEntryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.LocalEntryNotFoundError) If network is disabled or unavailable and file is not found in cache.

**hide\_discussion\_comment**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5461)

( repo\_id: strdiscussion\_num: intcomment\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **comment\_id** (`str`) — The ID of the comment to edit.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionComment](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionComment)

the hidden comment

Hides a comment on a Discussion / Pull Request.

Hidden comments' content cannot be retrieved anymore. Hiding a comment is irreversible.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**like**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1583)

( repo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — The repository to like. Example: `"user/my-cool-model"`.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if liking a dataset or space, `None` or `"model"` if liking a model. Default is `None`.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.

Like a given repo on the Hub (e.g. set as favorite).

See also [unlike()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.unlike) and [list\_liked\_repos()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_liked_repos).



Example:

Copied

```
>>> from huggingface_hub import like, list_liked_repos, unlike
>>> like("gpt2")
>>> "gpt2" in list_liked_repos().models
True
>>> unlike("gpt2")
>>> "gpt2" in list_liked_repos().models
False
```

**list\_datasets**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1322)

( filter: Union\[DatasetFilter, str, Iterable\[str], None] = Noneauthor: Optional\[str] = Nonesearch: Optional\[str] = Nonesort: Union\[Literal\['lastModified'], str, None] = Nonedirection: Optional\[Literal\[-1]] = Nonelimit: Optional\[int] = Nonefull: Optional\[bool] = Nonetoken: Optional\[str] = None ) → `Iterable[DatasetInfo]`

Parameters

* **filter** ([DatasetFilter](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.DatasetFilter) or `str` or `Iterable`, _optional_) — A string or [DatasetFilter](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.DatasetFilter) which can be used to identify datasets on the hub.
* **author** (`str`, _optional_) — A string which identify the author of the returned datasets.
* **search** (`str`, _optional_) — A string that will be contained in the returned datasets.
* **sort** (`Literal["lastModified"]` or `str`, _optional_) — The key with which to sort the resulting datasets. Possible values are the properties of the [huggingface\_hub.hf\_api.DatasetInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.DatasetInfo) class.
* **direction** (`Literal[-1]` or `int`, _optional_) — Direction in which to sort. The value `-1` sorts by descending order while all other values sort by ascending order.
* **limit** (`int`, _optional_) — The limit on the number of datasets fetched. Leaving this option to `None` fetches all datasets.
* **full** (`bool`, _optional_) — Whether to fetch all dataset data, including the `lastModified` and the `cardData`. Can contain useful information such as the PapersWithCode ID.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`Iterable[DatasetInfo]`

an iterable of [huggingface\_hub.hf\_api.DatasetInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.DatasetInfo) objects.

List datasets hosted on the Huggingface Hub, given some filters.



Example usage with the `filter` argument:

Copied

```
>>> from huggingface_hub import HfApi

>>> api = HfApi()

>>> # List all datasets
>>> api.list_datasets()

>>> # Get all valid search arguments
>>> args = DatasetSearchArguments()

>>> # List only the text classification datasets
>>> api.list_datasets(filter="task_categories:text-classification")
>>> # Using the `DatasetFilter`
>>> filt = DatasetFilter(task_categories="text-classification")
>>> # With `DatasetSearchArguments`
>>> filt = DatasetFilter(task=args.task_categories.text_classification)
>>> api.list_models(filter=filt)

>>> # List only the datasets in russian for language modeling
>>> api.list_datasets(
...     filter=("language:ru", "task_ids:language-modeling")
... )
>>> # Using the `DatasetFilter`
>>> filt = DatasetFilter(language="ru", task_ids="language-modeling")
>>> # With `DatasetSearchArguments`
>>> filt = DatasetFilter(
...     language=args.language.ru,
...     task_ids=args.task_ids.language_modeling,
... )
>>> api.list_datasets(filter=filt)
```



Example usage with the `search` argument:

Copied

```
>>> from huggingface_hub import HfApi

>>> api = HfApi()

>>> # List all datasets with "text" in their name
>>> api.list_datasets(search="text")

>>> # List all datasets with "text" in their name made by google
>>> api.list_datasets(search="text", author="google")
```

**list\_files\_info**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2169)

( repo\_id: strpaths: Union\[List\[str], str, None] = Noneexpand: bool = Falserevision: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonetoken: Optional\[Union\[bool, str]] = None ) → `Iterable[RepoFile]`

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **paths** (`Union[List[str], str, None]`, _optional_) — The paths to get information about. Paths to files are directly resolved. Paths to folders are resolved recursively which means that information is returned about all files in the folder and its subfolders. If `None`, all files are returned (the default). If a path do not exist, it is ignored without raising an exception.
* **expand** (`bool`, _optional_, defaults to `False`) — Whether to fetch more information about the files (e.g. last commit and security scan results). This operation is more expensive for the server so only 50 results are returned per page (instead of 1000). As pagination is implemented in `huggingface_hub`, this is transparent for you except for the time it takes to get the results.
* **revision** (`str`, _optional_) — The revision of the repository from which to get the information. Defaults to `"main"` branch.
* **repo\_type** (`str`, _optional_) — The type of the repository from which to get the information (`"model"`, `"dataset"` or `"space"`. Defaults to `"model"`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`Iterable[RepoFile]`

The information about the files, as an iterable of `RepoFile` objects. The order of the files is not guaranteed.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) — If revision is not found (error 404) on the repo.

List files on a repo and get information about them.

Takes as input a list of paths. Those paths can be either files or folders. Two server endpoints are called:

1. POST “/paths-info” to get information about the provided paths. Called once.
2. GET “/tree?recursive=True” to paginate over the input folders. Called only if a folder path is provided as input. Will be called multiple times to follow pagination. If no path is provided as input, step 1. is ignored and all files from the repo are listed.

Examples:

Get information about files on a repo.

Copied

```
>>> from huggingface_hub import list_files_info
>>> files_info = list_files_info("lysandre/arxiv-nlp", ["README.md", "config.json"])
>>> files_info
<generator object HfApi.list_files_info at 0x7f93b848e730>
>>> list(files_info)
[
    RepoFile: {"blob_id": "43bd404b159de6fba7c2f4d3264347668d43af25", "lfs": None, "rfilename": "README.md", "size": 391},
    RepoFile: {"blob_id": "2f9618c3a19b9a61add74f70bfb121335aeef666", "lfs": None, "rfilename": "config.json", "size": 554},
]
```

Get even more information about files on a repo (last commit and security scan results)

Copied

```
>>> from huggingface_hub import list_files_info
>>> files_info = list_files_info("prompthero/openjourney-v4", expand=True)
>>> list(files_info)
[
    RepoFile: {
    {'blob_id': '815004af1a321eaed1d93f850b2e94b0c0678e42',
    'lastCommit': {'date': '2023-03-21T09:05:27.000Z',
                    'id': '47b62b20b20e06b9de610e840282b7e6c3d51190',
                    'title': 'Upload diffusers weights (#48)'},
    'lfs': None,
    'rfilename': 'model_index.json',
    'security': {'avScan': {'virusFound': False, 'virusNames': None},
                    'blobId': '815004af1a321eaed1d93f850b2e94b0c0678e42',
                    'name': 'model_index.json',
                    'pickleImportScan': None,
                    'repositoryId': 'models/prompthero/openjourney-v4',
                    'safe': True},
    'size': 584}
    },
    RepoFile: {
    {'blob_id': 'd2343d78b33ac03dade1d525538b02b130d0a3a0',
    'lastCommit': {'date': '2023-03-21T09:05:27.000Z',
                    'id': '47b62b20b20e06b9de610e840282b7e6c3d51190',
                    'title': 'Upload diffusers weights (#48)'},
    'lfs': {'pointer_size': 134,
            'sha256': 'dcf4507d99b88db73f3916e2a20169fe74ada6b5582e9af56cfa80f5f3141765',
            'size': 334711857},
    'rfilename': 'vae/diffusion_pytorch_model.bin',
    'security': {'avScan': {'virusFound': False, 'virusNames': None},
                    'blobId': 'd2343d78b33ac03dade1d525538b02b130d0a3a0',
                    'name': 'vae/diffusion_pytorch_model.bin',
                    'pickleImportScan': {'highestSafetyLevel': 'innocuous',
                                        'imports': [{'module': 'torch._utils',
                                                    'name': '_rebuild_tensor_v2',
                                                    'safety': 'innocuous'},
                                                    {'module': 'collections', 'name': 'OrderedDict', 'safety': 'innocuous'},
                                                    {'module': 'torch', 'name': 'FloatStorage', 'safety': 'innocuous'}]},
                    'repositoryId': 'models/prompthero/openjourney-v4',
                    'safe': True},
    'size': 334711857}
    },
    (...)
]
```

List LFS files from the “vae/” folder in “stabilityai/stable-diffusion-2” repository.

Copied

```
>>> from huggingface_hub import list_files_info
>>> [info.rfilename for info in list_files_info("stabilityai/stable-diffusion-2", "vae") if info.lfs is not None]
['vae/diffusion_pytorch_model.bin', 'vae/diffusion_pytorch_model.safetensors']
```

List all files on a repo.

Copied

```
>>> from huggingface_hub import list_files_info
>>> [info.rfilename for info in list_files_info("glue", repo_type="dataset")]
['.gitattributes', 'README.md', 'dataset_infos.json', 'glue.py']
```

**list\_liked\_repos**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1678)

( user: Optional\[str] = Nonetoken: Optional\[str] = None ) → [UserLikes](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.UserLikes)

Parameters

* **user** (`str`, _optional_) — Name of the user for which you want to fetch the likes.
* **token** (`str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). Used only if `user` is not passed to implicitly determine the current user name.

Returns

[UserLikes](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.UserLikes)

object containing the user name and 3 lists of repo ids (1 for models, 1 for datasets and 1 for Spaces).

Raises

`ValueError`

* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If `user` is not passed and no token found (either from argument or from machine).

List all public repos liked by a user on huggingface.co.

This list is public so token is optional. If `user` is not passed, it defaults to the logged in user.

See also [like()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.like) and [unlike()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.unlike).



Example:

Copied

```
>>> from huggingface_hub import list_liked_repos

>>> likes = list_liked_repos("julien-c")

>>> likes.user
"julien-c"

>>> likes.models
["osanseviero/streamlit_1.15", "Xhaheen/ChatGPT_HF", ...]
```

**list\_metrics**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1485)

( ) → `List[MetricInfo]`

Returns

`List[MetricInfo]`

a list of `MetricInfo` objects which.

Get the public list of all the metrics on huggingface.co

**list\_models**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1124)

( filter: Union\[ModelFilter, str, Iterable\[str], None] = Noneauthor: Optional\[str] = Nonesearch: Optional\[str] = Noneemissions\_thresholds: Optional\[Tuple\[float, float]] = Nonesort: Union\[Literal\['lastModified'], str, None] = Nonedirection: Optional\[Literal\[-1]] = Nonelimit: Optional\[int] = Nonefull: Optional\[bool] = NonecardData: bool = Falsefetch\_config: bool = Falsetoken: Optional\[Union\[bool, str]] = None ) → `Iterable[ModelInfo]`

Parameters

* **filter** ([ModelFilter](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.ModelFilter) or `str` or `Iterable`, _optional_) — A string or [ModelFilter](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.ModelFilter) which can be used to identify models on the Hub.
* **author** (`str`, _optional_) — A string which identify the author (user or organization) of the returned models
* **search** (`str`, _optional_) — A string that will be contained in the returned model ids.
* **emissions\_thresholds** (`Tuple`, _optional_) — A tuple of two ints or floats representing a minimum and maximum carbon footprint to filter the resulting models with in grams.
* **sort** (`Literal["lastModified"]` or `str`, _optional_) — The key with which to sort the resulting models. Possible values are the properties of the [huggingface\_hub.hf\_api.ModelInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.ModelInfo) class.
* **direction** (`Literal[-1]` or `int`, _optional_) — Direction in which to sort. The value `-1` sorts by descending order while all other values sort by ascending order.
* **limit** (`int`, _optional_) — The limit on the number of models fetched. Leaving this option to `None` fetches all models.
* **full** (`bool`, _optional_) — Whether to fetch all model data, including the `lastModified`, the `sha`, the files and the `tags`. This is set to `True` by default when using a filter.
* **cardData** (`bool`, _optional_) — Whether to grab the metadata for the model as well. Can contain useful information such as carbon emissions, metrics, and datasets trained on.
* **fetch\_config** (`bool`, _optional_) — Whether to fetch the model configs as well. This is not included in `full` due to its size.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`Iterable[ModelInfo]`

an iterable of [huggingface\_hub.hf\_api.ModelInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.ModelInfo) objects.

List models hosted on the Huggingface Hub, given some filters.



Example usage with the `filter` argument:

Copied

```
>>> from huggingface_hub import HfApi

>>> api = HfApi()

>>> # List all models
>>> api.list_models()

>>> # Get all valid search arguments
>>> args = ModelSearchArguments()

>>> # List only the text classification models
>>> api.list_models(filter="text-classification")
>>> # Using the `ModelFilter`
>>> filt = ModelFilter(task="text-classification")
>>> # With `ModelSearchArguments`
>>> filt = ModelFilter(task=args.pipeline_tags.TextClassification)
>>> api.list_models(filter=filt)

>>> # Using `ModelFilter` and `ModelSearchArguments` to find text classification in both PyTorch and TensorFlow
>>> filt = ModelFilter(
...     task=args.pipeline_tags.TextClassification,
...     library=[args.library.PyTorch, args.library.TensorFlow],
... )
>>> api.list_models(filter=filt)

>>> # List only models from the AllenNLP library
>>> api.list_models(filter="allennlp")
>>> # Using `ModelFilter` and `ModelSearchArguments`
>>> filt = ModelFilter(library=args.library.allennlp)
```



Example usage with the `search` argument:

Copied

```
>>> from huggingface_hub import HfApi

>>> api = HfApi()

>>> # List all models with "bert" in their name
>>> api.list_models(search="bert")

>>> # List all models with "bert" in their name made by google
>>> api.list_models(search="bert", author="google")
```

**list\_repo\_commits**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2449)

( repo\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[Union\[bool, str]] = Nonerevision: Optional\[str] = Noneformatted: bool = False ) → List\[[GitCommitInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitCommitInfo)]

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if listing from a model. Default is `None`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **formatted** (`bool`) — Whether to return the HTML-formatted title and description of the commits. Defaults to False.

Returns

List\[[GitCommitInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitCommitInfo)]

list of objects containing information about the commits for a repo on the Hub.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) — If revision is not found (error 404) on the repo.

Get the list of commits of a given revision for a repo on the Hub.

Commits are sorted by date (last commit first).



Example:

Copied

```
>>> from huggingface_hub import HfApi
>>> api = HfApi()

# Commits are sorted by date (last commit first)
>>> initial_commit = api.list_repo_commits("gpt2")[-1]

# Initial commit is always a system commit containing the `.gitattributes` file.
>>> initial_commit
GitCommitInfo(
    commit_id='9b865efde13a30c13e0a33e536cf3e4a5a9d71d8',
    authors=['system'],
    created_at=datetime.datetime(2019, 2, 18, 10, 36, 15, tzinfo=datetime.timezone.utc),
    title='initial commit',
    message='',
    formatted_title=None,
    formatted_message=None
)

# Create an empty branch by deriving from initial commit
>>> api.create_branch("gpt2", "new_empty_branch", revision=initial_commit.commit_id)
```

**list\_repo\_files**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2352)

( repo\_id: strrevision: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonetimeout: Optional\[float] = Nonetoken: Optional\[Union\[bool, str]] = None ) → `List[str]`

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **revision** (`str`, _optional_) — The revision of the model repository from which to get the information.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`List[str]`

the list of files in a given repository.

Get the list of files in a given repo.

**list\_repo\_likers**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1753)

( repo\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None ) → `List[User]`

Parameters

* **repo\_id** (`str`) — The repository to retrieve . Example: `"user/my-cool-model"`.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.

Returns

`List[User]`

a list of [User](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.User) objects.

List all users who liked a given repo on the hugging Face Hub.

See also [like()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.like) and [list\_liked\_repos()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_liked_repos).

**list\_repo\_refs**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2389)

( repo\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[Union\[bool, str]] = None ) → [GitRefs](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitRefs)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if listing refs from a dataset or a Space, `None` or `"model"` if listing from a model. Default is `None`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

[GitRefs](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitRefs)

object containing all information about branches and tags for a repo on the Hub.

Get the list of refs of a given repo (both tags and branches).



Example:

Copied

```
>>> from huggingface_hub import HfApi
>>> api = HfApi()
>>> api.list_repo_refs("gpt2")
GitRefs(branches=[GitRefInfo(name='main', ref='refs/heads/main', target_commit='e7da7f221d5bf496a48136c0cd264e630fe9fcc8')], converts=[], tags=[])

>>> api.list_repo_refs("bigcode/the-stack", repo_type='dataset')
GitRefs(
    branches=[
        GitRefInfo(name='main', ref='refs/heads/main', target_commit='18edc1591d9ce72aa82f56c4431b3c969b210ae3'),
        GitRefInfo(name='v1.1.a1', ref='refs/heads/v1.1.a1', target_commit='f9826b862d1567f3822d3d25649b0d6d22ace714')
    ],
    converts=[],
    tags=[
        GitRefInfo(name='v1.0', ref='refs/tags/v1.0', target_commit='c37a8cd1e382064d8aced5e05543c5f7753834da')
    ]
)
```

**list\_spaces**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1498)

( filter: Union\[str, Iterable\[str], None] = Noneauthor: Optional\[str] = Nonesearch: Optional\[str] = Nonesort: Union\[Literal\['lastModified'], str, None] = Nonedirection: Optional\[Literal\[-1]] = Nonelimit: Optional\[int] = Nonedatasets: Union\[str, Iterable\[str], None] = Nonemodels: Union\[str, Iterable\[str], None] = Nonelinked: bool = Falsefull: Optional\[bool] = Nonetoken: Optional\[str] = None ) → `Iterable[SpaceInfo]`

Parameters

* **filter** (`str` or `Iterable`, _optional_) — A string tag or list of tags that can be used to identify Spaces on the Hub.
* **author** (`str`, _optional_) — A string which identify the author of the returned Spaces.
* **search** (`str`, _optional_) — A string that will be contained in the returned Spaces.
* **sort** (`Literal["lastModified"]` or `str`, _optional_) — The key with which to sort the resulting Spaces. Possible values are the properties of the [huggingface\_hub.hf\_api.SpaceInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.SpaceInfo)\` class.
* **direction** (`Literal[-1]` or `int`, _optional_) — Direction in which to sort. The value `-1` sorts by descending order while all other values sort by ascending order.
* **limit** (`int`, _optional_) — The limit on the number of Spaces fetched. Leaving this option to `None` fetches all Spaces.
* **datasets** (`str` or `Iterable`, _optional_) — Whether to return Spaces that make use of a dataset. The name of a specific dataset can be passed as a string.
* **models** (`str` or `Iterable`, _optional_) — Whether to return Spaces that make use of a model. The name of a specific model can be passed as a string.
* **linked** (`bool`, _optional_) — Whether to return Spaces that make use of either a model or a dataset.
* **full** (`bool`, _optional_) — Whether to fetch all Spaces data, including the `lastModified` and the `cardData`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`Iterable[SpaceInfo]`

an iterable of [huggingface\_hub.hf\_api.SpaceInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.SpaceInfo) objects.

List spaces hosted on the Huggingface Hub, given some filters.

**merge\_pull\_request**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5351)

( repo\_id: strdiscussion\_num: inttoken: Optional\[str] = Nonecomment: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionStatusChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionStatusChange)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **comment** (`str`, _optional_) — An optional comment to post with the status change.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionStatusChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionStatusChange)

the status change event

Merges a Pull Request.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**model\_info**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1803)

( repo\_id: strrevision: Optional\[str] = Nonetimeout: Optional\[float] = NonesecurityStatus: Optional\[bool] = Nonefiles\_metadata: bool = Falsetoken: Optional\[Union\[bool, str]] = None ) → [huggingface\_hub.hf\_api.ModelInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.ModelInfo)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **revision** (`str`, _optional_) — The revision of the model repository from which to get the information.
* **timeout** (`float`, _optional_) — Whether to set a timeout for the request to the Hub.
* **securityStatus** (`bool`, _optional_) — Whether to retrieve the security status from the model repository as well.
* **files\_metadata** (`bool`, _optional_) — Whether or not to retrieve metadata for files in the repository (size, LFS metadata, etc). Defaults to `False`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

[huggingface\_hub.hf\_api.ModelInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.ModelInfo)

The model repository information.

Get info on one specific model on huggingface.co

Model can be private if you pass an acceptable token or are logged in.

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.

**move\_repo**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2854)

( from\_id: strto\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **from\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`. Original repository identifier.
* **to\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`. Final repository identifier.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Moving a repository from namespace1/repo\_name1 to namespace2/repo\_name2

Note there are certain limitations. For more information about moving repositories, please see [https://hf.co/docs/hub/repositories-settings#renaming-or-transferring-a-repo](https://hf.co/docs/hub/repositories-settings#renaming-or-transferring-a-repo).

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**pause\_space**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5767)

( repo\_id: strtoken: Optional\[str] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the Space to pause. Example: `"Salesforce/BLIP2"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about your Space including `stage=PAUSED` and requested hardware.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) or [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If your Space is not found (error 404). Most probably wrong repo\_id or your space is private but you are not authenticated.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — 403 Forbidden: only the owner of a Space can pause it. If you want to manage a Space that you don’t own, either ask the owner by opening a Discussion or duplicate the Space.
* [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError) — If your Space is a static Space. Static Spaces are always running and never billed. If you want to hide a static Space, you can set it to private.

Pause your Space.

A paused Space stops executing until manually restarted by its owner. This is different from the sleeping state in which free Spaces go after 48h of inactivity. Paused time is not billed to your account, no matter the hardware you’ve selected. To restart your Space, use [restart\_space()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.restart_space) and go to your Space settings page.

For more details, please visit [the docs](https://huggingface.co/docs/hub/spaces-gpus#pause).

**preupload\_lfs\_files**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L3473)

( repo\_id: stradditions: Iterable\[CommitOperationAdd]token: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Nonenum\_threads: int = 5free\_memory: bool = True )

Parameters

* **repo\_id** (`str`) — The repository in which you will commit the files, for example: `"username/custom_transformers"`.
* **operations** (`Iterable` of [CommitOperationAdd](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd)) — The list of files to upload. Warning: the objects in this list will be mutated to include information relative to the upload. Do not reuse the same objects for multiple commits.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — The type of repository to upload to (e.g. `"model"` -default-, `"dataset"` or `"space"`).
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **create\_pr** (`boolean`, _optional_) — Whether or not you plan to create a Pull Request with that commit. Defaults to `False`.
* **num\_threads** (`int`, _optional_) — Number of concurrent threads for uploading files. Defaults to 5. Setting it to 2 means at most 2 files will be uploaded concurrently.

Pre-upload LFS files to S3 in preparation on a future commit.

This method is useful if you are generating the files to upload on-the-fly and you don’t want to store them in memory before uploading them all at once.

This is a power-user method. You shouldn’t need to call it directly to make a normal commit. Use [create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit) directly instead.

Commit operations will be mutated during the process. In particular, the attached `path_or_fileobj` will be removed after the upload to save memory (and replaced by an empty `bytes` object). Do not reuse the same objects except to pass them to [create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit). If you don’t want to remove the attached content from the commit operation object, pass `free_memory=False`.



Example:

Copied

```
>>> from huggingface_hub import CommitOperationAdd, preupload_lfs_files, create_commit, create_repo

>>> repo_id = create_repo("test_preupload").repo_id

# Generate and preupload LFS files one by one
>>> operations = [] # List of all `CommitOperationAdd` objects that will be generated
>>> for i in range(5):
...     content = ... # generate binary content
...     addition = CommitOperationAdd(path_in_repo=f"shard_{i}_of_5.bin", path_or_fileobj=content)
...     preupload_lfs_files(repo_id, additions=[addition]) # upload + free memory
...     operations.append(addition)

# Create commit
>>> create_commit(repo_id, operations=operations, commit_message="Commit all shards")
```

**rename\_discussion**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5209)

( repo\_id: strdiscussion\_num: intnew\_title: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None ) → [DiscussionTitleChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionTitleChange)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **discussion\_num** (`int`) — The number of the Discussion or Pull Request . Must be a strictly positive integer.
* **new\_title** (`str`) — The new title for the discussion
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))

Returns

[DiscussionTitleChange](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/community#huggingface_hub.DiscussionTitleChange)

the title change event

Renames a Discussion.



Examples:

Copied

```
>>> new_title = "New title, fixing a typo"
>>> HfApi().rename_discussion(
...     repo_id="username/repo_name",
...     discussion_num=34
...     new_title=new_title
... )
# DiscussionTitleChange(id='deadbeef0000000', type='title-change', ...)
```

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**repo\_exists**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2065)

( repo\_id: strrepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space, `None` or `"model"` if getting repository info from a model. Default is `None`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Checks if a repository exists on the Hugging Face Hub.



Examples:

Copied

```
>>> from huggingface_hub import repo_exists
>>> repo_exists("huggingface/transformers")
True
>>> repo_exists("huggingface/not-a-repo")
False
```

**repo\_info**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1997)

( repo\_id: strrevision: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonetimeout: Optional\[float] = Nonefiles\_metadata: bool = Falsetoken: Optional\[Union\[bool, str]] = None ) → `Union[SpaceInfo, DatasetInfo, ModelInfo]`

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **revision** (`str`, _optional_) — The revision of the repository from which to get the information.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if getting repository info from a dataset or a space, `None` or `"model"` if getting repository info from a model. Default is `None`.
* **timeout** (`float`, _optional_) — Whether to set a timeout for the request to the Hub.
* **files\_metadata** (`bool`, _optional_) — Whether or not to retrieve metadata for files in the repository (size, LFS metadata, etc). Defaults to `False`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

`Union[SpaceInfo, DatasetInfo, ModelInfo]`

The repository information, as a [huggingface\_hub.hf\_api.DatasetInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.DatasetInfo), [huggingface\_hub.hf\_api.ModelInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.ModelInfo) or [huggingface\_hub.hf\_api.SpaceInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.SpaceInfo) object.

Get the info object for a given repo of a given type.

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.

**request\_space\_hardware**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5671)

( repo\_id: strhardware: SpaceHardwaretoken: Optional\[str] = Nonesleep\_time: Optional\[int] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **hardware** (`str` or [SpaceHardware](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceHardware)) — Hardware on which to run the Space. Example: `"t4-medium"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.
* **sleep\_time** (`int`, _optional_) — Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don’t want your Space to sleep (default behavior for upgraded hardware). For free hardware, you can’t configure the sleep time (value is fixed to 48 hours of inactivity). See [https://huggingface.co/docs/hub/spaces-gpus#sleep-time](https://huggingface.co/docs/hub/spaces-gpus#sleep-time) for more details.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about a Space including Space stage and hardware.

Request new hardware for a Space.

It is also possible to request hardware directly when creating the Space repo! See [create\_repo()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo) for details.

**request\_space\_storage**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5961)

( repo\_id: strstorage: SpaceStoragetoken: Optional\[str] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the Space to update. Example: `"HuggingFaceH4/open_llm_leaderboard"`.
* **storage** (`str` or [SpaceStorage](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceStorage)) — Storage tier. Either ‘small’, ‘medium’, or ‘large’.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about a Space including Space stage and hardware.

Request persistent storage for a Space.

It is not possible to decrease persistent storage after its granted. To do so, you must delete it via [delete\_space\_storage()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.delete_space_storage).

**restart\_space**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5803)

( repo\_id: strtoken: Optional\[str] = Nonefactory\_reboot: bool = False ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the Space to restart. Example: `"Salesforce/BLIP2"`.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.
* **factory\_reboot** (`bool`, _optional_) — If `True`, the Space will be rebuilt from scratch without caching any requirements.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about your Space.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) or [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If your Space is not found (error 404). Most probably wrong repo\_id or your space is private but you are not authenticated.
* [HfHubHTTPError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.HfHubHTTPError) — 403 Forbidden: only the owner of a Space can restart it. If you want to restart a Space that you don’t own, either ask the owner by opening a Discussion or duplicate the Space.
* [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError) — If your Space is a static Space. Static Spaces are always running and never billed. If you want to hide a static Space, you can set it to private.

Restart your Space.

This is the only way to programmatically restart a Space if you’ve put it on Pause (see [pause\_space()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.pause_space)). You must be the owner of the Space to restart it. If you are using an upgraded hardware, your account will be billed as soon as the Space is restarted. You can trigger a restart no matter the current state of a Space.

For more details, please visit [the docs](https://huggingface.co/docs/hub/spaces-gpus#pause).

**run\_as\_future**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1015)

( fn: Callable\[..., R]\*args\*\*kwargs ) → `Future`

Parameters

* **fn** (`Callable`) — The method to run in the background.
* **\*args,** \*\*kwargs — Arguments with which the method will be called.

Returns

`Future`

a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects) instance to get the result of the task.

Run a method in the background and return a Future instance.

The main goal is to run methods without blocking the main thread (e.g. to push data during a training). Background jobs are queued to preserve order but are not ran in parallel. If you need to speed-up your scripts by parallelizing lots of call to the API, you must setup and use your own [ThreadPoolExecutor](https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor).

Note: Most-used methods like [upload\_file()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file), [upload\_folder()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder) and [create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit) have a `run_as_future: bool` argument to directly call them in the background. This is equivalent to calling `api.run_as_future(...)` on them but less verbose.



Example:

Copied

```
>>> from huggingface_hub import HfApi
>>> api = HfApi()
>>> future = api.run_as_future(api.whoami) # instant
>>> future.done()
False
>>> future.result() # wait until complete and return result
(...)
>>> future.done()
True
```

**set\_space\_sleep\_time**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L5721)

( repo\_id: strsleep\_time: inttoken: Optional\[str] = None ) → [SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Parameters

* **repo\_id** (`str`) — ID of the repo to update. Example: `"bigcode/in-the-stack"`.
* **sleep\_time** (`int`, _optional_) — Number of seconds of inactivity to wait before a Space is put to sleep. Set to `-1` if you don’t want your Space to pause (default behavior for upgraded hardware). For free hardware, you can’t configure the sleep time (value is fixed to 48 hours of inactivity). See [https://huggingface.co/docs/hub/spaces-gpus#sleep-time](https://huggingface.co/docs/hub/spaces-gpus#sleep-time) for more details.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Returns

[SpaceRuntime](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/space_runtime#huggingface_hub.SpaceRuntime)

Runtime information about a Space including Space stage and hardware.

Set a custom sleep time for a Space running on upgraded hardware..

Your Space will go to sleep after X seconds of inactivity. You are not billed when your Space is in “sleep” mode. If a new visitor lands on your Space, it will “wake it up”. Only upgraded hardware can have a configurable sleep time. To know more about the sleep stage, please refer to [https://huggingface.co/docs/hub/spaces-gpus#sleep-time](https://huggingface.co/docs/hub/spaces-gpus#sleep-time).

It is also possible to set a custom sleep time when requesting hardware with [request\_space\_hardware()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.request_space_hardware).

**snapshot\_download**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L4394)

( repo\_id: strrepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecache\_dir: Union\[str, Path, None] = Nonelocal\_dir: Union\[str, Path, None] = Nonelocal\_dir\_use\_symlinks: Union\[bool, Literal\['auto']] = 'auto'proxies: Optional\[Dict] = Noneetag\_timeout: float = 10resume\_download: bool = Falseforce\_download: bool = Falsetoken: Optional\[Union\[str, bool]] = Nonelocal\_files\_only: bool = Falseallow\_patterns: Optional\[Union\[List\[str], str]] = Noneignore\_patterns: Optional\[Union\[List\[str], str]] = Nonemax\_workers: int = 8tqdm\_class: Optional\[base\_tqdm] = None )

Parameters

* **repo\_id** (`str`) — A user or an organization name and a repo name separated by a `/`.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if downloading from a dataset or space, `None` or `"model"` if downloading from a model. Default is `None`.
* **revision** (`str`, _optional_) — An optional Git revision id which can be a branch name, a tag, or a commit hash.
* **cache\_dir** (`str`, `Path`, _optional_) — Path to the folder where cached files are stored.
* **local\_dir** (`str` or `Path`, _optional_) — If provided, the downloaded files will be placed under this directory, either as symlinks (default) or regular files (see description for more details).
* **local\_dir\_use\_symlinks** (`"auto"` or `bool`, defaults to `"auto"`) — To be used with `local_dir`. If set to “auto”, the cache directory will be used and the file will be either duplicated or symlinked to the local directory depending on its size. It set to `True`, a symlink will be created, no matter the file size. If set to `False`, the file will either be duplicated from cache (if already exists) or downloaded from the Hub and not cached. See description for more details.
* **proxies** (`dict`, _optional_) — Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
* **etag\_timeout** (`float`, _optional_, defaults to `10`) — When fetching ETag, how many seconds to wait for the server to send data before giving up which is passed to `requests.request`.
* **resume\_download** (`bool`, _optional_, defaults to `False) -- If` True\`, resume a previously interrupted download.
* **force\_download** (`bool`, _optional_, defaults to `False`) — Whether the file should be downloaded even if it already exists in the local cache.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.
* **local\_files\_only** (`bool`, _optional_, defaults to `False`) — If `True`, avoid downloading the file and return the path to the local cached file if it exists.
* **allow\_patterns** (`List[str]` or `str`, _optional_) — If provided, only files matching at least one pattern are downloaded.
* **ignore\_patterns** (`List[str]` or `str`, _optional_) — If provided, files matching any of the patterns are not downloaded.
* **max\_workers** (`int`, _optional_) — Number of concurrent threads to download files (1 thread = 1 file download). Defaults to 8.
* **tqdm\_class** (`tqdm`, _optional_) — If provided, overwrites the default behavior for the progress bar. Passed argument must inherit from `tqdm.auto.tqdm` or at least mimic its behavior. Note that the `tqdm_class` is not passed to each individual download. Defaults to the custom HF progress bar that can be disabled by setting `HF_HUB_DISABLE_PROGRESS_BARS` environment variable.

Download repo files.

Download a whole snapshot of a repo’s files at the specified revision. This is useful when you want all files from a repo, because you don’t know which ones you will need a priori. All files are nested inside a folder in order to keep their actual filename relative to that folder. You can also filter which files to download using `allow_patterns` and `ignore_patterns`.

If `local_dir` is provided, the file structure from the repo will be replicated in this location. You can configure how you want to move those files:

* If `local_dir_use_symlinks="auto"` (default), files are downloaded and stored in the cache directory as blob files. Small files (<5MB) are duplicated in `local_dir` while a symlink is created for bigger files. The goal is to be able to manually edit and save small files without corrupting the cache while saving disk space for binary files. The 5MB threshold can be configured with the `HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD` environment variable.
* If `local_dir_use_symlinks=True`, files are downloaded, stored in the cache directory and symlinked in `local_dir`. This is optimal in term of disk usage but files must not be manually edited.
* If `local_dir_use_symlinks=False` and the blob files exist in the cache directory, they are duplicated in the local dir. This means disk usage is not optimized.
* Finally, if `local_dir_use_symlinks=False` and the blob files do not exist in the cache directory, then the files are downloaded and directly placed under `local_dir`. This means if you need to download them again later, they will be re-downloaded entirely.

An alternative would be to clone the repo but this requires git and git-lfs to be installed and properly configured. It is also not possible to filter which files to download when cloning a repository using git.

Raises the following errors:

* [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError) if `token=True` and the token cannot be found.
* [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if ETag cannot be determined.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid

**space\_info**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1934)

( repo\_id: strrevision: Optional\[str] = Nonetimeout: Optional\[float] = Nonefiles\_metadata: bool = Falsetoken: Optional\[Union\[bool, str]] = None ) → [SpaceInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.SpaceInfo)

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **revision** (`str`, _optional_) — The revision of the space repository from which to get the information.
* **timeout** (`float`, _optional_) — Whether to set a timeout for the request to the Hub.
* **files\_metadata** (`bool`, _optional_) — Whether or not to retrieve metadata for files in the repository (size, LFS metadata, etc). Defaults to `False`.
* **token** (`bool` or `str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If `None` or `True` and machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token will be retrieved from the cache. If `False`, token is not sent in the request header.

Returns

[SpaceInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.SpaceInfo)

The space repository information.

Get info on one specific Space on huggingface.co.

Space can be private if you pass an acceptable token.

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.

**super\_squash\_history**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2527)

( repo\_id: strbranch: Optional\[str] = Nonecommit\_message: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — A namespace (user or an organization) and a repo name separated by a `/`.
* **branch** (`str`, _optional_) — The branch to squash. Defaults to the head of the `"main"` branch.
* **commit\_message** (`str`, _optional_) — The commit message to use for the squashed commit.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if listing commits from a dataset or a Space, `None` or `"model"` if listing from a model. Default is `None`.
* **token** (`str`, _optional_) — A valid authentication token (see [https://huggingface.co/settings/token](https://huggingface.co/settings/token)). If the machine is logged in (through `huggingface-cli login` or [login()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/login#huggingface_hub.login)), token can be automatically retrieved from the cache.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) or [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) or [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) — If the branch to squash cannot be found.
* [BadRequestError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.BadRequestError) — If invalid reference for a branch. You cannot squash history on tags.

Squash commit history on a branch for a repo on the Hub.

Squashing the repo history is useful when you know you’ll make hundreds of commits and you don’t want to clutter the history. Squashing commits can only be performed from the head of a branch.

Once squashed, the commit history cannot be retrieved. This is a non-revertible operation.

Once the history of a branch has been squashed, it is not possible to merge it back into another branch since their history will have diverged.



Example:

Copied

```
>>> from huggingface_hub import HfApi
>>> api = HfApi()

# Create repo
>>> repo_id = api.create_repo("test-squash").repo_id

# Make a lot of commits.
>>> api.upload_file(repo_id=repo_id, path_in_repo="file.txt", path_or_fileobj=b"content")
>>> api.upload_file(repo_id=repo_id, path_in_repo="lfs.bin", path_or_fileobj=b"content")
>>> api.upload_file(repo_id=repo_id, path_in_repo="file.txt", path_or_fileobj=b"another_content")

# Squash history
>>> api.super_squash_history(repo_id=repo_id)
```

**unlike**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1631)

( repo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = None )

Parameters

* **repo\_id** (`str`) — The repository to unlike. Example: `"user/my-cool-model"`.
* **token** (`str`, _optional_) — Authentication token. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if unliking a dataset or space, `None` or `"model"` if unliking a model. Default is `None`.

Raises

[RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError)

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) — If repository is not found (error 404): wrong repo\_id/repo\_type, private but not authenticated or repo does not exist.

Unlike a given repo on the Hub (e.g. remove from favorite list).

See also [like()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.like) and [list\_liked\_repos()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_liked_repos).



Example:

Copied

```
>>> from huggingface_hub import like, list_liked_repos, unlike
>>> like("gpt2")
>>> "gpt2" in list_liked_repos().models
True
>>> unlike("gpt2")
>>> "gpt2" in list_liked_repos().models
False
```

**update\_collection\_item**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6304)

( collection\_slug: stritem\_object\_id: strnote: Optional\[str] = Noneposition: Optional\[int] = Nonetoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection to update. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **item\_object\_id** (`str`) — ID of the item in the collection. This is not the id of the item on the Hub (repo\_id or paper id). It must be retrieved from a [CollectionItem](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.CollectionItem) object. Example: `collection.items[0]._id`.
* **note** (`str`, _optional_) — A note to attach to the item in the collection. The maximum size for a note is 500 characters.
* **position** (`int`, _optional_) — New position of the item in the collection.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Update an item in a collection.



Example:

Copied

```
>>> from huggingface_hub import get_collection, update_collection_item

# Get collection first
>>> collection = get_collection("TheBloke/recent-models-64f9a55bb3115b4f513ec026")

# Update item based on its ID (add note + update position)
>>> update_collection_item(
...     collection_slug="TheBloke/recent-models-64f9a55bb3115b4f513ec026",
...     item_object_id=collection.items[-1].item_object_id,
...     note="Newly updated model!"
...     position=0,
... )
```

**update\_collection\_metadata**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L6131)

( collection\_slug: strtitle: Optional\[str] = Nonedescription: Optional\[str] = Noneposition: Optional\[int] = Noneprivate: Optional\[bool] = Nonetheme: Optional\[str] = Nonetoken: Optional\[str] = None )

Parameters

* **collection\_slug** (`str`) — Slug of the collection to update. Example: `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`.
* **title** (`str`) — Title of the collection to update.
* **description** (`str`, _optional_) — Description of the collection to update.
* **position** (`int`, _optional_) — New position of the collection in the list of collections of the user.
* **private** (`bool`, _optional_) — Whether the collection should be private or not.
* **theme** (`str`, _optional_) — Theme of the collection on the Hub.
* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Update metadata of a collection on the Hub.

All arguments are optional. Only provided metadata will be updated.

Returns: [Collection](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/collections#huggingface_hub.Collection)



Example:

Copied

```
>>> from huggingface_hub import update_collection_metadata
>>> collection = update_collection_metadata(
...     collection_slug="username/iccv-2023-64f9a55bb3115b4f513ec026",
...     title="ICCV Oct. 2023"
...     description="Portfolio of models, datasets, papers and demos I presented at ICCV Oct. 2023",
...     private=False,
...     theme="pink",
... )
>>> collection.slug
"username/iccv-oct-2023-64f9a55bb3115b4f513ec026"
# ^collection slug got updated but not the trailing ID
```

**update\_repo\_visibility**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L2794)

( repo\_id: strprivate: bool = Falsetoken: Optional\[str] = Noneorganization: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonename: Optional\[str] = None )

Parameters

* **repo\_id** (`str`, _optional_) — A namespace (user or an organization) and a repo name separated by a `/`.
* **private** (`bool`, _optional_, defaults to `False`) — Whether the model repo should be private.
* **token** (`str`, _optional_) — An authentication token (See [https://huggingface.co/settings/token](https://huggingface.co/settings/token))
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.

Update the visibility setting of a repository.

Raises the following errors:

* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.

**upload\_file**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L3625)

( path\_or\_fileobj: Union\[str, Path, bytes, BinaryIO]path\_in\_repo: strrepo\_id: strtoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecommit\_message: Optional\[str] = Nonecommit\_description: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Noneparent\_commit: Optional\[str] = Nonerun\_as\_future: bool = False ) → `str` or `Future`

Parameters

* **path\_or\_fileobj** (`str`, `Path`, `bytes`, or `IO`) — Path to a file on the local machine or binary data stream / fileobj / buffer.
* **path\_in\_repo** (`str`) — Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"`
* **repo\_id** (`str`) — The repository to which the file will be uploaded, for example: `"username/custom_transformers"`
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **commit\_message** (`str`, _optional_) — The summary / title / first line of the generated commit
* **commit\_description** (`str` _optional_) — The description of the generated commit
* **create\_pr** (`boolean`, _optional_) — Whether or not to create a Pull Request with that commit. Defaults to `False`. If `revision` is not set, PR is opened against the `"main"` branch. If `revision` is set and is a branch, PR is opened against this branch. If `revision` is set and is not a branch name (example: a commit oid), an `RevisionNotFoundError` is returned by the server.
* **parent\_commit** (`str`, _optional_) — The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`. If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`. Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.
* **run\_as\_future** (`bool`, _optional_) — Whether or not to run this method in the background. Background jobs are run sequentially without blocking the main thread. Passing `run_as_future=True` will return a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects) object. Defaults to `False`.

Returns

`str` or `Future`

The URL to visualize the uploaded file on the hub. If `run_as_future=True` is passed, returns a Future object which will contain the result when executed.

Upload a local file (up to 50 GB) to the given repo. The upload is done through a HTTP post request, and doesn’t require git or git-lfs to be installed.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid
* [RepositoryNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RepositoryNotFoundError) If the repository to download from cannot be found. This may be because it doesn’t exist, or because it is set to `private` and you do not have access.
* [RevisionNotFoundError](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/utilities#huggingface_hub.utils.RevisionNotFoundError) If the revision to download from cannot be found.

`upload_file` assumes that the repo already exists on the Hub. If you get a Client error 404, please make sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create it first using [create\_repo()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo).



Example:

Copied

```
>>> from huggingface_hub import upload_file

>>> with open("./local/filepath", "rb") as fobj:
...     upload_file(
...         path_or_fileobj=fileobj,
...         path_in_repo="remote/file/path.h5",
...         repo_id="username/my-dataset",
...         repo_type="dataset",
...         token="my_token",
...     )
"https://huggingface.co/datasets/username/my-dataset/blob/main/remote/file/path.h5"

>>> upload_file(
...     path_or_fileobj=".\\local\\file\\path",
...     path_in_repo="remote/file/path.h5",
...     repo_id="username/my-model",
...     token="my_token",
... )
"https://huggingface.co/username/my-model/blob/main/remote/file/path.h5"

>>> upload_file(
...     path_or_fileobj=".\\local\\file\\path",
...     path_in_repo="remote/file/path.h5",
...     repo_id="username/my-model",
...     token="my_token",
...     create_pr=True,
... )
"https://huggingface.co/username/my-model/blob/refs%2Fpr%2F1/remote/file/path.h5"
```

**upload\_folder**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L3827)

( repo\_id: strfolder\_path: Union\[str, Path]path\_in\_repo: Optional\[str] = Nonecommit\_message: Optional\[str] = Nonecommit\_description: Optional\[str] = Nonetoken: Optional\[str] = Nonerepo\_type: Optional\[str] = Nonerevision: Optional\[str] = Nonecreate\_pr: Optional\[bool] = Noneparent\_commit: Optional\[str] = Noneallow\_patterns: Optional\[Union\[List\[str], str]] = Noneignore\_patterns: Optional\[Union\[List\[str], str]] = Nonedelete\_patterns: Optional\[Union\[List\[str], str]] = Nonemulti\_commits: bool = Falsemulti\_commits\_verbose: bool = Falserun\_as\_future: bool = False ) → `str` or `Future[str]`

Parameters

* **repo\_id** (`str`) — The repository to which the file will be uploaded, for example: `"username/custom_transformers"`
* **folder\_path** (`str` or `Path`) — Path to the folder to upload on the local file system
* **path\_in\_repo** (`str`, _optional_) — Relative path of the directory in the repo, for example: `"checkpoints/1fec34a/results"`. Will default to the root folder of the repository.
* **token** (`str`, _optional_) — Authentication token, obtained with `HfApi.login` method. Will default to the stored token.
* **repo\_type** (`str`, _optional_) — Set to `"dataset"` or `"space"` if uploading to a dataset or space, `None` or `"model"` if uploading to a model. Default is `None`.
* **revision** (`str`, _optional_) — The git revision to commit from. Defaults to the head of the `"main"` branch.
* **commit\_message** (`str`, _optional_) — The summary / title / first line of the generated commit. Defaults to: `f"Upload {path_in_repo} with huggingface_hub"`
* **commit\_description** (`str` _optional_) — The description of the generated commit
* **create\_pr** (`boolean`, _optional_) — Whether or not to create a Pull Request with that commit. Defaults to `False`. If `revision` is not set, PR is opened against the `"main"` branch. If `revision` is set and is a branch, PR is opened against this branch. If `revision` is set and is not a branch name (example: a commit oid), an `RevisionNotFoundError` is returned by the server. If both `multi_commits` and `create_pr` are True, the PR created in the multi-commit process is kept opened.
* **parent\_commit** (`str`, _optional_) — The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported. If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`. If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`. Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be especially useful if the repo is updated / committed to concurrently.
* **allow\_patterns** (`List[str]` or `str`, _optional_) — If provided, only files matching at least one pattern are uploaded.
* **ignore\_patterns** (`List[str]` or `str`, _optional_) — If provided, files matching any of the patterns are not uploaded.
* **delete\_patterns** (`List[str]` or `str`, _optional_) — If provided, remote files matching any of the patterns will be deleted from the repo while committing new files. This is useful if you don’t know which files have already been uploaded. Note: to avoid discrepancies the `.gitattributes` file is not deleted even if it matches the pattern.
* **multi\_commits** (`bool`) — If True, changes are pushed to a PR using a multi-commit process. Defaults to `False`.
* **multi\_commits\_verbose** (`bool`) — If True and `multi_commits` is used, more information will be displayed to the user.
* **run\_as\_future** (`bool`, _optional_) — Whether or not to run this method in the background. Background jobs are run sequentially without blocking the main thread. Passing `run_as_future=True` will return a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects) object. Defaults to `False`.

Returns

`str` or `Future[str]`

A URL to visualize the uploaded folder on the hub. If `run_as_future=True` is passed, returns a Future object which will contain the result when executed.

Upload a local folder to the given repo. The upload is done through a HTTP requests, and doesn’t require git or git-lfs to be installed.

The structure of the folder will be preserved. Files with the same name already present in the repository will be overwritten. Others will be left untouched.

Use the `allow_patterns` and `ignore_patterns` arguments to specify which files to upload. These parameters accept either a single pattern or a list of patterns. Patterns are Standard Wildcards (globbing patterns) as documented [here](https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm). If both `allow_patterns` and `ignore_patterns` are provided, both constraints apply. By default, all files from the folder are uploaded.

Use the `delete_patterns` argument to specify remote files you want to delete. Input type is the same as for `allow_patterns` (see above). If `path_in_repo` is also provided, the patterns are matched against paths relative to this folder. For example, `upload_folder(..., path_in_repo="experiment", delete_patterns="logs/*")` will delete any remote file under `./experiment/logs/`. Note that the `.gitattributes` file will not be deleted even if it matches the patterns.

Any `.git/` folder present in any subdirectory will be ignored. However, please be aware that the `.gitignore` file is not taken into account.

Uses `HfApi.create_commit` under the hood.

Raises the following errors:

* [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError) if the HuggingFace API returned an error
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if some parameter value is invalid

`upload_folder` assumes that the repo already exists on the Hub. If you get a Client error 404, please make sure you are authenticated and that `repo_id` and `repo_type` are set correctly. If repo does not exist, create it first using [create\_repo()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo).

`multi_commits` is experimental. Its API and behavior is subject to change in the future without prior notice.



Example:

Copied

```
# Upload checkpoints folder except the log files
>>> upload_folder(
...     folder_path="local/checkpoints",
...     path_in_repo="remote/experiment/checkpoints",
...     repo_id="username/my-dataset",
...     repo_type="datasets",
...     token="my_token",
...     ignore_patterns="**/logs/*.txt",
... )
# "https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"

# Upload checkpoints folder including logs while deleting existing logs from the repo
# Useful if you don't know exactly which log files have already being pushed
>>> upload_folder(
...     folder_path="local/checkpoints",
...     path_in_repo="remote/experiment/checkpoints",
...     repo_id="username/my-dataset",
...     repo_type="datasets",
...     token="my_token",
...     delete_patterns="**/logs/*.txt",
... )
"https://huggingface.co/datasets/username/my-dataset/tree/main/remote/experiment/checkpoints"

# Upload checkpoints folder while creating a PR
>>> upload_folder(
...     folder_path="local/checkpoints",
...     path_in_repo="remote/experiment/checkpoints",
...     repo_id="username/my-dataset",
...     repo_type="datasets",
...     token="my_token",
...     create_pr=True,
... )
"https://huggingface.co/datasets/username/my-dataset/tree/refs%2Fpr%2F1/remote/experiment/checkpoints"
```

**whoami**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L1055)

( token: Optional\[str] = None )

Parameters

* **token** (`str`, _optional_) — Hugging Face token. Will default to the locally saved token if not provided.

Call HF API to know “whoami”.

**huggingface\_hub.plan\_multi\_commits**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_multi_commits.py#L77)

( operations: typing.Iterable\[typing.Union\[huggingface\_hub.\_commit\_api.CommitOperationAdd, huggingface\_hub.\_commit\_api.CommitOperationDelete]]max\_operations\_per\_commit: int = 50max\_upload\_size\_per\_commit: int = 2147483648 ) → `Tuple[List[List[CommitOperationAdd]], List[List[CommitOperationDelete]]]`

Parameters

* **operations** (`List` of `CommitOperation()`) — The list of operations to split into commits.
* **max\_operations\_per\_commit** (`int`) — Maximum number of operations in a single commit. Defaults to 50.
* **max\_upload\_size\_per\_commit** (`int`) — Maximum size to upload (in bytes) in a single commit. Defaults to 2GB. Files bigger than this limit are uploaded, 1 per commit.

Returns

`Tuple[List[List[CommitOperationAdd]], List[List[CommitOperationDelete]]]`

a tuple. First item is a list of lists of [CommitOperationAdd](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd) representing the addition commits to push. The second item is a list of lists of [CommitOperationDelete](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationDelete) representing the deletion commits.

Split a list of operations in a list of commits to perform.

Implementation follows a sub-optimal (yet simple) algorithm:

1. Delete operations are grouped together by commits of maximum `max_operations_per_commits` operations.
2. All additions exceeding `max_upload_size_per_commit` are committed 1 by 1.
3. All remaining additions are grouped together and split each time the `max_operations_per_commit` or the `max_upload_size_per_commit` limit is reached.

We do not try to optimize the splitting to get the lowest number of commits as this is a NP-hard problem (see [bin packing problem](https://en.wikipedia.org/wiki/Bin_packing_problem)). For our use case, it is not problematic to use a sub-optimal solution so we favored an easy-to-explain implementation.

`plan_multi_commits` is experimental. Its API and behavior is subject to change in the future without prior notice.



Example:

Copied

```
>>> from huggingface_hub import HfApi, plan_multi_commits
>>> addition_commits, deletion_commits = plan_multi_commits(
...     operations=[
...          CommitOperationAdd(...),
...          CommitOperationAdd(...),
...          CommitOperationDelete(...),
...          CommitOperationDelete(...),
...          CommitOperationAdd(...),
...     ],
... )
>>> HfApi().create_commits_on_pr(
...     repo_id="my-cool-model",
...     addition_commits=addition_commits,
...     deletion_commits=deletion_commits,
...     (...)
...     verbose=True,
... )
```

The initial order of the operations is not guaranteed! All deletions will be performed before additions. If you are not updating multiple times the same file, you are fine.

### API Dataclasses

#### CommitInfo

#### class huggingface\_hub.CommitInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L258)

( commit\_url: strcommit\_message: strcommit\_description: stroid: strpr\_url: Optional\[str] = None )

Parameters

* **commit\_url** (`str`) — Url where to find the commit.
* **commit\_message** (`str`) — The summary (first line) of the commit that has been created.
* **commit\_description** (`str`) — Description of the commit that has been created. Can be empty.
* **oid** (`str`) — Commit hash id. Example: `"91c54ad1727ee830252e457677f467be0bfd8a57"`.
* **pr\_url** (`str`, _optional_) — Url to the PR that has been created, if any. Populated when `create_pr=True` is passed.
* **pr\_revision** (`str`, _optional_) — Revision of the PR that has been created, if any. Populated when `create_pr=True` is passed. Example: `"refs/pr/1"`.
* **pr\_num** (`int`, _optional_) — Number of the PR discussion that has been created, if any. Populated when `create_pr=True` is passed. Can be passed as `discussion_num` in [get\_discussion\_details()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.get_discussion_details). Example: `1`.

Data structure containing information about a newly created commit.

Returned by [create\_commit()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit).

#### DatasetInfo

#### class huggingface\_hub.hf\_api.DatasetInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L477)

( id: Optional\[str] = Nonesha: Optional\[str] = NonelastModified: Optional\[str] = Nonetags: Optional\[List\[str]] = Nonesiblings: Optional\[List\[Dict]] = Noneprivate: bool = Falseauthor: Optional\[str] = Nonedescription: Optional\[str] = Nonecitation: Optional\[str] = NonecardData: Optional\[dict] = None\*\*kwargs )

Parameters

* **id** (`str`, _optional_) — ID of dataset repository.
* **sha** (`str`, _optional_) — repo sha at this particular revision
* **lastModified** (`str`, _optional_) — date of last commit to repo
* **tags** (`List[str]`, _optional_) — List of tags.
* **siblings** (`List[RepoFile]`, _optional_) — list of [huggingface\_hub.hf\_api.RepoFile](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.RepoFile) objects that constitute the dataset.
* **private** (`bool`, _optional_, defaults to `False`) — is the repo private
* **author** (`str`, _optional_) — repo author
* **description** (`str`, _optional_) — Description of the dataset
* **citation** (`str`, _optional_) — Dataset citation
* **cardData** (`Dict`, _optional_) — Metadata of the model card as a dictionary.
* **kwargs** (`Dict`, _optional_) — Kwargs that will be become attributes of the class.

Info about a dataset accessible from huggingface.co

#### GitRefInfo

#### class huggingface\_hub.GitRefInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L806)

( data: Dict )

Parameters

* **name** (`str`) — Name of the reference (e.g. tag name or branch name).
* **ref** (`str`) — Full git ref on the Hub (e.g. `"refs/heads/main"` or `"refs/tags/v1.0"`).
* **target\_commit** (`str`) — OID of the target commit for the ref (e.g. `"e7da7f221d5bf496a48136c0cd264e630fe9fcc8"`)

Contains information about a git reference for a repo on the Hub.

#### GitCommitInfo

#### class huggingface\_hub.GitCommitInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L852)

( data: Dict )

Parameters

* **commit\_id** (`str`) — OID of the commit (e.g. `"e7da7f221d5bf496a48136c0cd264e630fe9fcc8"`)
* **authors** (`List[str]`) — List of authors of the commit.
* **created\_at** (`datetime`) — Datetime when the commit was created.
* **title** (`str`) — Title of the commit. This is a free-text value entered by the authors.
* **message** (`str`) — Description of the commit. This is a free-text value entered by the authors.
* **formatted\_title** (`str`) — Title of the commit formatted as HTML. Only returned if `formatted=True` is set.
* **formatted\_message** (`str`) — Description of the commit formatted as HTML. Only returned if `formatted=True` is set.

Contains information about a git commit for a repo on the Hub. Check out [list\_repo\_commits()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_repo_commits) for more details.

#### GitRefs

#### class huggingface\_hub.GitRefs

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L830)

( branches: List\[GitRefInfo]converts: List\[GitRefInfo]tags: List\[GitRefInfo] )

Parameters

* **branches** (`List[GitRefInfo]`) — A list of [GitRefInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitRefInfo) containing information about branches on the repo.
* **converts** (`List[GitRefInfo]`) — A list of [GitRefInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitRefInfo) containing information about “convert” refs on the repo. Converts are refs used (internally) to push preprocessed data in Dataset repos.
* **tags** (`List[GitRefInfo]`) — A list of [GitRefInfo](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.GitRefInfo) containing information about tags on the repo.

Contains information about all git references for a repo on the Hub.

Object is returned by [list\_repo\_refs()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.list_repo_refs).

#### ModelInfo

#### class huggingface\_hub.hf\_api.ModelInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L411)

( modelId: Optional\[str] = Nonesha: Optional\[str] = NonelastModified: Optional\[str] = Nonetags: Optional\[List\[str]] = Nonepipeline\_tag: Optional\[str] = Nonesiblings: Optional\[List\[Dict]] = Noneprivate: bool = Falseauthor: Optional\[str] = Noneconfig: Optional\[Dict] = NonesecurityStatus: Optional\[Dict] = None\*\*kwargs )

Parameters

* **modelId** (`str`, _optional_) — ID of model repository.
* **sha** (`str`, _optional_) — repo sha at this particular revision
* **lastModified** (`str`, _optional_) — date of last commit to repo
* **tags** (`List[str]`, _optional_) — List of tags.
* **pipeline\_tag** (`str`, _optional_) — Pipeline tag to identify the correct widget.
* **siblings** (`List[RepoFile]`, _optional_) — list of ([huggingface\_hub.hf\_api.RepoFile](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.hf_api.RepoFile)) objects that constitute the model.
* **private** (`bool`, _optional_, defaults to `False`) — is the repo private
* **author** (`str`, _optional_) — repo author
* **config** (`Dict`, _optional_) — Model configuration information
* **securityStatus** (`Dict`, _optional_) — Security status of the model. Example: `{"containsInfected": False}`
* **kwargs** (`Dict`, _optional_) — Kwargs that will be become attributes of the class.

Info about a model accessible from huggingface.co

#### RepoFile

#### class huggingface\_hub.hf\_api.RepoFile

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L373)

( rfilename: strsize: Optional\[int] = NoneblobId: Optional\[str] = Nonelfs: Optional\[BlobLfsInfo] = None\*\*kwargs )

Parameters

* **rfilename** (str) — file name, relative to the repo root. This is the only attribute that’s guaranteed to be here, but under certain conditions there can certain other stuff.
* **size** (`int`, _optional_) — The file’s size, in bytes. This attribute is present when `files_metadata` argument of [repo\_info()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.repo_info) is set to `True`. It’s `None` otherwise.
* **blob\_id** (`str`, _optional_) — The file’s git OID. This attribute is present when `files_metadata` argument of [repo\_info()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.repo_info) is set to `True`. It’s `None` otherwise.
* **lfs** (`BlobLfsInfo`, _optional_) — The file’s LFS metadata. This attribute is present when`files_metadata` argument of [repo\_info()](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.repo_info) is set to `True` and the file is stored with Git LFS. It’s `None` otherwise.

Data structure that represents a public file inside a repo, accessible from huggingface.co

#### RepoUrl

#### class huggingface\_hub.RepoUrl

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L313)

( url: Anyendpoint: Optional\[str] = None )

Parameters

* **url** (`Any`) — String value of the repo url.
* **endpoint** (`str`, _optional_) — Endpoint of the Hub. Defaults to [https://huggingface.co](https://huggingface.co/).

Raises

*
*
  * — [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) If URL cannot be parsed.
*
  * — [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) If `repo_type` is unknown.

Subclass of `str` describing a repo URL on the Hub.

`RepoUrl` is returned by `HfApi.create_repo`. It inherits from `str` for backward compatibility. At initialization, the URL is parsed to populate properties:

* endpoint (`str`)
* namespace (`Optional[str]`)
* repo\_name (`str`)
* repo\_id (`str`)
* repo\_type (`Literal["model", "dataset", "space"]`)
* url (`str`)



Example:

Copied

```
>>> RepoUrl('https://huggingface.co/gpt2')
RepoUrl('https://huggingface.co/gpt2', endpoint='https://huggingface.co', repo_type='model', repo_id='gpt2')

>>> RepoUrl('https://hub-ci.huggingface.co/datasets/dummy_user/dummy_dataset', endpoint='https://hub-ci.huggingface.co')
RepoUrl('https://hub-ci.huggingface.co/datasets/dummy_user/dummy_dataset', endpoint='https://hub-ci.huggingface.co', repo_type='dataset', repo_id='dummy_user/dummy_dataset')

>>> RepoUrl('hf://datasets/my-user/my-dataset')
RepoUrl('hf://datasets/my-user/my-dataset', endpoint='https://huggingface.co', repo_type='dataset', repo_id='user/dataset')

>>> HfApi.create_repo("dummy_model")
RepoUrl('https://huggingface.co/Wauplin/dummy_model', endpoint='https://huggingface.co', repo_type='model', repo_id='Wauplin/dummy_model')
```

#### SpaceInfo

#### class huggingface\_hub.hf\_api.SpaceInfo

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L542)

( id: Optional\[str] = Nonesha: Optional\[str] = NonelastModified: Optional\[str] = Nonesiblings: Optional\[List\[Dict]] = Noneprivate: bool = Falseauthor: Optional\[str] = None\*\*kwargs )

Parameters

* **id** (`str`, _optional_) — id of space
* **sha** (`str`, _optional_) — repo sha at this particular revision
* **lastModified** (`str`, _optional_) — date of last commit to repo
* **siblings** (`List[RepoFile]`, _optional_) — list of `huggingface_hub.hf_api.RepoFIle` objects that constitute the Space
* **private** (`bool`, _optional_, defaults to `False`) — is the repo private
* **author** (`str`, _optional_) — repo author
* **kwargs** (`Dict`, _optional_) — Kwargs that will be become attributes of the class.

Info about a Space accessible from huggingface.co

This is a “dataclass” like container that just sets on itself any attribute passed by the server.

#### User

#### class huggingface\_hub.User

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L923)

( avatar\_url: strusername: strfullname: str )

Parameters

* **avatar\_url** (`str`) — URL of the user’s avatar.
* **username** (`str`) — Name of the user on the Hub (unique).
* **fullname** (`str`) — User’s full name.

Contains information about a user on the Hub.

#### UserLikes

#### class huggingface\_hub.UserLikes

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L895)

( user: strtotal: intdatasets: List\[str]models: List\[str]spaces: List\[str] )

Parameters

* **user** (`str`) — Name of the user for which we fetched the likes.
* **total** (`int`) — Total number of likes.
* **datasets** (`List[str]`) — List of datasets liked by the user (as repo\_ids).
* **models** (`List[str]`) — List of models liked by the user (as repo\_ids).
* **spaces** (`List[str]`) — List of spaces liked by the user (as repo\_ids).

Contains information about a user likes on the Hub.

### CommitOperation

Below are the supported values for `CommitOperation()`:

#### class huggingface\_hub.CommitOperationAdd

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_api.py#L111)

( path\_in\_repo: strpath\_or\_fileobj: typing.Union\[str, pathlib.Path, bytes, typing.BinaryIO] )

Parameters

* **path\_in\_repo** (`str`) — Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"`
* **path\_or\_fileobj** (`str`, `Path`, `bytes`, or `BinaryIO`) — Either:
  * a path to a local file (as `str` or `pathlib.Path`) to upload
  * a buffer of bytes (`bytes`) holding the content of the file to upload
  * a “file object” (subclass of `io.BufferedIOBase`), typically obtained with `open(path, "rb")`. It must support `seek()` and `tell()` methods.

Raises

`ValueError`

* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If `path_or_fileobj` is not one of `str`, `Path`, `bytes` or `io.BufferedIOBase`.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If `path_or_fileobj` is a `str` or `Path` but not a path to an existing file.
* [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) — If `path_or_fileobj` is a `io.BufferedIOBase` but it doesn’t support both `seek()` and `tell()`.

Data structure holding necessary info to upload a file to a repository on the Hub.

**as\_file**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_api.py#L183)

( with\_tqdm: bool = False )

Parameters

* **with\_tqdm** (`bool`, _optional_, defaults to `False`) — If True, iterating over the file object will display a progress bar. Only works if the file-like object is a path to a file. Pure bytes and buffers are not supported.

A context manager that yields a file-like object allowing to read the underlying data behind `path_or_fileobj`.



Example:

Copied

```
>>> operation = CommitOperationAdd(
...        path_in_repo="remote/dir/weights.h5",
...        path_or_fileobj="./local/weights.h5",
... )
CommitOperationAdd(path_in_repo='remote/dir/weights.h5', path_or_fileobj='./local/weights.h5')

>>> with operation.as_file() as file:
...     content = file.read()

>>> with operation.as_file(with_tqdm=True) as file:
...     while True:
...         data = file.read(1024)
...         if not data:
...              break
config.json: 100%|█████████████████████████| 8.19k/8.19k [00:02<00:00, 3.72kB/s]

>>> with operation.as_file(with_tqdm=True) as file:
...     requests.put(..., data=file)
config.json: 100%|█████████████████████████| 8.19k/8.19k [00:02<00:00, 3.72kB/s]
```

**b64content**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_api.py#L233)

( )

The base64-encoded content of `path_or_fileobj`

Returns: `bytes`

#### class huggingface\_hub.CommitOperationDelete

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_api.py#L50)

( path\_in\_repo: stris\_folder: typing.Union\[bool, typing.Literal\['auto']] = 'auto' )

Parameters

* **path\_in\_repo** (`str`) — Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"` for a file or `"checkpoints/1fec34a/"` for a folder.
* **is\_folder** (`bool` or `Literal["auto"]`, _optional_) — Whether the Delete Operation applies to a folder or not. If “auto”, the path type (file or folder) is guessed automatically by looking if path ends with a ”/” (folder) or not (file). To explicitly set the path type, you can set `is_folder=True` or `is_folder=False`.

Data structure holding necessary info to delete a file or a folder from a repository on the Hub.

#### class huggingface\_hub.CommitOperationCopy

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_api.py#L81)

( src\_path\_in\_repo: strpath\_in\_repo: strsrc\_revision: typing.Optional\[str] = None )

Parameters

* **src\_path\_in\_repo** (`str`) — Relative filepath in the repo of the file to be copied, e.g. `"checkpoints/1fec34a/weights.bin"`.
* **path\_in\_repo** (`str`) — Relative filepath in the repo where to copy the file, e.g. `"checkpoints/1fec34a/weights_copy.bin"`.
* **src\_revision** (`str`, _optional_) — The git revision of the file to be copied. Can be any valid git revision. Default to the target commit revision.

Data structure holding necessary info to copy a file in a repository on the Hub.

Limitations:

* Only LFS files can be copied. To copy a regular file, you need to download it locally and re-upload it
* Cross-repository copies are not supported.

Note: you can combine a [CommitOperationCopy](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationCopy) and a [CommitOperationDelete](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationDelete) to rename an LFS file on the Hub.

### CommitScheduler

#### class huggingface\_hub.CommitScheduler

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_scheduler.py#L29)

( repo\_id: strfolder\_path: typing.Union\[str, pathlib.Path]every: typing.Union\[int, float] = 5path\_in\_repo: typing.Optional\[str] = Nonerepo\_type: typing.Optional\[str] = Nonerevision: typing.Optional\[str] = Noneprivate: bool = Falsetoken: typing.Optional\[str] = Noneallow\_patterns: typing.Union\[typing.List\[str], str, NoneType] = Noneignore\_patterns: typing.Union\[typing.List\[str], str, NoneType] = Nonesquash\_history: bool = Falsehf\_api: typing.Optional\[ForwardRef('HfApi')] = None )

Parameters

* **repo\_id** (`str`) — The id of the repo to commit to.
* **folder\_path** (`str` or `Path`) — Path to the local folder to upload regularly.
* **every** (`int` or `float`, _optional_) — The number of minutes between each commit. Defaults to 5 minutes.
* **path\_in\_repo** (`str`, _optional_) — Relative path of the directory in the repo, for example: `"checkpoints/"`. Defaults to the root folder of the repository.
* **repo\_type** (`str`, _optional_) — The type of the repo to commit to. Defaults to `model`.
* **revision** (`str`, _optional_) — The revision of the repo to commit to. Defaults to `main`.
* **private** (`bool`, _optional_) — Whether to make the repo private. Defaults to `False`. This value is ignored if the repo already exist.
* **token** (`str`, _optional_) — The token to use to commit to the repo. Defaults to the token saved on the machine.
* **allow\_patterns** (`List[str]` or `str`, _optional_) — If provided, only files matching at least one pattern are uploaded.
* **ignore\_patterns** (`List[str]` or `str`, _optional_) — If provided, files matching any of the patterns are not uploaded.
* **squash\_history** (`bool`, _optional_) — Whether to squash the history of the repo after each commit. Defaults to `False`. Squashing commits is useful to avoid degraded performances on the repo when it grows too large.
* **hf\_api** (`HfApi`, _optional_) — The [HfApi](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi) client to use to commit to the Hub. Can be set with custom settings (user agent, token,…).

Scheduler to upload a local folder to the Hub at regular intervals (e.g. push to hub every 5 minutes).

The scheduler is started when instantiated and run indefinitely. At the end of your script, a last commit is triggered. Checkout the [upload guide](https://huggingface.co/docs/huggingface_hub/guides/upload#scheduled-uploads) to learn more about how to use it.



Example:

Copied

```
>>> from pathlib import Path
>>> from huggingface_hub import CommitScheduler

# Scheduler uploads every 10 minutes
>>> csv_path = Path("watched_folder/data.csv")
>>> CommitScheduler(repo_id="test_scheduler", repo_type="dataset", folder_path=csv_path.parent, every=10)

>>> with csv_path.open("a") as f:
...     f.write("first line")

# Some time later (...)
>>> with csv_path.open("a") as f:
...     f.write("second line")
```

**push\_to\_hub**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_scheduler.py#L178)

( )

Push folder to the Hub and return the commit info.

This method is not meant to be called directly. It is run in the background by the scheduler, respecting a queue mechanism to avoid concurrent commits. Making a direct call to the method might lead to concurrency issues.

The default behavior of `push_to_hub` is to assume an append-only folder. It lists all files in the folder and uploads only changed files. If no changes are found, the method returns without committing anything. If you want to change this behavior, you can inherit from [CommitScheduler](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler) and override this method. This can be useful for example to compress data together in a single file before committing. For more details and examples, check out our [integration guide](https://huggingface.co/docs/huggingface_hub/main/en/guides/upload#scheduled-uploads).

**stop**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_scheduler.py#L140)

( )

Stop the scheduler.

A stopped scheduler cannot be restarted. Mostly for tests purposes.

**trigger**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/_commit_scheduler.py#L155)

( )

Trigger a `push_to_hub` and return a future.

This method is automatically called every `every` minutes. You can also call it manually to trigger a commit immediately, without waiting for the next scheduled commit.

### Token helper

`huggingface_hub` stores the authentication information locally so that it may be re-used in subsequent methods.

It does this using the [HfFolder](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfFolder) utility, which saves data at the root of the user.

#### class huggingface\_hub.HfFolder

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/_hf_folder.py#L24)

( )

**delete\_token**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/_hf_folder.py#L79)

( )

Deletes the token from storage. Does not fail if token does not exist.

**get\_token**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/_hf_folder.py#L44)

( ) → `str` or `None`

Returns

`str` or `None`

The token, `None` if it doesn’t exist.

Get token or None if not existent.

Note that a token can be also provided using the `HUGGING_FACE_HUB_TOKEN` environment variable.

Token is saved in the huggingface home folder. You can configure it by setting the `HF_HOME` environment variable. Previous location was `~/.huggingface/token`. If token is found in old location but not in new location, it is copied there first. For more details, see [https://github.com/huggingface/huggingface\_hub/issues/1232](https://github.com/huggingface/huggingface_hub/issues/1232).

**save\_token**

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/_hf_folder.py#L29)

( token: str )

Parameters

* **token** (`str`) — The token to save to the [HfFolder](https://huggingface.co/docs/huggingface_hub/v0.18.0.rc0/en/package_reference/hf_api#huggingface_hub.HfFolder)

Save token, creating folder as needed.

Token is saved in the huggingface home folder. You can configure it by setting the `HF_HOME` environment variable.

### Search helpers

Some helpers to filter repositories on the Hub are available in the `huggingface_hub` package.

#### DatasetFilter

#### class huggingface\_hub.DatasetFilter

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/endpoint_helpers.py#L71)

( author: typing.Optional\[str] = Nonebenchmark: typing.Union\[typing.List\[str], str, NoneType] = Nonedataset\_name: typing.Optional\[str] = Nonelanguage\_creators: typing.Union\[typing.List\[str], str, NoneType] = Nonelanguage: typing.Union\[typing.List\[str], str, NoneType] = Nonemultilinguality: typing.Union\[typing.List\[str], str, NoneType] = Nonesize\_categories: typing.Union\[typing.List\[str], str, NoneType] = Nonetask\_categories: typing.Union\[typing.List\[str], str, NoneType] = Nonetask\_ids: typing.Union\[typing.List\[str], str, NoneType] = None )

Parameters

* **author** (`str`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by the original uploader (author or organization), such as `facebook` or `huggingface`.
* **benchmark** (`str` or `List`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by their official benchmark.
* **dataset\_name** (`str`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by its name, such as `SQAC` or `wikineural`
* **language\_creators** (`str` or `List`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub with how the data was curated, such as `crowdsourced` or `machine_generated`.
* **language** (`str` or `List`, _optional_) — A string or list of strings representing a two-character language to filter datasets by on the Hub.
* **multilinguality** (`str` or `List`, _optional_) — A string or list of strings representing a filter for datasets that contain multiple languages.
* **size\_categories** (`str` or `List`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by the size of the dataset such as `100K<n<1M` or `1M<n<10M`.
* **task\_categories** (`str` or `List`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by the designed task, such as `audio_classification` or `named_entity_recognition`.
* **task\_ids** (`str` or `List`, _optional_) — A string or list of strings that can be used to identify datasets on the Hub by the specific task such as `speech_emotion_recognition` or `paraphrase`.

A class that converts human-readable dataset search parameters into ones compatible with the REST API. For all parameters capitalization does not matter.



Examples:

Copied

```
>>> from huggingface_hub import DatasetFilter

>>> # Using author
>>> new_filter = DatasetFilter(author="facebook")

>>> # Using benchmark
>>> new_filter = DatasetFilter(benchmark="raft")

>>> # Using dataset_name
>>> new_filter = DatasetFilter(dataset_name="wikineural")

>>> # Using language_creator
>>> new_filter = DatasetFilter(language_creator="crowdsourced")

>>> # Using language
>>> new_filter = DatasetFilter(language="en")

>>> # Using multilinguality
>>> new_filter = DatasetFilter(multilinguality="multilingual")

>>> # Using size_categories
>>> new_filter = DatasetFilter(size_categories="100K<n<1M")

>>> # Using task_categories
>>> new_filter = DatasetFilter(task_categories="audio_classification")

>>> # Using task_ids
>>> new_filter = DatasetFilter(task_ids="paraphrase")
```

#### ModelFilter

#### class huggingface\_hub.ModelFilter

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/utils/endpoint_helpers.py#L157)

( author: typing.Optional\[str] = Nonelibrary: typing.Union\[typing.List\[str], str, NoneType] = Nonelanguage: typing.Union\[typing.List\[str], str, NoneType] = Nonemodel\_name: typing.Optional\[str] = Nonetask: typing.Union\[typing.List\[str], str, NoneType] = Nonetrained\_dataset: typing.Union\[typing.List\[str], str, NoneType] = Nonetags: typing.Union\[typing.List\[str], str, NoneType] = None )

Parameters

* **author** (`str`, _optional_) — A string that can be used to identify models on the Hub by the original uploader (author or organization), such as `facebook` or `huggingface`.
* **library** (`str` or `List`, _optional_) — A string or list of strings of foundational libraries models were originally trained from, such as pytorch, tensorflow, or allennlp.
* **language** (`str` or `List`, _optional_) — A string or list of strings of languages, both by name and country code, such as “en” or “English”
* **model\_name** (`str`, _optional_) — A string that contain complete or partial names for models on the Hub, such as “bert” or “bert-base-cased”
* **task** (`str` or `List`, _optional_) — A string or list of strings of tasks models were designed for, such as: “fill-mask” or “automatic-speech-recognition”
* **tags** (`str` or `List`, _optional_) — A string tag or a list of tags to filter models on the Hub by, such as `text-generation` or `spacy`.
* **trained\_dataset** (`str` or `List`, _optional_) — A string tag or a list of string tags of the trained dataset for a model on the Hub.

A class that converts human-readable model search parameters into ones compatible with the REST API. For all parameters capitalization does not matter.

Copied

```
>>> from huggingface_hub import ModelFilter

>>> # For the author_or_organization
>>> new_filter = ModelFilter(author_or_organization="facebook")

>>> # For the library
>>> new_filter = ModelFilter(library="pytorch")

>>> # For the language
>>> new_filter = ModelFilter(language="french")

>>> # For the model_name
>>> new_filter = ModelFilter(model_name="bert")

>>> # For the task
>>> new_filter = ModelFilter(task="text-classification")

>>> # Retrieving tags using the `HfApi.get_model_tags` method
>>> from huggingface_hub import HfApi

>>> api = HfApi()
# To list model tags

>>> api.get_model_tags()
# To list dataset tags

>>> api.get_dataset_tags()
>>> new_filter = ModelFilter(tags="benchmark:raft")

>>> # Related to the dataset
>>> new_filter = ModelFilter(trained_dataset="common_voice")
```

#### DatasetSearchArguments

#### class huggingface\_hub.DatasetSearchArguments

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L755)

( api: Optional\['HfApi'] = None )

A nested namespace object holding all possible values for properties of datasets currently hosted in the Hub with tab-completion. If a value starts with a number, it will only exist in the dictionary



Example:

Copied

```
>>> args = DatasetSearchArguments()

>>> args.author.huggingface
'huggingface'

>>> args.language.en
'language:en'
```

`DatasetSearchArguments` is a legacy class meant for exploratory purposes only. Its initialization requires listing all datasets on the Hub which makes it increasingly slower as the number of repos on the Hub increases.

#### ModelSearchArguments

#### class huggingface\_hub.ModelSearchArguments

[\<source>](https://github.com/huggingface/huggingface_hub/blob/v0.18.0.rc0/src/huggingface_hub/hf_api.py#L705)

( api: Optional\['HfApi'] = None )

A nested namespace object holding all possible values for properties of models currently hosted in the Hub with tab-completion. If a value starts with a number, it will only exist in the dictionary



Example:

Copied

```
>>> args = ModelSearchArguments()

>>> args.author.huggingface
'huggingface'

>>> args.language.en
'en'
```

`ModelSearchArguments` is a legacy class meant for exploratory purposes only. Its initialization requires listing all models on the Hub which makes it increasingly slower as the number of repos on the Hub increases.
