Convert Figma logo to code with AI

huggingface logohuggingface_hub

The official Python client for the Hugging Face Hub.

3,743
1,094
3,743
196

Top Related Projects

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

99,486

Tensors and Dynamic neural networks in Python with strong GPU acceleration

194,834

An Open Source Machine Learning Framework for Everyone

42,282

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

40,008

TensorFlow code and pre-trained models for BERT

32,229

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

Quick Overview

The huggingface/huggingface_hub repository is a Python library that provides an interface to interact with the Hugging Face Hub. It allows users to easily download and upload models, datasets, and other artifacts, as well as manage repositories on the Hub. This library is essential for integrating Hugging Face's ecosystem into various machine learning workflows.

Pros

  • Seamless integration with Hugging Face's ecosystem of models and datasets
  • Easy-to-use API for downloading, uploading, and managing Hub resources
  • Supports various file formats and versioning
  • Extensive documentation and community support

Cons

  • Requires an internet connection for most operations
  • May have rate limits or restrictions for heavy usage
  • Learning curve for users unfamiliar with Hugging Face's ecosystem
  • Dependency on external services (Hugging Face Hub)

Code Examples

  1. Downloading a model from the Hub:
from huggingface_hub import hf_hub_download

model_path = hf_hub_download(repo_id="bert-base-uncased", filename="pytorch_model.bin")
print(f"Model downloaded to: {model_path}")
  1. Uploading a file to the Hub:
from huggingface_hub import HfApi

api = HfApi()
api.upload_file(
    path_or_fileobj="./my_model.safetensors",
    path_in_repo="model.safetensors",
    repo_id="username/my-model",
    repo_type="model",
)
  1. Creating a new repository on the Hub:
from huggingface_hub import create_repo

repo_url = create_repo(repo_id="username/new-repo", private=True)
print(f"New repository created at: {repo_url}")

Getting Started

To get started with the huggingface_hub library, follow these steps:

  1. Install the library:
pip install huggingface_hub
  1. Import the necessary modules and authenticate:
from huggingface_hub import login

login()  # This will prompt for your Hugging Face access token
  1. Use the library to interact with the Hub:
from huggingface_hub import hf_hub_download, HfApi

# Download a model
model_path = hf_hub_download(repo_id="bert-base-uncased", filename="config.json")

# List models in a repository
api = HfApi()
models = api.list_repo_files("username/my-repo")
print(models)

With these steps, you can start using the huggingface_hub library to interact with the Hugging Face Hub, download models and datasets, and manage your repositories.

Competitor Comparisons

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

Pros of transformers

  • Comprehensive library for state-of-the-art NLP models
  • Extensive documentation and community support
  • Seamless integration with popular deep learning frameworks

Cons of transformers

  • Larger codebase and potentially steeper learning curve
  • Higher computational requirements for some models
  • May include unnecessary features for simple use cases

Code comparison

transformers:

from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("Hello world!", return_tensors="pt")
outputs = model(**inputs)

huggingface_hub:

from huggingface_hub import hf_hub_download

model_path = hf_hub_download(repo_id="bert-base-uncased", filename="pytorch_model.bin")

The transformers library provides a higher-level API for working with pre-trained models, while huggingface_hub focuses on model and dataset management. transformers offers more comprehensive functionality for NLP tasks, but huggingface_hub is lighter and more focused on interacting with the Hugging Face ecosystem.

99,486

Tensors and Dynamic neural networks in Python with strong GPU acceleration

Pros of PyTorch

  • More comprehensive and lower-level deep learning framework
  • Wider range of applications beyond NLP, including computer vision and reinforcement learning
  • Larger community and ecosystem of tools and extensions

Cons of PyTorch

  • Steeper learning curve for beginners
  • Less focus on ease of use for specific NLP tasks
  • Requires more boilerplate code for common operations

Code Comparison

PyTorch:

import torch

x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
z = torch.matmul(x, y)

Hugging Face Hub:

from huggingface_hub import hf_hub_download

model = hf_hub_download(repo_id="bert-base-uncased", filename="pytorch_model.bin")

PyTorch provides lower-level tensor operations, while Hugging Face Hub focuses on easy model downloading and management. PyTorch offers more flexibility but requires more code for basic operations, whereas Hugging Face Hub simplifies access to pre-trained models and datasets for NLP tasks.

194,834

An Open Source Machine Learning Framework for Everyone

Pros of TensorFlow

  • Comprehensive ecosystem for machine learning, including tools for deployment and production
  • Strong support for distributed computing and GPU acceleration
  • Extensive documentation and large community support

Cons of TensorFlow

  • Steeper learning curve compared to HuggingFace Hub
  • More complex setup and configuration process
  • Less focus on natural language processing tasks specifically

Code Comparison

TensorFlow example:

import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='categorical_crossentropy')

HuggingFace Hub example:

from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")

TensorFlow provides a lower-level API for building custom models, while HuggingFace Hub focuses on easy access to pre-trained models for NLP tasks. TensorFlow offers more flexibility but requires more code, whereas HuggingFace Hub prioritizes simplicity and rapid prototyping for specific NLP applications.

42,282

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

Pros of DeepSpeed

  • Focuses on optimizing large-scale model training and inference
  • Offers advanced distributed training techniques like ZeRO and 3D parallelism
  • Provides built-in support for mixed precision and gradient accumulation

Cons of DeepSpeed

  • Steeper learning curve for beginners compared to Hugging Face Hub
  • Less integrated ecosystem for model sharing and collaboration
  • Requires more manual configuration for optimal performance

Code Comparison

DeepSpeed:

import deepspeed
model_engine, optimizer, _, _ = deepspeed.initialize(
    args=args, model=model, model_parameters=params
)

Hugging Face Hub:

from huggingface_hub import Repository
repo = Repository(local_dir="./my_model", clone_from="username/my_model")
repo.git_pull()

Summary

DeepSpeed excels in optimizing large-scale model training and inference, offering advanced techniques for distributed computing. However, it has a steeper learning curve and requires more manual configuration. Hugging Face Hub, on the other hand, provides a more user-friendly interface for model sharing and collaboration, but may not offer the same level of performance optimization for large-scale models.

40,008

TensorFlow code and pre-trained models for BERT

Pros of BERT

  • Original implementation of the groundbreaking BERT model
  • Focused specifically on BERT, providing a deep dive into its architecture
  • Includes pre-training and fine-tuning scripts for various tasks

Cons of BERT

  • Less actively maintained compared to Hugging Face Hub
  • Limited to BERT and its variants, not covering other model architectures
  • Lacks the extensive ecosystem and community support of Hugging Face

Code Comparison

BERT:

import tensorflow as tf
import modeling

bert_config = modeling.BertConfig.from_json_file("bert_config.json")
model = modeling.BertModel(
    config=bert_config,
    is_training=True,
    input_ids=input_ids,
    input_mask=input_mask,
    token_type_ids=segment_ids)

Hugging Face Hub:

from transformers import BertModel, BertTokenizer

tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
model = BertModel.from_pretrained("bert-base-uncased")
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)

The BERT repository provides a lower-level implementation, while Hugging Face Hub offers a more user-friendly interface with pre-trained models and easy integration. Hugging Face Hub also supports a wide range of models beyond BERT, making it more versatile for various NLP tasks.

32,229

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.

Pros of fairseq

  • Specialized for sequence-to-sequence tasks like machine translation
  • Includes pre-trained models and benchmarks for various NLP tasks
  • Offers more low-level control and customization options

Cons of fairseq

  • Steeper learning curve, especially for beginners
  • Less extensive documentation compared to Hugging Face Hub
  • Narrower focus on sequence modeling tasks

Code Comparison

fairseq:

from fairseq.models.transformer import TransformerModel

en2de = TransformerModel.from_pretrained(
    '/path/to/model',
    checkpoint_file='model.pt',
    data_name_or_path='data-bin/wmt14_en_de'
)
en2de.translate('Hello world!')

huggingface_hub:

from transformers import pipeline

translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-de")
translator("Hello world!")

The fairseq example demonstrates more explicit model loading and data path specification, while the Hugging Face Hub example showcases a simpler, more abstracted approach using pipelines. fairseq offers more granular control, while Hugging Face Hub prioritizes ease of use and quick implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

huggingface_hub library logo

The official CLI and Python client for the Hugging Face Hub.
About · Documentation · Install · CLI Guide · Contributing

Documentation GitHub release PyPi version PyPI - Downloads Code coverage

English | Deutsch | Français | हिंदी | 한국어 | 中文 (简体) | ಕನ್ನಡ

Quick start

Install the hf CLI with the standalone installer:

# On macOS and Linux.
curl -LsSf https://hf.co/cli/install.sh | bash
# On Windows.
powershell -ExecutionPolicy ByPass -c "irm https://hf.co/cli/install.ps1 | iex"

Log in, then start working with the Hub:

# Log in (use --token $HF_TOKEN in non-interactive environments)
hf auth login

# Find models served by Inference Providers
hf models ls --warm

# Download a model
hf download Qwen/Qwen3-0.6B

# Upload files to your own repo
hf upload username/my-cool-model ./model.safetensors

# Sync a local folder to a storage bucket
hf buckets sync ./checkpoints hf://buckets/username/my-bucket

# Run a job on Hugging Face infrastructure
hf jobs run python:3.12 python -c "print('Hello from the cloud!')"

# Discover everything else
hf --help

The Hub uses tokens to authenticate applications (see docs). Check out the CLI guide for a tour of the main features.

What is huggingface_hub?

The huggingface_hub library allows you to interact with the Hugging Face Hub, a platform democratizing open-source Machine Learning for creators and collaborators. Discover pre-trained models and datasets for your projects, play with the thousands of machine learning apps hosted on the Hub, or create and share your own models, datasets and demos with the community. Everything ships in one package with two interfaces: the hf CLI for your terminal and the huggingface_hub library for Python — both designed to work well for humans and AI agents. Use them to:

Built for humans and AI agents

The hf CLI is designed for people and coding agents alike: the same commands adapt their output when run by an agent. If you use Claude Code, Codex, Cursor, or another coding agent, install the hf CLI Skill — a command reference generated from your installed CLI:

# for Codex, Cursor, OpenCode, Pi and other agents that load skills from `.agents/skills`
hf skills add
# includes the above + Claude Code
hf skills add --claude

Learn more in the Hugging Face CLI for AI agents guide and the announcement blog post.

Use the Python library

Install the huggingface_hub package with pip (this also installs the hf CLI):

pip install huggingface_hub

We recommend using uv for a fast and reliable install:

uv pip install huggingface_hub

In order to keep the package minimal by default, huggingface_hub comes with optional dependencies useful for some use cases. For example, if you want to use the MCP module, run:

pip install "huggingface_hub[mcp]"

To learn more about installation and optional dependencies, check out the installation guide.

Download files

Download a single file

from huggingface_hub import hf_hub_download

hf_hub_download(repo_id="zai-org/GLM-5.2", filename="config.json")

Or an entire repository

from huggingface_hub import snapshot_download

snapshot_download("sentence-transformers/all-MiniLM-L6-v2")

Files will be downloaded in a local cache folder. More details in this guide.

Create a repository

from huggingface_hub import create_repo

create_repo(repo_id="super-cool-model")

Upload files

Upload a single file

from huggingface_hub import upload_file

upload_file(
    path_or_fileobj="/home/lysandre/dummy-test/README.md",
    path_in_repo="README.md",
    repo_id="lysandre/test-model",
)

Or an entire folder

from huggingface_hub import upload_folder

upload_folder(
    folder_path="/path/to/local/space",
    repo_id="username/my-cool-space",
    repo_type="space",
)

More details in the upload guide.

Integrating with the Hub.

We're partnering with cool open source ML libraries to provide free model hosting and versioning. You can find the existing integrations here.

The advantages are:

  • Free model or dataset hosting for libraries and their users.
  • Built-in file versioning, even with very large files, made possible by Xet, the Hub's chunk-deduplicated storage backend.
  • In-browser widgets to play with the uploaded models.
  • Anyone can upload a new model for your library, they just need to add the corresponding tag for the model to be discoverable.
  • Fast downloads! We use Cloudfront (a CDN) to geo-replicate downloads so they're blazing fast from anywhere on the globe.
  • Usage stats and more features to come.

If you would like to integrate your library, feel free to open an issue to begin the discussion. We wrote a step-by-step guide with ❤️ showing how to do this integration.

Contributions (feature requests, bugs, etc.) are super welcome 💙💚💛💜🧡❤️

Everyone is welcome to contribute, and we value everybody's contribution. Code is not the only way to help the community. Answering questions, helping others, reaching out and improving the documentations are immensely valuable to the community. We wrote a contribution guide to summarize how to get started to contribute to this repository.