hfutils.repository.url

This module provides functions for generating URLs related to Hugging Face Hub repositories.

It includes functions to create URLs for repository paths and files, which can be useful for accessing and referencing resources within Hugging Face Hub repositories.

hf_hub_repo_path_url

hfutils.repository.url.hf_hub_repo_path_url(repo_id: str, path: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', endpoint: str | None = None) str[source]

Generate the URL for a path within a Hugging Face Hub repository.

This function constructs a URL that points to a specific path within a Hugging Face Hub repository. It’s useful for creating links to directories or files in the repository’s web interface.

Parameters:
  • repo_id (str) – The repository ID (e.g., ‘username/repo-name’).

  • path (str) – The path within the repository to generate the URL for.

  • repo_type (RepoTypeTyping, optional) – The type of the repository. Defaults to ‘dataset’.

  • revision (str, optional) – The revision (branch, tag, or commit) to use. Defaults to ‘main’.

  • endpoint (str, optional) – The API endpoint to use. If None, the default endpoint will be used.

Returns:

The URL for the specified path in the Hugging Face Hub repository.

Return type:

str

Example:
>>> url = hf_hub_repo_path_url('username/my-dataset', 'data/train.csv')
>>> print(url)
https://huggingface.co/datasets/username/my-dataset/tree/main/data/train.csv

hf_hub_repo_file_url

hfutils.repository.url.hf_hub_repo_file_url(repo_id: str, path: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', endpoint: str | None = None) str[source]

Generate the URL for a file within a Hugging Face Hub repository.

This function constructs a URL that points to a specific file within a Hugging Face Hub repository. It’s useful for creating links to view files in the repository’s web interface.

Parameters:
  • repo_id (str) – The repository ID (e.g., ‘username/repo-name’).

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

  • repo_type (RepoTypeTyping, optional) – The type of the repository. Defaults to ‘dataset’.

  • revision (str, optional) – The revision (branch, tag, or commit) to use. Defaults to ‘main’.

  • endpoint (str, optional) – The API endpoint to use. If None, the default endpoint will be used.

Returns:

The URL for the specified file in the Hugging Face Hub repository.

Return type:

str

Example:
>>> url = hf_hub_repo_file_url('username/my-model', 'config.json')
>>> print(url)
https://huggingface.co/username/my-model/blob/main/config.json

Note

This is not the downloadable URL of the file in the repository. For downloading URLs, use huggingface_hub.hf_hub_url().