Skip to content

feat: expose skip_sha256 parameter in Python upload API#705

Merged
XciD merged 4 commits intomainfrom
expose-skip-sha256-publicly
Mar 12, 2026
Merged

feat: expose skip_sha256 parameter in Python upload API#705
XciD merged 4 commits intomainfrom
expose-skip-sha256-publicly

Conversation

@XciD
Copy link
Member

@XciD XciD commented Mar 12, 2026

Summary

Add skip_sha256 and sha256s parameters to upload_bytes() Python binding for per-file SHA-256 policies:

  • skip_sha256: bool = False - Skip SHA-256 computation entirely (sets Sha256Policy::Skip)
  • sha256s: Optional[List[str]] = None - Provide pre-computed SHA-256 hashes (companion to existing parameter on upload_files())
  • These parameters are mutually exclusive

Changes

Python binding changes:

  • Add skip_sha256 + sha256s params to upload_bytes() / upload_files()
  • All policy conversion happens at Python boundary

Internal refactoring:

  • Add Clone/Copy derives + from_skip()/from_hex() helpers to Sha256Policy
  • Update upload_bytes_async, upload_async, clean_file to use Vec<Sha256Policy>
  • Update all internal callers across git_xet, xet_pkg, migration tool, tests

Motivation

huggingface_hub already knows whether SHA-256 is required. This change enables skipping expensive computation when unnecessary, or passing pre-computed hashes for bulk operations.

Companion to #678.

@XciD XciD force-pushed the expose-skip-sha256-publicly branch from fb9dd90 to f9aeea5 Compare March 12, 2026 13:29
@XciD XciD changed the title Expose skip_sha256 publicly feat: expose skip_sha256 parameter in Python upload API Mar 12, 2026
@XciD XciD requested a review from Wauplin March 12, 2026 13:33
…rings

Move the bool-to-Sha256Policy conversion to the Python boundary (hf_xet)
and accept Sha256Policy directly in data_client and clean_file. This
eliminates duplicated conversion logic, adds validation in the Rust layer,
and makes clean_file consistent with clean_bytes.

- Add Clone/Copy derives and from_skip/from_hex helpers on Sha256Policy
- Change upload_bytes_async to accept Sha256Policy instead of bool
- Change upload_async to accept Vec<Sha256Policy> instead of Option<Vec<String>> + bool
- Change clean_file to accept Sha256Policy instead of impl AsRef<str>
- Update all callers: hf_xet, git_xet, xet_pkg, migration_tool, test_utils
@XciD XciD force-pushed the expose-skip-sha256-publicly branch from e8f063c to 3524451 Compare March 12, 2026 13:45
Mirror the sha256s support from upload_files() to upload_bytes(), allowing
callers to pass pre-computed SHA-256 hashes for byte uploads. Also aligns
upload_bytes_async to accept Vec<Sha256Policy> (per-file) like upload_async.
@XciD XciD requested review from hoytak and seanses March 12, 2026 13:55
@Wauplin
Copy link
Collaborator

Wauplin commented Mar 12, 2026

Thank you! Will unlock huggingface/huggingface_hub#3900 and huggingface/huggingface_hub#3876

@XciD XciD merged commit 0fb930c into main Mar 12, 2026
7 checks passed
@XciD XciD deleted the expose-skip-sha256-publicly branch March 12, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants