pypi huggingface-hub 2.5.0
[v2.5.0] Token revocation, sandbox network policies & SQL over Hub datasets

2 hours ago

๐Ÿšจ Revoke leaked tokens with hf auth revoke

If a token ever leaks โ€” committed to a repo, pasted in a log, shared in a snippet โ€” you can now revoke it right away with hf auth revoke. Revocation doesn't require being logged in: anyone holding the raw value of a token can revoke it, and the token owner gets notified by email. To rule out footguns, the request is deliberately sent without your own Authorization header, so your active token can never be revoked by mistake. The same is available in Python with the new top-level revoke_tokens() helper, which sends tokens in batches of 1000. Note that the Hub always answers with a generic "revocation requested" message, whether the token existed or not.

>>> hf auth revoke hf_xxx hf_yyy
โœ“ Revocation requested for 2 token(s)
  count: 2
>>> from huggingface_hub import revoke_tokens
>>> revoke_tokens(["hf_xxx"])

๐Ÿ“š Documentation: hf auth revoke in the CLI guide ยท revoke_tokens() reference

  • [CLI] Add hf auth revoke to revoke leaked tokens by @Wauplin in #5389

๐ŸŒ Sandbox network policies: no internet access, or an allowlist

Sandboxes can now run without internet access, or with access restricted to an allowlist. Pass network="none" to block all outbound connections, or network={"allow": [...]} with IP ranges, IPs (optionally with a port) and hostnames โ€” for example, to let an agent in a sandbox reach your internal vLLM server and the Hub, and nothing else. The policy is enforced by the sandbox server with seccomp and Landlock, applies to every process the sandbox starts, and cannot be removed from inside the sandbox, even by root. Pools support it per-sandbox too, so one host can run isolated and connected sandboxes side by side. If the server cannot apply the policy (e.g. a pool host started by an older version of huggingface_hub), creation fails with a SandboxError instead of silently returning a connected sandbox.

sbx = Sandbox.create("python:3.12", network="none")  # volumes still work
sbx = Sandbox.create("python:3.12", network={"allow": ["10.0.0.0/8", "203.0.113.10:443", "huggingface.co"]})
agent = pool.create(network="none")  # pools can mix isolated and connected sandboxes
hf sandbox create --network none
hf sandbox create --network 10.0.0.0/8,huggingface.co:443

๐Ÿ“š Documentation: Sandboxes guide

  • [Sandbox] Add network policies: no internet access, or an allowlist by @Wauplin in #5303

๐Ÿฆ† Query datasets with hf_dataset() in hf datasets sql

hf datasets sql now auto-installs and loads the Hugging Face DuckDB extension, so you can query a dataset with hf_dataset('org/name') instead of hand-building read_parquet(...) URLs against the Dataset Viewer. This is a nice ergonomics win for agents previewing datasets, and as a side effect it also enables writing back to the Hub with COPY ... TO 'hf://datasets/username/dataset-name/...'. The extension requires DuckDB 2.0+; if it cannot be installed (older DuckDB or an unsupported platform), a warning is logged and existing read_parquet workflows keep working unchanged.

>>> hf datasets sql "SELECT * FROM hf_dataset('stanfordnlp/imdb') LIMIT 3"

๐Ÿ“š Documentation: hf datasets sql in the CLI guide

๐Ÿ’พ fsspec transactions for buckets

HfFileSystem now supports fsspec transactions for buckets. Files written inside a fs.transaction block are uploaded when the block ends, and nothing is uploaded if the block raises. This unlocks libraries that wrap every save in a transaction, such as PyTorch Lightning's _atomic_save, which previously could not write checkpoints to hf://buckets/... paths. Transactions are best-effort (each file is uploaded separately on commit, so a failure can leave earlier files uploaded) and buckets-only: repo writes, rm and cp_file inside a transaction raise a NotImplementedError before any upload or delete.

>>> with hffs.transaction:
...     with hffs.open("buckets/my-username/my-bucket/checkpoints/last.ckpt", "wb") as f:
...         f.write(data)
...     # not uploaded yet
>>> # uploaded now

๐Ÿ“š Documentation: Transactions in the HfFileSystem guide

๐Ÿ” Spaces OAuth without a client secret (PKCE)

OAUTH_CLIENT_SECRET is now optional when adding Hugging Face OAuth to a Space. PKCE (S256) is always enabled: without a secret, the Space authenticates as a public OAuth client (token_endpoint_auth_method="none"), while Spaces that still receive a client secret keep working as before. Session cookies are now signed with a key derived from SPACE_SIGNING_SECRET โ€” a stable per-Space secret injected by the Hub โ€” instead of OAUTH_CLIENT_SECRET, so sessions survive restarts and are shared across replicas, and secretless Spaces no longer share a predictable cookie key. Heads-up: the signing key changes with this release, so users logged in to an OAuth Space will need to log in again once the Space upgrades huggingface_hub.

  • Make OAuth client secret optional for Spaces (PKCE support) by @moon-bot-app[bot] in #4578

๐Ÿค– Chat completions routed through the Hub router

When calling chat_completion with a Hugging Face token and a specific provider, requests now go through the Hub router at /v1/chat/completions with model set to hf-model-id:provider, instead of calling provider-specific routes directly. Provider routes skip the router's server-side routing (auto, :cheapest/:fastest/:preferred policies, model pinning), so pinned-provider calls now follow exactly the same path as auto calls and the Hub code snippets, with OpenRouter picking a serving provider and failing over automatically if one is down or rate limited. Calls with a provider API key are unchanged and still reach the provider directly, and the chat provider helpers dropped by this change are no longer needed by the client.

๐Ÿ“š Documentation: Inference guide

  • [Inference Providers] Route chat through the router and drop chat provider helpers by @hanouticelina in #5333

๐Ÿ–ฅ๏ธ CLI

  • [CLI] Fix --format guidance in the generated hf-cli skill by @hanouticelina in #5286
  • [CLI] Fix visibility help in hf repos settings by @sergiopaniego in #5379
  • [CLI] List global formatting flags in the generated CLI reference by @moon-bot-app[bot] in #5438

๐Ÿ“Š Jobs

  • [Jobs] Use the client to resolve the list_jobs namespace by @mertkayacs in #5285
  • [Jobs] Keep auto-generated Job names within the 100-character limit by @sergiopaniego in #5306
  • [Jobs] Clear error for an invalid --timeout value by @sergiopaniego in #5386
  • [Jobs] Use the script file name as default Job name on Windows paths by @Wauplin in #5388
  • [Jobs] Fix run_uv_job crash on long script arguments by @davanstrien in #5424

๐Ÿงช Sandbox

  • [Sandbox] Prune cached pool hosts whose job no longer exists by @CharlesXmf in #5375

๐Ÿค– Inference

  • [Inference] Keep the client alive while its response is streamed by @ShaanGS in #5399
  • [Endpoints] Use the HfApi client token for returned endpoints by @AyeshaWaseemAhmad in #5331

๐Ÿ”ง Other QoL Improvements

  • [Spaces] Add visibility field to SpaceInfo by @Wauplin in #5295
  • [Discussions] Expose diff_url on DiscussionWithDetails and use it in hf discussions diff by @TejasLamba2006 in #5341
  • [HTTP] Raise EgressLimitError on 402 EgressLimitReached by @Wauplin in #5434 โ€” docs
  • Type JobStatus.stage and SpaceRuntime.stage as Enum | str by @davanstrien in #5440

๐Ÿ“– Documentation

๐Ÿ› Bug and typo fixes

๐Ÿ—๏ธ Internal

  • Post-release: bump version to 2.5.0.dev0 by @huggingface-hub-bot[bot] in #5279
  • [Tests] Fix test_validate_repocard for new Hub license error message by @Wauplin in #5296
  • [Tests] Don't tie RepoCard line-ending test to the OS by @Aschenbath in #5300
  • [Fastai] Replace toml with tomllib and tomli by @dimbleby in #5312
  • Fix CI type error from click 8.5.1 in HfArgument by @Wauplin in #5322
  • [CI] Fix ty 0.0.100 failures from the unresolved-attribute rule split by @hanouticelina in #5335
  • [CI] Fix ty 0.0.105 missing-module-member errors on hf_xet by @Wauplin in #5369
  • [CI] Drop model card consistency reminder workflow by @Wauplin in #5370
  • [Tests] Fix live inference provider mapping tests (DeepSeek-R1 has no providers anymore) by @Wauplin in #5436

Don't miss a new huggingface-hub release

NewReleases is sending notifications on new releases.