Expand description
§hf-fetch-model
Fast HuggingFace model downloads for Rust.
An embeddable library for downloading HuggingFace model repositories
with maximum throughput. Wraps hf_hub and adds repo-level orchestration.
§Quick Start
let outcome = hf_fetch_model::download("julien-c/dummy-unknown".to_owned()).await?;
println!("Model at: {}", outcome.inner().display());§Configured Download
use hf_fetch_model::FetchConfig;
let config = FetchConfig::builder()
.filter("*.safetensors")
.filter("*.json")
.on_progress(|e| {
println!("{}: {:.1}%", e.filename, e.percent);
})
.build()?;
let outcome = hf_fetch_model::download_with_config(
"google/gemma-2-2b".to_owned(),
&config,
).await?;
// outcome.is_cached() tells you if it came from local cache
let path = outcome.into_inner();§Inspect Before Downloading
Read tensor metadata from .safetensors headers via HTTP Range requests —
no weight data downloaded. See examples/candle_inspect.rs
for a runnable example.
let results = hf_fetch_model::inspect::inspect_repo_safetensors(
"EleutherAI/pythia-1.4b", None, None,
).await?;
for (filename, header, _source) in &results {
println!("{filename}: {} tensors", header.tensors.len());
}§HuggingFace Cache
Downloaded files are stored in the standard HuggingFace cache directory
(~/.cache/huggingface/hub/), ensuring compatibility with Python tooling.
§Authentication
Set the HF_TOKEN environment variable to access private or gated models,
or use FetchConfig::builder().token().
Re-exports§
pub use config::compile_glob_patterns;pub use config::file_matches;pub use config::has_glob_chars;pub use config::FetchConfig;pub use config::FetchConfigBuilder;pub use config::Filter;pub use discover::DiscoveredFamily;pub use discover::GateStatus;pub use discover::ModelCardMetadata;pub use discover::SearchResult;pub use download::DownloadOutcome;pub use error::FetchError;pub use error::FileFailure;pub use inspect::AdapterConfig;pub use plan::download_plan;pub use plan::DownloadPlan;pub use plan::FilePlan;pub use progress::ProgressEvent;pub use progress::ProgressReceiver;
Modules§
- cache
HuggingFacecache directory resolution, model family scanning, and disk usage.- cache_
layout - Centralized
hf-hubcache path construction. - checksum
- SHA256 checksum verification for downloaded files.
- config
- Configuration for model downloads.
- discover
- Model family discovery and search via the
HuggingFaceHub API. - download
- Download orchestration for
HuggingFacemodel repositories. - error
- Error types for hf-fetch-model.
- inspect
- Safetensors header inspection (local and remote).
- plan
- Download plan: metadata-only analysis of what needs downloading.
- progress
- Progress reporting for model downloads.
- repo
- Repository file listing via the
HuggingFaceAPI.
Functions§
- build_
client - Builds a
reqwest::Clientwith auth token, user-agent, and 30-second TCP connect timeout. - download
- Downloads all files from a
HuggingFacemodel repository. - download_
blocking - Blocking version of
download()for non-async callers. - download_
file - Downloads a single file from a
HuggingFacemodel repository. - download_
file_ blocking - Blocking version of
download_file()for non-async callers. - download_
files - Downloads all files from a
HuggingFacemodel repository and returns a filename → path map. - download_
files_ blocking - Blocking version of
download_files()for non-async callers. - download_
files_ with_ config - Downloads files from a
HuggingFacemodel repository using the given configuration and returns a filename → path map. - download_
files_ with_ config_ blocking - Blocking version of
download_files_with_config()for non-async callers. - download_
with_ config - Downloads files from a
HuggingFacemodel repository using the given configuration. - download_
with_ config_ blocking - Blocking version of
download_with_config()for non-async callers. - download_
with_ plan - Downloads files according to an existing
DownloadPlan. - download_
with_ plan_ blocking - Blocking version of
download_with_plan()for non-async callers.