How to get all hugging face models list using python?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Hugging Face hosts over half a million models spanning NLP, computer vision, audio, and more. Whether you are building a model search tool, auditing available architectures, or simply exploring what exists, you need a programmatic way to list and filter those models. Python gives you two clean paths: the official huggingface_hub library and the raw HTTP API.
Using the huggingface_hub Library
The recommended approach is the huggingface_hub package, which wraps the Hugging Face REST API in a convenient Python interface. Install it first:
The central class is HfApi, and its list_models() method returns an iterator of model objects:
Each model object carries metadata such as id, author, downloads, likes, pipeline_tag, tags, and last_modified. Because the Hub hosts hundreds of thousands of models, iterating over every single one takes time. In practice you almost always want to filter.
Filtering Models by Task, Author, and Library
The real power of list_models() comes from its keyword arguments that let the server do the heavy lifting. Why filter server-side? Because downloading the entire model catalog just to discard 99% of it locally wastes both time and bandwidth.
You can also search by free-text query or by tags:
The Deprecated transformers.list_models() Approach
Older tutorials may reference transformers.list_models(). This function was removed in recent versions of the transformers library. If you encounter it in legacy code, replace it with huggingface_hub.HfApi().list_models(), which provides the same functionality with better filtering support and is actively maintained.
Using the HTTP API Directly
If you prefer to avoid adding a dependency, you can call the REST API with requests. The endpoint is https://huggingface.co/api/models:
The API returns JSON arrays. For pagination, use the Link header to walk through large result sets page by page.
Handling Pagination for Large Result Sets
The Hub caps responses at a default page size. The huggingface_hub library handles pagination automatically through its iterator, so you can loop without worrying about pages. With the raw HTTP API you must follow pagination manually:
Accessing Model Card Metadata
Each model on the Hub has a model card with structured metadata. You can retrieve it with model_info() when you need details beyond what list_models() returns:
This is especially useful for inspecting license information, dataset references, evaluation metrics, or the full README content of a specific model.
Common Pitfalls
- Iterating all models without filters can take many minutes and consume significant memory. Always apply task, author, or tag filters when possible.
- Using the deprecated
transformers.list_models()will raise anImportErroron newer versions. Switch tohuggingface_hub. - Ignoring pagination with the HTTP API means you only get the first page of results, silently missing thousands of models.
- Assuming model metadata is always complete leads to
KeyErrorcrashes. Many community models have sparse or missing card data, so always use.get()with defaults. - Making rapid unauthenticated requests triggers rate limits. Pass your token via
HfApi(token="hf_...")or set theHF_TOKENenvironment variable to get higher rate limits.
Summary
- Use
huggingface_hub.HfApi().list_models()as the primary method to list models programmatically. - Filter server-side by
task,author,library,tags, andsearchto avoid downloading the entire catalog. - The raw HTTP API at
https://huggingface.co/api/modelsworks when you want to avoid extra dependencies, but you must handle pagination yourself. - Access detailed model card metadata with
api.model_info("model-name")for license, dataset, and evaluation details. - Always handle missing metadata gracefully and authenticate your requests to avoid rate limits.
Related reading
- How to get bag of words from textual data?
- How to Get Dependency Parse Output from SyntaxNet
- How to get last 4 characters of a string?
- How to grep a yaml value
- How to get allocated GPU spec in Google Colab
- How to get both MSE and R2 from a sklearn GridSearchCV?
- How to get all possible 2N combinations of a list’s elements, of any length
- How to get all possible combinations from two arrays?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.