Repository creation, deletion, branch management, and commit history.
Summary
Functions
Checks if the given token has access to a repository.
Counts total commits on a branch. See HuggingfaceClient.count_commits/2.
Creates a repository. See HuggingfaceClient.create_repo/2.
Creates a branch. See HuggingfaceClient.create_branch/3.
Deletes a repository. See HuggingfaceClient.delete_repo/2.
Deletes a branch. See HuggingfaceClient.delete_branch/3.
Checks if a repository exists. See HuggingfaceClient.repo_exists/2.
Likes a repository on the Hub.
Returns a lazy stream of commits. See HuggingfaceClient.list_commits/2.
Lists repos liked by a user.
Gets the list of logs from a Space (for debugging).
Renames a repository or transfers it to a new namespace.
Gets repository settings (gating, private, SDK for spaces, etc.).
Squashes all commits in a repo into a single commit (history-destructive).
Tags a specific commit (lightweight tag without a message).
Unlikes a repository on the Hub.
Updates repository settings (visibility, gating, etc.).
Uploads a local folder's content to a repository.
Functions
@spec auth_check( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Checks if the given token has access to a repository.
Returns :ok if access is granted, or raises an appropriate error.
Options
:write— iftrue, check for write access (default: false = read access):type— repo type (default::model):access_token
Example
case HuggingfaceClient.auth_check("meta-llama/Llama-3.1-8B", access_token: "hf_...") do
:ok -> IO.puts("Access granted!")
{:error, reason} -> IO.puts("No access: #{Exception.message(reason)}")
end
@spec count_commits( String.t(), keyword() ) :: {:ok, non_neg_integer()} | {:error, Exception.t()}
Counts total commits on a branch. See HuggingfaceClient.count_commits/2.
@spec create( String.t(), keyword() ) :: {:ok, map()} | {:error, Exception.t()}
Creates a repository. See HuggingfaceClient.create_repo/2.
@spec create_branch(String.t(), String.t(), keyword()) :: :ok | {:error, Exception.t()}
Creates a branch. See HuggingfaceClient.create_branch/3.
@spec delete( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Deletes a repository. See HuggingfaceClient.delete_repo/2.
@spec delete_branch(String.t(), String.t(), keyword()) :: :ok | {:error, Exception.t()}
Deletes a branch. See HuggingfaceClient.delete_branch/3.
@spec exists?( String.t(), keyword() ) :: {:ok, boolean()} | {:error, Exception.t()}
Checks if a repository exists. See HuggingfaceClient.repo_exists/2.
@spec like( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Likes a repository on the Hub.
Example
:ok = HuggingfaceClient.Hub.Repos.like("gpt2", access_token: token)
@spec list_commits( String.t(), keyword() ) :: Enumerable.t()
Returns a lazy stream of commits. See HuggingfaceClient.list_commits/2.
@spec list_liked_repos(keyword()) :: {:ok, [map()]} | {:error, Exception.t()}
Lists repos liked by a user.
Options
:user— username (defaults to authenticated user):type—"model","dataset","space"(default: all types):access_token
Example
{:ok, liked} = HuggingfaceClient.Hub.Repos.list_liked_repos(
user: "yann-lecun", access_token: token
)
@spec list_space_logs( String.t(), keyword() ) :: {:ok, [map()]} | {:error, Exception.t()}
Gets the list of logs from a Space (for debugging).
Example
{:ok, logs} = HuggingfaceClient.Hub.Repos.list_space_logs("my-org/my-space",
access_token: token
)
@spec move(keyword()) :: {:ok, String.t()} | {:error, Exception.t()}
Renames a repository or transfers it to a new namespace.
Options
:from_id— current repo ID (e.g."old-user/old-name") (required):to_id— new repo ID (e.g."org/new-name") (required):type— repo type (default::model):access_token
Example
{:ok, url} = HuggingfaceClient.move_repo(
from_id: "my-user/old-model",
to_id: "my-org/new-model",
access_token: "hf_..."
)
@spec settings( String.t(), keyword() ) :: {:ok, map()} | {:error, Exception.t()}
Gets repository settings (gating, private, SDK for spaces, etc.).
Example
{:ok, settings} = HuggingfaceClient.Hub.Repos.settings("my-model",
access_token: token
)
IO.puts("Private: #{settings["private"]}")
IO.puts("Gated: #{settings["gated"]}")
@spec super_squash_history( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Squashes all commits in a repo into a single commit (history-destructive).
Useful for cleaning up a repo's commit history before releasing. Requires admin access.
Example
:ok = HuggingfaceClient.Hub.Repos.super_squash_history("my-org/my-model",
branch: "main", access_token: token
)
@spec tag_commit( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Tags a specific commit (lightweight tag without a message).
Options
:tag— tag name (required):commit— commit SHA to tag (default: HEAD):type— repo type:access_token
Example
:ok = HuggingfaceClient.Hub.Repos.tag_commit("my-model",
tag: "v1.0.0-checkpoint-500",
commit: "abc123def456",
access_token: token
)
@spec unlike( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Unlikes a repository on the Hub.
Example
:ok = HuggingfaceClient.Hub.Repos.unlike("gpt2", access_token: token)
@spec update_settings( String.t(), keyword() ) :: :ok | {:error, Exception.t()}
Updates repository settings (visibility, gating, etc.).
Options
:private—trueto make private,falsefor public:gated—"auto","manual", orfalseto disable gating:type— repo type (default::model):access_token
Example
:ok = HuggingfaceClient.update_repo_settings("my-org/my-model",
private: true,
gated: "auto",
access_token: "hf_..."
)
@spec upload_folder( String.t(), keyword() ) :: {:ok, map()} | {:error, Exception.t()}
Uploads a local folder's content to a repository.
Walks the directory tree and uploads all files in a single commit.
Options
:folder_path— local directory to upload (required):path_in_repo— target path prefix in the repo (default: root""):allow_patterns— glob pattern(s) to include (e.g."*.json"):ignore_patterns— glob pattern(s) to exclude:commit_message— commit message:branch— target branch (default:"main"):create_pr— iftrue, open as pull request:type— repo type:access_token
Example
{:ok, commit} = HuggingfaceClient.upload_folder("my-org/my-model",
folder_path: "./model_outputs",
path_in_repo: "checkpoints/step-1000",
ignore_patterns: ["*.log", "__pycache__/**"],
access_token: "hf_..."
)