Thanks a lot @not-lain ! 🤗 The speedup comes from making imports lazy, in #4914:
huggingface_hub.utils now uses the same lazy loading as the root package, so a name is only imported the first time you use it.
HfApi loads its heavy internals (commit, upload, bucket, download) inside the methods that need them.
- Optional dependencies (Torch, TensorBoard, NumPy, FastAPI, Starlette) are only loaded when you use the matching integration. Which is very rare, in practice you don't need them to make http calls.
- The
hf CLI registers commands lazily too, so hf version and similar commands start much faster.
On from huggingface_hub import *, this took us from 2.36s to 0.39s, and peak memory from ~627 MiB to ~50 MiB.
One small heads-up: huggingface_hub.hf_api no longer re-exports classes like BucketFile or CommitOperationAdd. You should import them from the package root (from huggingface_hub import CommitOperationAdd) instead.