[hub] Add download command to the CLI#2266
Open
assafvayner wants to merge 2 commits into
Open
Conversation
Add a `download` command group with three subcommands, one per download library function: - `download file <repo> <path> [local-path]` — downloadFile to an arbitrary local path, with a progress bar (xet: true) - `download cache <repo> <path>` — downloadFileToCacheDir into the HF cache dir - `download snapshot <repo>` — snapshotDownload the whole repo into the cache dir Extract a tested `streamBlobToFile` helper to stream a lazy Blob to disk with progress, removing the partial file on error.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
coyotte508
reviewed
Jul 1, 2026
Member
There was a problem hiding this comment.
This doesn't really belong to a utils function, only used in cli, behavior too specific (eg catch error & unlink file)
coyotte508
reviewed
Jul 1, 2026
Comment on lines
+128
to
+135
| # Download a single file to a local path (defaults to ./config.json) | ||
| npx @huggingface/hub download file coyotte508/test-model config.json | ||
| npx @huggingface/hub download file coyotte508/test-model config.json ./local-config.json | ||
| # Download a single file into the Hugging Face cache directory | ||
| npx @huggingface/hub download cache coyotte508/test-model config.json | ||
| # Download an entire repo into the Hugging Face cache directory | ||
| npx @huggingface/hub download snapshot coyotte508/test-model | ||
| npx @huggingface/hub download snapshot --repo-type dataset coyotte508/test-dataset |
Member
There was a problem hiding this comment.
@moonbot what's the huggingface_hub's hf cli syntax?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
downloadcommand group to the@huggingface/hubCLI, one subcommand per download library function.Subcommands
hfjs download file <repo> <path> [local-path]downloadFilehfjs download cache <repo> <path>downloadFileToCacheDirhfjs download snapshot <repo>snapshotDownloadCommon flags on all three:
--repo-type {dataset|model|space},--revision,--token,--quiet/-q.cache/snapshotalso accept--cache-dir. Repo type can be given via flag or name prefix (datasets/...). Downloads use Xet (filepassesxet: trueexplicitly;cache/snapshotinherit Xet-on by default).download fileon a missing file prints an error and exits non-zero without creating a file.Implementation
streamBlobToFileutil streams a lazyBlobto disk with a cumulative-progress callback, removing the partial file on error. It's extracted from the CLI so it's unit-testable (cli.ts runs on import).cli.tsgets thedownloadcommand group, modeled on the existingbranch/repogroups.Testing
streamBlobToFile(exact bytes, cumulative progress, error cleanup).file(default + explicit path, quiet), not-found → exit 1 with no file,cache, andsnapshot.Note
Low Risk
Additive CLI and docs only; reuses existing library download functions with local file writes guarded on missing files.
Overview
Adds a
downloadcommand group to the@huggingface/hubCLI so users can pull Hub content from the terminal, mirroring existing upload flows.download filefetches one file viadownloadFile(withxet: true), streams it to a local path (default: basename in cwd) using newstreamBlobToFile(progress callback, deletes partial files on failure), optionalcli-progressbar, and exits non-zero without writing when the path is missing.download cacheanddownload snapshotcalldownloadFileToCacheDirandsnapshotDownloadinto the HF cache (optional--cache-dir).All subcommands share
--repo-type,--revision,--token, and--quiet, with help wired likebranch. The hub README documentsnpx/hfjsdownload examples andhelp download.Reviewed by Cursor Bugbot for commit f9e1d4b. Bugbot is set up for automated code reviews on this repo. Configure here.