Skip to main content

hfpin

Pin the Hugging Face models and datasets in your code to exact commits.

# Before: downloads whatever is on the Hub today
model = AutoModel.from_pretrained("google-bert/bert-base-uncased")

# After `hfpin pin`: always the same files
model = AutoModel.from_pretrained("google-bert/bert-base-uncased", revision="86b5e0934494bd15c9632b12f734a8a67f723594")

Why

from_pretrained("org/model") downloads the latest commit of the main branch. That commit can change at any time:

  • Silent changes. The owner updates weights, tokenizer or config, and your results change with no code change on your side.
  • Supply chain attacks. If the owner's account is compromised, the attacker's files go straight into your app. With trust_remote_code=True, that includes Python code that runs on your machine.
  • Reproducibility. A paper, a test, or a training run from last month may not give the same result today.

Pinning a commit sha (revision="<sha>") fixes all three. It is the same idea as pinning GitHub Actions to a sha, and Hugging Face recommends it. Doing it by hand means looking up a 40-character sha for every model, which is why almost nobody does. hfpin does it for you.

Install

pip install hfpin

Requires Python 3.10+. No dependencies.

Usage

Find unpinned downloads

$ hfpin check
train.py:5:7: unpinned model 'bert-base-uncased' (AutoTokenizer.from_pretrained): add revision=<commit sha>
train.py:10:7: model 'distilbert/distilbert-base-uncased-finetuned-sst-2-english' (pipeline) uses revision 'main', which can change: use a commit sha
train.py:11:6: unpinned dataset 'stanfordnlp/imdb' (load_dataset): add revision=<commit sha>
train.py:13:7: warning: trust_remote_code runs Python code from 'microsoft/phi-2' and the code can change at any time

3 problem(s) found. Run `hfpin pin` to fix.

check works offline and exits with code 1 when it finds a problem, so it fits in CI and pre-commit hooks.

Options:

Option What it does
--online Also checks that every repo and revision exists on the Hub. Catches typos and model names made up by AI assistants.
--deny-license PATTERN Fails on models or datasets whose license matches, for example --deny-license "cc-by-nc*". Repeatable. Implies --online.
--allow-mutable Accepts branch and tag revisions such as revision="v1.0".
--format text|json|github Output format. github prints workflow annotations.
--exclude GLOB Skips matching files. Repeatable.

Pin them

$ hfpin pin
train.py:5:7: bert-base-uncased@main -> 86b5e0934494 (now 'google-bert/bert-base-uncased')
train.py:10:7: distilbert/distilbert-base-uncased-finetuned-sst-2-english@main -> 714eb0fa89d2
train.py:11:6: stanfordnlp/imdb@main -> e6281661ce1c
Pinned 3 download(s) in 1 file(s).

pin looks up the current commit of each repo (or of the branch or tag you already use) and edits only the call, keeping your formatting. Use --dry-run to see a diff first. For private or gated repos, log in with huggingface-cli login or set HF_TOKEN.

To update a model later, delete its revision= and run hfpin pin again.

GitHub Action

- uses: actions/checkout@v4
- uses: DipPansuriya/hfpin@v0.1.0
  with:
    paths: src          # default: .
    args: --online --deny-license "cc-by-nc*"   # optional
    hf-token: ${{ secrets.HF_TOKEN }}           # optional, for private or gated repos

Problems show up as annotations on the pull request diff.

What it detects

Call Repo type
*.from_pretrained(...) (transformers, diffusers, peft, timm, ...) model
pipeline(task, model=...) model
SentenceTransformer(...) model
hf_hub_download(...), snapshot_download(...) model, dataset or space (repo_type=)
load_dataset(...) dataset

It only looks at repo names written as string literals. It skips local paths, built-in dataset loaders such as load_dataset("csv", ...), and calls whose revision= is a variable.

To ignore a call, add # hfpin: ignore on any of its lines.

Compared with Bandit

Bandit rule B615 warns about unpinned Hugging Face downloads. hfpin also fixes them, checks that the repos exist, and checks licenses.

License

MIT

Metadata

Release files for hfpin 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hfpin 0.1.0
File Size Uploaded Provenance Actions
hfpin-0.1.0.tar.gz 13.0 kB With provenance Details for hfpin-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hfpin 0.1.0
File Interpreter ABI Platform Actions
hfpin-0.1.0-py3-none-any.whl Python 3 none any Details for hfpin-0.1.0-py3-none-any.whl

Total release size: 25.1 kB

Release files / hfpin-0.1.0.tar.gz

Download URL hfpin-0.1.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
177ff39bfb6c2d1076b3277e4349ab0e5ee7cee4f70c2a5c1fbcef1800189355
BLAKE2b-256 checksum
How to use checksums
73228190e9bcbd6c6e8b011d352470e124b97730d72c0ec582fe4974b73fe883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / hfpin-0.1.0-py3-none-any.whl

Download URL hfpin-0.1.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a92094182ae1fa8b964cfba01db59502f9fd784c9be51f320bec67637afece09
BLAKE2b-256 checksum
How to use checksums
b1f7107e4ccffab09951bccf200afbc7550773c5ee5a946a854365694e074fbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for hfpin 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hfpin-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page