Get startedGet started for free

Listing models on Hugging Face Hub

The Hugging Face Hub provides a powerful programmatic interface to access a vast range of pre-trained models. In this exercise, you will learn how to use the huggingface_hub package to interact with the Hub and list available models directly from your Python environment.

Note: The huggingface_hub package has already been installed for you.

This exercise is part of the course

Working with Hugging Face

View Course

Exercise instructions

  • Import the HfApi class and create an instance of it.
  • Use the appropriate method to list all models and print first two.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from huggingface_hub import ____

# Create an instance of the HfApi class
api = ____()

# List only the first 2 models available on the Hub
models = list(api.____(limit=2))

# Print the first 2 models
for model in models:
    print(model)
Edit and Run Code