Hub Python Library documentation
Migrating to huggingface_hub v2.0
Migrating to huggingface_hub v2.0
huggingface_hub v2.0 replaces its HTTP dependency with httpx2 and removes deprecated 1.x APIs. HTTP clients and exceptions now come from a separate package.
To support both huggingface_hub v1.x (starting with v1.30.0) and v2.x, import the HTTP module from huggingface_hub.utils:
from huggingface_hub.utils import get_session, httpx
try:
response = get_session().get("https://huggingface.co/api/models/gpt2")
response.raise_for_status()
except httpx.HTTPError:
...Use this same import when creating custom clients for set_client_factory() or set_async_client_factory(). Clients and exceptions from the old HTTP package are distinct from those in httpx2 and cannot be used interchangeably.
httpx2 uses the operating system’s certificate trust store by default. Custom CA bundles configured with SSL_CERT_FILE or SSL_CERT_DIR are still supported. Logging configuration should target httpx2 and httpcore2 instead of the old logger names. See the upstream migration guide for details.
The oauth extra now requires authlib>=1.8.0 for httpx2 support.
Removed deprecated APIs
- Use
upload_folderinstead ofupload_large_folderorHfApi.upload_large_folder. - Use
duplicate_repo,set_space_volumes, anddelete_space_volumesinstead ofduplicate_space,request_space_storage, anddelete_space_storage. - Use
parse_hf_uriinstead ofrepo_type_and_id_from_hf_id, andlist_models(search=...)instead ofmodel_name=.... - Use
space_volumesinstead ofspace_storageincreate_repoandduplicate_repo. - Use
InferenceEndpointType.AUTHENTICATEDortype="authenticated"instead ofPROTECTEDortype="protected". - Use
text_generation(stop=...)instead ofstop_sequences=..., and pass a token string orNonetoInferenceClientinstead of a boolean. - Use
hfinstead ofhuggingface-cli;hf repoandhf repo-files deleteare replaced byhf reposandhf repos delete-files. - Use
hf uploadinstead ofhf upload-large-folder; use--volumeinstead of--storagefor repository creation and duplication, and--statusor--labelinstead ofhf jobs ps --filter. - The deprecated
--claudeoption onhf skills addandhf skills updateis removed. Skills are installed for Claude Code automatically.
For more context, see the httpx2 project, the httpx2 documentation, the upstream transition guide from httpx to httpx2, and the huggingface_hub transition plan.