HuggingfaceClient.Hub.Repositories.Repos (huggingface_client v0.1.0)

Copy Markdown View Source

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

auth_check(repo, opts \\ [])

@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 — if true, 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

count_commits(repo, opts)

@spec count_commits(
  String.t(),
  keyword()
) :: {:ok, non_neg_integer()} | {:error, Exception.t()}

Counts total commits on a branch. See HuggingfaceClient.count_commits/2.

create(name, opts)

@spec create(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, Exception.t()}

Creates a repository. See HuggingfaceClient.create_repo/2.

create_branch(repo, branch, opts)

@spec create_branch(String.t(), String.t(), keyword()) ::
  :ok | {:error, Exception.t()}

Creates a branch. See HuggingfaceClient.create_branch/3.

delete(name, opts)

@spec delete(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}

Deletes a repository. See HuggingfaceClient.delete_repo/2.

delete_branch(repo, branch, opts)

@spec delete_branch(String.t(), String.t(), keyword()) ::
  :ok | {:error, Exception.t()}

Deletes a branch. See HuggingfaceClient.delete_branch/3.

exists?(name, opts)

@spec exists?(
  String.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Exception.t()}

Checks if a repository exists. See HuggingfaceClient.repo_exists/2.

like(repo_id, opts \\ [])

@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)

list_commits(repo, opts)

@spec list_commits(
  String.t(),
  keyword()
) :: Enumerable.t()

Returns a lazy stream of commits. See HuggingfaceClient.list_commits/2.

list_liked_repos(opts \\ [])

@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
)

list_space_logs(space_id, opts \\ [])

@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
)

move(opts \\ [])

@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_..."
)

settings(repo_id, opts \\ [])

@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"]}")

super_squash_history(repo_id, opts \\ [])

@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
)

tag_commit(repo_id, opts)

@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
)

unlike(repo_id, opts \\ [])

@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)

update_settings(repo, opts \\ [])

@spec update_settings(
  String.t(),
  keyword()
) :: :ok | {:error, Exception.t()}

Updates repository settings (visibility, gating, etc.).

Options

  • :privatetrue to make private, false for public
  • :gated"auto", "manual", or false to 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_..."
)

upload_folder(repo, opts \\ [])

@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 — if true, 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_..."
)