{"course":{"slug":"hugging-face","title":"Hugging Face, End to End","url":"https://addaly.com/learn/hugging-face","level":"intermediate","track":"create"},"lesson":{"slug":"the-hub-api","title":"Ask the Hub questions instead of browsing it","url":"https://addaly.com/learn/hugging-face/the-hub-api","position":8,"of":75,"minutes":9,"answer":"Use metadata to choose a repository, check the licence and file sizes, and pin a revision before downloading only the files you need.","keyIdea":"Use metadata to choose a repository, check the licence and file sizes, and pin a revision before downloading only the files you need."},"body":{"format":"markdown","text":"## Ask the Hub for information before downloading a model\n\nThe website and the Hub API both expose information about repositories. In this lesson, start with read-only requests. They list models and inspect files without running model code or downloading weights. The current [HfApi reference](https://huggingface.co/docs/huggingface_hub/en/package_reference/hf_api) documents the Python names used below. Run the examples in a Python environment with a current `huggingface_hub` installed.\n\n## List models with a few filters\n\n```python\nfrom huggingface_hub import HfApi\n\napi = HfApi(token=False)\nmodels = api.list_models(\n    pipeline_tag=\"automatic-speech-recognition\",\n    filter=(\"transformers\", \"hi\"),\n    sort=\"downloads\",\n    limit=20,\n    cardData=True,\n)\nfor model in models:\n    card = model.card_data\n    licence = card.license if card and card.license else \"not listed\"\n    print(model.id, model.downloads, licence)\n```\n\nThe task, library and language tags narrow the results. They do not show which model handles your audio well. The download count is a recent activity measure, not an accuracy score. A missing licence field does not give permission. Read the model card and licence terms before using a model.\n\n## Check file sizes and record the revision\n\n```python\nrepo = \"openai/whisper-tiny\"\ninfo = api.model_info(repo, files_metadata=True)\n\nprint(\"Revision:\", info.sha)\nprint(\"Last commit:\", info.last_modified)\nfor file in info.siblings or []:\n    if file.size is None:\n        print(file.rfilename, \"size not reported\")\n    else:\n        print(file.rfilename, file.size, \"bytes\")\n```\n\n`siblings` lists files at the selected revision. It can include several formats for the same weights, so a total for all files is not your own download estimate. Add up only the files you need and account for sizes that are not reported. In the Python result, use `card_data` and `last_modified`; field names shown by the raw JSON endpoint can differ.\n\n## Download only the small config for this exercise\n\n```python\nfrom huggingface_hub import hf_hub_download\n\nconfig_path = hf_hub_download(\n    \"openai/whisper-tiny\",\n    \"config.json\",\n    revision=\"169d4a4341b33bc18d8881c4b69c2e104e1cc0af\",\n    token=False,\n)\nprint(config_path)\n```\n\nUsing a specific commit makes this example reproducible. For several files, `snapshot_download` can take `allow_patterns` and `ignore_patterns`. An unfiltered snapshot may download every format at that revision. Start with the default transfer settings. The old `hf_transfer` setting is deprecated; the [Hub transfer documentation](https://huggingface.co/docs/huggingface_hub/en/package_reference/environment_variables) explains the current options.\n\n## Translate the same read-only task to the command line\n\n```bash\nhf download openai/whisper-tiny config.json \\\n  --revision 169d4a4341b33bc18d8881c4b69c2e104e1cc0af\nhf cache ls --revisions\n```\n\nThe second command shows what is already stored locally. The [cache guide](https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache) explains how to review sizes before removing anything. For private repositories you need appropriate access; none of the examples here needs a private token.\n\n## Try it now\n\nChange the language filter and compare a few results. Record one model’s exact revision, which file you would download, its reported size, and which licence you would check. If the query returns no results, remove one filter at a time and say which constraint caused the empty result."},"check":{"question":"Why does `model_info(repo, files_metadata=True)` frequently report a total far larger than what you need to download?","options":[{"text":"It reports the size of the full commit history, including superseded checkpoint versions still held in large-file storage.","correct":false,"tempting":"Confuses repository storage with the current revision's file listing, which is what siblings describes."},{"text":"It counts every file at that revision, including duplicate weight formats you would never fetch.","correct":true},{"text":"Sizes are returned before large-file deduplication, so the true transfer is always substantially smaller than reported.","correct":false,"tempting":"Deduplication affects upload and storage, not the bytes a fresh client must receive."},{"text":"The call sums sizes across every branch and open pull request in the repository.","correct":false,"tempting":"Assumes a repository-wide aggregate when the call is scoped to one revision."}],"why":"The file list describes the entire selected revision. If several formats are present, the size of a single needed format is only part of that total."},"prev":{"slug":"four-shelves","title":"Four shelves, and picking the wrong one costs a weekend","url":"https://addaly.com/learn/hugging-face/four-shelves"},"next":{"slug":"counters-and-trending","title":"What a download count is counting","url":"https://addaly.com/learn/hugging-face/counters-and-trending"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Ask the Hub questions instead of browsing it', in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/the-hub-api (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Ask the Hub questions instead of browsing it","courseTitle":"Hugging Face, End to End","module":{"index":1,"slug":"the-hub-as-a-repository-host","title":"The Hub, read properly"},"answer":null,"keyIdea":"Use metadata to choose a repository, check the licence and file sizes, and pin a revision before downloading only the files you need.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"ask-the-hub-for-information-before-downloading-a-model","runs":[{"text":"Ask the Hub for information before downloading a model"}]},{"t":"p","runs":[{"text":"The website and the Hub API both expose information about repositories. In this lesson, start with read-only requests. They list models and inspect files without running model code or downloading weights. The current "},{"text":"HfApi reference","href":"https://huggingface.co/docs/huggingface_hub/en/package_reference/hf_api"},{"text":" documents the Python names used below. Run the examples in a Python environment with a current "},{"text":"huggingface_hub","code":true},{"text":" installed."}]},{"t":"h2","id":"list-models-with-a-few-filters","runs":[{"text":"List models with a few filters"}]},{"t":"code","lang":"python","label":"Python","text":"from huggingface_hub import HfApi\n\napi = HfApi(token=False)\nmodels = api.list_models(\n    pipeline_tag=\"automatic-speech-recognition\",\n    filter=(\"transformers\", \"hi\"),\n    sort=\"downloads\",\n    limit=20,\n    cardData=True,\n)\nfor model in models:\n    card = model.card_data\n    licence = card.license if card and card.license else \"not listed\"\n    print(model.id, model.downloads, licence)"},{"t":"p","runs":[{"text":"The task, library and language tags narrow the results. They do not show which model handles your audio well. The download count is a recent activity measure, not an accuracy score. A missing licence field does not give permission. Read the model card and licence terms before using a model."}]},{"t":"h2","id":"check-file-sizes-and-record-the-revision","runs":[{"text":"Check file sizes and record the revision"}]},{"t":"code","lang":"python","label":"Python","text":"repo = \"openai/whisper-tiny\"\ninfo = api.model_info(repo, files_metadata=True)\n\nprint(\"Revision:\", info.sha)\nprint(\"Last commit:\", info.last_modified)\nfor file in info.siblings or []:\n    if file.size is None:\n        print(file.rfilename, \"size not reported\")\n    else:\n        print(file.rfilename, file.size, \"bytes\")"},{"t":"p","runs":[{"text":"siblings","code":true},{"text":" lists files at the selected revision. It can include several formats for the same weights, so a total for all files is not your own download estimate. Add up only the files you need and account for sizes that are not reported. In the Python result, use "},{"text":"card_data","code":true},{"text":" and "},{"text":"last_modified","code":true},{"text":"; field names shown by the raw JSON endpoint can differ."}]},{"t":"h2","id":"download-only-the-small-config-for-this-exercise","runs":[{"text":"Download only the small config for this exercise"}]},{"t":"code","lang":"python","label":"Python","text":"from huggingface_hub import hf_hub_download\n\nconfig_path = hf_hub_download(\n    \"openai/whisper-tiny\",\n    \"config.json\",\n    revision=\"169d4a4341b33bc18d8881c4b69c2e104e1cc0af\",\n    token=False,\n)\nprint(config_path)"},{"t":"p","runs":[{"text":"Using a specific commit makes this example reproducible. For several files, "},{"text":"snapshot_download","code":true},{"text":" can take "},{"text":"allow_patterns","code":true},{"text":" and "},{"text":"ignore_patterns","code":true},{"text":". An unfiltered snapshot may download every format at that revision. Start with the default transfer settings. The old "},{"text":"hf_transfer","code":true},{"text":" setting is deprecated; the "},{"text":"Hub transfer documentation","href":"https://huggingface.co/docs/huggingface_hub/en/package_reference/environment_variables"},{"text":" explains the current options."}]},{"t":"h2","id":"translate-the-same-read-only-task-to-the-command-line","runs":[{"text":"Translate the same read-only task to the command line"}]},{"t":"code","lang":"bash","label":"Bash","text":"hf download openai/whisper-tiny config.json \\\n  --revision 169d4a4341b33bc18d8881c4b69c2e104e1cc0af\nhf cache ls --revisions"},{"t":"p","runs":[{"text":"The second command shows what is already stored locally. The "},{"text":"cache guide","href":"https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache"},{"text":" explains how to review sizes before removing anything. For private repositories you need appropriate access; none of the examples here needs a private token."}]},{"t":"h2","id":"try-it-now","runs":[{"text":"Try it now"}],"role":"try"},{"t":"p","runs":[{"text":"Change the language filter and compare a few results. Record one model’s exact revision, which file you would download, its reported size, and which licence you would check. If the query returns no results, remove one filter at a time and say which constraint caused the empty result."}]}],"check":{"question":[{"text":"Why does "},{"text":"model_info(repo, files_metadata=True)","code":true},{"text":" frequently report a total far larger than what you need to download?"}],"options":[{"text":[{"text":"It reports the size of the full commit history, including superseded checkpoint versions still held in large-file storage."}],"correct":false,"tempting":[{"text":"Confuses repository storage with the current revision’s file listing, which is what siblings describes."}]},{"text":[{"text":"It counts every file at that revision, including duplicate weight formats you would never fetch."}],"correct":true,"tempting":null},{"text":[{"text":"Sizes are returned before large-file deduplication, so the true transfer is always substantially smaller than reported."}],"correct":false,"tempting":[{"text":"Deduplication affects upload and storage, not the bytes a fresh client must receive."}]},{"text":[{"text":"The call sums sizes across every branch and open pull request in the repository."}],"correct":false,"tempting":[{"text":"Assumes a repository-wide aggregate when the call is scoped to one revision."}]}],"order":[2,0,3,1],"why":[{"text":"The file list describes the entire selected revision. If several formats are present, the size of a single needed format is only part of that total."}]},"prev":{"slug":"four-shelves","title":"Four shelves, and picking the wrong one costs a weekend","minutes":8},"next":{"slug":"counters-and-trending","title":"What a download count is counting","minutes":8}}}