How does snapshot download work in Huggingface hub?

It uses class HfApi - Client to interact with the Hugging Face Hub via HTTP, which you can see imported from hf_api.py. Then list_repo_tree() and other methods.

It uses that client to get a listing, defaulting to https://huggingface.co, and then starts grabbing a specified model, a dataset, or space, checking its hash.
Python httpx module is used for the secure http/2 download connection.

Your “How” could mean many things, like “how does an API work”.

A model card will usually have the quick-and-easy transformers or sentence_transformers “auto-get”, so you don’t have to think too hard, and just get magic:

from sentence_transformers import SentenceTransformer
model = SentenceTransformer("google/embeddinggemma-300m")
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained(model_dir, trust_remote_code=True)