# Supercharged Searching on the 🤗 Hub

huggingface.co · Zachary Mueller · Jan 25, 2022

**Type:** Tutorial

## Summary

Programmatically searching the Hugging Face Hub previously required navigating web browser widgets or enduring trial and error to guess exact query string formats. The huggingface\_hub library solves this issue by introducing helper utilities such as ModelSearchArguments, DatasetSearchArguments, and ModelFilter alongside HfApi. These namespace helpers translate accessible Python attributes into the formatted parameters expected by the backend API, covering datasets, tasks, and libraries. For complex queries across multiple tasks, frameworks, and datasets, developers can combine criteria inside ModelFilter instances and retrieve matching model metadata via api.list\_models. Under the hood, the library uses AttributeDictionary, a data structure inspired by fastcore that enables nested tab-completion while supporting standard dictionary key indexing for special characters.

## Context

Searching the Hugging Face Hub programmatically using the huggingface\_hub library previously required trial and error to format search parameters correctly, or forced users to leave their IDE and Jupyter interfaces to search manually via web browser widgets.

## Approach / What changed

The huggingface\_hub library introduces ModelSearchArguments, DatasetSearchArguments, and ModelFilter helper classes to interface with HfApi. Built on AttributeDictionary (inspired by fastcore's AttrDict), these classes provide human-readable attributes with tab-completion that automatically format search parameters for API queries.

## Takeaways

- ModelSearchArguments provides pre-formatted API search parameters as attributes (such as mapping model\_args.dataset.glue to dataset:glue) to eliminate parameter syntax guesswork.
- ModelFilter allows combining multiple search constraints, including lists of task tags, training datasets, and supported frameworks, into a single structured query passed to HfApi.list\_models.
- AttributeDictionary enables nested tab-completion and attribute deletion, but keys containing numbers or special characters must be accessed using standard dictionary bracket indexing instead of dot notation.

**Tags:** [Developer Experience](https://yomu.fyi/topic/developer-experience), [Machine Learning](https://yomu.fyi/topic/machine-learning), [Python](https://yomu.fyi/topic/python), [Search](https://yomu.fyi/topic/search)

[Read original post](https://huggingface.co/blog/searching-the-hub)
