Skip to main content

A Python library and CLI tool to search for models and datasets on Hugging Face Hub

Project description

hfsearch

A Python library and CLI tool to search for models and datasets on the Hugging Face Hub.

Installation

Install from PyPI:

pip install hfsearch

Or install from source:

git clone https://github.com/yourusername/hfsearch.git
cd hfsearch
pip install -e .

Usage

As a Library

from hfsearch import search_models, search_datasets, export_to_csv

# Search for models
results = search_models(query="bert", limit=10)
print(f"Found {len(results)} models")
for model in results:
    print(f"{model['id']} - {model['author']}")

# Search for datasets
datasets = search_datasets(query="sentiment", limit=5)
for dataset in datasets:
    print(f"{dataset['id']} - Downloads: {dataset['downloads']}")

# Export results
export_to_csv(results, "Model", "results.csv")

As a CLI Tool

After installation, use the hfsearch command:

# Search for models
hfsearch models --query "bert"

# Search with filters
hfsearch models --query "translation" --limit 20 --author "google"

# Search datasets
hfsearch datasets --query "sentiment" --limit 15

# Export results
hfsearch models --query "bert" --export
hfsearch models --query "bert" --export --export-format txt

Features

  • Search Models: Find models by keywords, author, tags, or task
  • Search Datasets: Find datasets by keywords, author, or tags
  • Export Results: Export search results to CSV or TXT files
  • Beautiful Output: Formatted terminal output with Rich
  • Python API: Use as a library in your Python projects

CLI Examples

Search Models

# Search by keyword
hfsearch models --query "bert"

# Search with limit
hfsearch models --query "translation" --limit 20

# Filter by author
hfsearch models --author "google" --limit 5

# Filter by tags
hfsearch models --tags "text-classification" "pytorch"

# Filter by task
hfsearch models --task "text-classification"

# Combine filters
hfsearch models --query "bert" --author "google" --limit 10

Search Datasets

# Search by keyword
hfsearch datasets --query "sentiment"

# Filter by tags
hfsearch datasets --tags "text-classification" --limit 15

# Filter by author
hfsearch datasets --author "huggingface"

Export Results

# Export to CSV (default)
hfsearch models --query "bert" --export

# Export to TXT
hfsearch models --query "bert" --export --export-format txt

API Reference

search_models(query=None, limit=10, author=None, tags=None, task=None)

Search for models on Hugging Face Hub.

Parameters:

  • query (str, optional): Search query/keywords
  • limit (int): Maximum number of results (default: 10)
  • author (str, optional): Filter by author/organization
  • tags (list, optional): Filter by tags
  • task (str, optional): Filter by task (e.g., "text-classification")

Returns:

  • List of dictionaries with keys: id, author, downloads, likes, tags

search_datasets(query=None, limit=10, author=None, tags=None)

Search for datasets on Hugging Face Hub.

Parameters:

  • query (str, optional): Search query/keywords
  • limit (int): Maximum number of results (default: 10)
  • author (str, optional): Filter by author/organization
  • tags (list, optional): Filter by tags

Returns:

  • List of dictionaries with keys: id, author, downloads, likes, tags

export_to_csv(results, result_type, filename)

Export results to a CSV file.

Parameters:

  • results (list): List of result dictionaries
  • result_type (str): "Model" or "Dataset"
  • filename (str): Output filename

export_to_txt(results, result_type, filename)

Export results to a text file.

Parameters:

  • results (list): List of result dictionaries
  • result_type (str): "Model" or "Dataset"
  • filename (str): Output filename

Requirements

  • Python 3.7+
  • huggingface_hub>=0.20.0 - For accessing Hugging Face Hub API
  • rich>=13.0.0 - For beautiful terminal output

Notes

  • The tool uses the Hugging Face Hub API, so you need an internet connection
  • For downloading models, use the official huggingface-cli download command
  • Authentication is optional but recommended for private models/datasets

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hfsearch-1.0.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hfsearch-1.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file hfsearch-1.0.1.tar.gz.

File metadata

  • Download URL: hfsearch-1.0.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for hfsearch-1.0.1.tar.gz
Algorithm Hash digest
SHA256 52f70b6f48151197cfd86803654172e9f39afb7ad059e544aab181d2f3afdea2
MD5 f759f90a6837264f00948eca4624c470
BLAKE2b-256 d0c1cfa09a61a76ad807bd61afb429cf46b515e803df1aa8e5cddac89b678529

See more details on using hashes here.

File details

Details for the file hfsearch-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: hfsearch-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for hfsearch-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e96016e4767b69f49d2551016fad84261ba13407d1240bb3da935fc1a4b2600
MD5 2ae9c5bb252f24a97bc508a7b291a1df
BLAKE2b-256 4857a95d041476c76198511cffbac31896f42b3f41134e2167608d95edc20646

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page