HfHub (HfHub v0.1.3)
View SourceElixir client for HuggingFace Hub.
HfHub provides a comprehensive interface to the HuggingFace Hub API,
enabling Elixir applications to access models, datasets, and spaces.
Features
- Hub API Client — Fetch metadata for models, datasets, and spaces
- File Downloads — Stream files from HuggingFace repositories with resume support
- Smart Caching — Local file caching with LRU eviction and integrity checks
- Filesystem Utilities — Manage local HuggingFace cache directory structure
- Authentication — Token-based authentication for private repositories
Quick Start
# Get model information
{:ok, model_info} = HfHub.Api.model_info("bert-base-uncased")
# Download a model file
{:ok, path} = HfHub.Download.hf_hub_download(
repo_id: "bert-base-uncased",
filename: "config.json",
repo_type: :model
)
# Check cache
cached? = HfHub.Cache.cached?(
repo_id: "bert-base-uncased",
filename: "config.json"
)Configuration
Configure in config/config.exs:
config :hf_hub,
token: System.get_env("HF_TOKEN"),
cache_dir: Path.expand("~/.cache/huggingface"),
endpoint: "https://huggingface.co"Modules
HfHub.Api— Hub API client (models, datasets, spaces)HfHub.Download— File download with cachingHfHub.Cache— Cache management and statisticsHfHub.FS— Filesystem utilities for cacheHfHub.Auth— Authentication and authorizationHfHub.Hub— Bumblebee-compatible ETag-based cachingHfHub.Repository— Repository reference typesHfHub.RepoFiles— Repository file listing with ETags
Summary
Types
A repository reference (Bumblebee-compatible).
Types
@type filename() :: String.t()
@type repo_id() :: String.t()
@type repo_type() :: :model | :dataset | :space
@type repository() :: HfHub.Repository.t()
A repository reference (Bumblebee-compatible).
Can be either:
{:hf, repository_id}- HuggingFace repository{:hf, repository_id, opts}- HuggingFace repository with options{:local, directory}- Local directory
@type revision() :: String.t()