Official Python client for the Hugging Face Hub. Handles model/dataset/Space downloading, uploading, caching, repo management, and Hub API interactions. Used as a dependency by transformers, datasets, sentence-transformers, and most HF ecosystem packages. The CLI was previously huggingface-cli; in v1.x it was rebranded as hf (also available as a standalone pip install hf package for CLI-only use). Import name: huggingface_hub (underscore). Package name: huggingface-hub (hyphen). These are different from the hf CLI package.
pip install huggingface-hubVerified import paths — ran on the pinned version, not inferred.
Files are cached locally in HF_HOME (default: ~/.cache/huggingface). hf_hub_download returns local path. Gated models (Llama, Gemma) require login() or HF_TOKEN with accepted license.
Update scripts to use hf auth login. huggingface-cli remains as a compatibility alias.
Update HTTP mocking to use httpx. Do not assume requests is the underlying transport.
Set HF_TOKEN env var with a token that has accepted the model's license at huggingface.co/settings/tokens.
To force re-download, delete the cached repo from HF_HOME or pass force_download=True.
Always: pip install huggingface-hub (hyphen). Always: import huggingface_hub (underscore).
Run `pip install huggingface-hub` or `conda install -c conda-forge huggingface-hub` to install the library.
Generate a new access token from your Hugging Face settings page (huggingface.co/settings/tokens). Then, try `huggingface-cli login` in your terminal and carefully paste the token, or use `from huggingface_hub import login; login(token='hf_YOUR_TOKEN_HERE')` in Python.
Ensure `huggingface-hub` is installed and up-to-date by running `pip install --upgrade huggingface-hub`. If `huggingface-cli` works but gives a deprecation warning, simply switch to using the `hf` command instead.
Log in to the Hugging Face Hub using `huggingface-cli login` in your terminal or programmatically with `from huggingface_hub import login; login()` in a notebook. Ensure your access token has sufficient permissions (read for download, write for upload) for the repository you are trying to access.
Upgrade `huggingface-hub` to its latest version by running `pip install --upgrade huggingface-hub`. After upgrading, verify your import statements, ensuring core components like `HfApi` are imported directly from `huggingface_hub` (e.g., `from huggingface_hub import HfApi`).