HuggingfaceClient.Config (huggingface_client v0.1.0)

Copy Markdown View Source

HuggingFace Client configuration and environment variable management.

Manages all HuggingFace environment variables and runtime configuration, mirroring the Python huggingface_hub environment variable system.

Environment Variables

VariableDescriptionDefault
HF_TOKENHuggingFace API token(none)
HUGGINGFACE_TOKENAlias for HF_TOKEN(none)
HUGGING_FACE_HUB_TOKENLegacy alias(none)
HF_HOMEBase cache directory~/.cache/huggingface
HF_HUB_CACHEHub cache directory$HF_HOME/hub
HF_ENDPOINTHub endpoint URLhttps://huggingface.co
HF_HUB_DISABLE_SYMLINKSDisable symlinks in cache(false)
HF_HUB_OFFLINEDisable network requests(false)
HF_DATASETS_CACHEDatasets cache directory$HF_HOME/datasets
TRANSFORMERS_CACHETransformers cache (legacy)(none)

Elixir Config

# config/config.exs
config :huggingface_client,
  hub_url:       "https://huggingface.co",
  default_token: System.get_env("HF_TOKEN"),
  cache_dir:     System.get_env("HF_HUB_CACHE"),
  offline:       false

Example

# Get current token
token = HuggingfaceClient.Config.token()

# Get cache directory
cache_dir = HuggingfaceClient.Config.cache_dir()

# Check if offline mode is enabled
if HuggingfaceClient.Config.offline?() do
  IO.puts("Offline mode: only using cached files")
end

Summary

Functions

Returns the Hub cache directory.

Returns the datasets cache directory.

Removes the locally saved token (equivalent to huggingface-cli logout).

Returns true if progress bars are disabled.

Returns true if symlinks in the cache are disabled.

Returns the Hub endpoint URL.

Returns a map of all HuggingFace-related environment variables that are set.

Returns the HuggingFace home directory.

Returns true if offline mode is enabled.

Prints the current configuration to stdout.

Saves a token to the local credential file (~/.cache/huggingface/token).

Returns the configured HuggingFace API token.

Functions

cache_dir()

@spec cache_dir() :: String.t()

Returns the Hub cache directory.

Checks HF_HUB_CACHE env var, then $HF_HOME/hub.

datasets_cache_dir()

@spec datasets_cache_dir() :: String.t()

Returns the datasets cache directory.

delete_token()

@spec delete_token() :: :ok

Removes the locally saved token (equivalent to huggingface-cli logout).

disable_progress_bars?()

@spec disable_progress_bars?() :: boolean()

Returns true if progress bars are disabled.

disable_symlinks?()

@spec disable_symlinks?() :: boolean()

Returns true if symlinks in the cache are disabled.

endpoint()

@spec endpoint() :: String.t()

Returns the Hub endpoint URL.

Checks HF_ENDPOINT env var, then application config, then default.

env_info()

@spec env_info() :: map()

Returns a map of all HuggingFace-related environment variables that are set.

Example

env = HuggingfaceClient.Config.env_info()
Enum.each(env, fn {k, v} -> IO.puts("#{k}=#{v}") end)

hf_home()

@spec hf_home() :: String.t()

Returns the HuggingFace home directory.

Checks HF_HOME env var, then defaults to ~/.cache/huggingface.

offline?()

@spec offline?() :: boolean()

Returns true if offline mode is enabled.

In offline mode, no network requests are made — only cached files are used. Controlled by HF_HUB_OFFLINE env var or application config.

save_token(token_value)

@spec save_token(String.t()) :: :ok | {:error, term()}

Saves a token to the local credential file (~/.cache/huggingface/token).

This is equivalent to running huggingface-cli login.

Example

HuggingfaceClient.Config.save_token("hf_your_token")

token()

@spec token() :: String.t() | nil

Returns the configured HuggingFace API token.

Checks in order:

  1. Application config: config :huggingface_client, default_token: "hf_xxx"
  2. HF_TOKEN env var
  3. HUGGINGFACE_TOKEN env var
  4. HUGGING_FACE_HUB_TOKEN env var (legacy)
  5. Token saved on disk by huggingface-cli login at ~/.cache/huggingface/token

Returns nil if no token is found.