Skip to main content

HuggingFaceStorage

Python library for cloud-style file storage backed by a private Hugging Face dataset repository.

Features

  • Immutable file version history per logical remote path
  • Soft delete via tombstone versions
  • Content-addressed blob storage (sha256) to avoid duplicate uploads
  • HF_TOKEN-based authentication
  • Public API: put, put_zip, get, list, delete, history

Project Structure

HuggingFaceStorage/
  src/hf_storage/
  tests/unit/
  tests/integration/
  requirements.txt
  pyproject.toml

Setup

  1. Create the virtual environment (Python 3.11):
py -3.11 -m venv .venv
  1. Activate:
.\.venv\Scripts\Activate.ps1
  1. Install dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .
  1. Deactivate when finished:
deactivate

Authentication

Set your Hugging Face token before using the library:

$env:HF_TOKEN = "hf_xxx"

Quick Example

from hf_storage import HFStorage, StorageConfig

storage = HFStorage(StorageConfig(repo_id="your-namespace/your-private-dataset"))
storage.setup(create_if_missing=True, private=True)

version = storage.put("local.txt", "docs/local.txt")
zip_version = storage.put_zip("my_folder", "archives/my_folder")
storage.get("docs/local.txt", "restored.txt")
entries = storage.list(prefix="docs/")
history = storage.history("docs/local.txt")
deleted = storage.delete("docs/local.txt")

Running Tests

Unit tests:

pytest tests/unit

Integration tests (real HF repo):

$env:HF_STORAGE_INTEGRATION = "1"
$env:HF_STORAGE_TEST_REPO = "your-namespace/your-private-dataset"
pytest tests/integration

Publishing (Maintainers)

publish.bat is maintainer tooling for package release workflow only. It is not part of the public runtime API.

Set Twine credentials via environment variables:

$env:TWINE_USERNAME = "__token__"
$env:TWINE_TEST_PASSWORD = "pypi-<testpypi-token>"
$env:TWINE_PASSWORD = "pypi-<pypi-production-token>"

Default release target is TestPyPI:

.\publish.bat

Publish to production PyPI explicitly:

.\publish.bat pypi

What publish.bat does:

  • Runs unit tests (pytest tests/unit)
  • Builds wheel + sdist (python -m build)
  • Validates artifacts (twine check dist/*)
  • Uploads to TestPyPI by default, or PyPI when pypi is passed

Credential behavior:

  • .\publish.bat (default TestPyPI) uses TWINE_TEST_PASSWORD
  • .\publish.bat pypi (production) uses TWINE_PASSWORD
  • TWINE_USERNAME must be __token__ for both

Important: bump package version before each release. PyPI/TestPyPI do not allow re-uploading the same version.

One-command Zip Upload (Windows)

Use the batch wrapper to zip and upload a file or directory:

.\put_zip.bat "C:\path\to\folder_or_file" "backups/my_archive"

Notes:

  • HF_TOKEN and HF_STORAGE_REPO_ID are read from .env (or current env vars).
  • If the remote path does not end with .zip, .zip is appended automatically.

List and Download (Windows)

List stored logical paths:

.\list_files.bat

Include soft-deleted entries too:

.\list_files.bat 1

Download latest version by logical path:

.\get_file.bat "backup/venv.zip" ".\downloads\venv.zip"

Download a specific version:

.\get_file.bat "backup/venv.zip" ".\downloads\venv.zip" "version_id_here"

Soft delete a logical path:

.\delete_file.bat "backup/venv.zip"

Hard delete a logical path (removes manifest entry and unreferenced blob objects):

.\delete_file.bat "backup/venv.zip" hard

Metadata

Release files for hf-storage 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 hf-storage 0.1.0
File Size Uploaded
hf_storage-0.1.0.tar.gz 10.1 kB Details

Built distribution (wheel)

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

Total release size: 20.2 kB

Release files / hf_storage-0.1.0.tar.gz

Download URL hf_storage-0.1.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
004a68dc5394800e1b3f84e4c726746db9bea7b3133f589b2c89bb6cb78e14ee
BLAKE2b-256 checksum
How to use checksums
555cef609de228fca5eeb4a11550910daf55b38a7d4c3e19bd124d04c09cfccb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

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

Download URL hf_storage-0.1.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf25f9f55fc79c457d0d1a0f3cec70aa00f3ca5d58b883d273834fc2e7aa3b26
BLAKE2b-256 checksum
How to use checksums
d9782804e4f8c19d3ce786318e0376d294349b5829612dd990a42ff6a15aea8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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