Skip to main content

Efficient Hugging Face downloader using official API methods

Project description

HFDL - Hugging Face Download Manager (version 0.2.3)

An efficient downloader for Hugging Face models and datasets using official API methods.

Key Features

  • Official API Integration:

    • Uses huggingface_hub's snapshot_download
    • Built-in LFS support
    • Automatic cache management
    • Resume capability
    • Progress tracking
  • Resource Management:

    • Optimized thread allocation
    • Built-in caching system
    • Automatic cleanup
    • System load awareness
  • Verification & Safety:

    • Built-in file verification
    • Automatic integrity checks
    • Resume capability
    • Graceful interruption handling
  • Authentication:

    • API-based token validation
    • Public repository support
    • Private repo access
    • Clear error messages

Requirements

  • Python 3.10+
  • Required packages:
    huggingface_hub >=0.28.1
    tqdm >=4.62.0
    pydantic >=2.0.0
    

Installation

pip install hfdl

From source:

git clone https://github.com/MubarakHAlketbi/hfdl.git
cd hfdl
pip install -e .

Authentication (for private repos):

huggingface-cli login

Usage

Command Line

# Basic download
hfdl username/model_name

# Advanced options
hfdl username/model_name \
    -d custom_dir \     # Custom directory (default: downloads)
    -t auto \           # Threads (auto or positive integer)
    -r model \          # Repository type (model, dataset, space)
    --verify \          # Verify downloads
    --force \           # Force fresh download
    --no-resume        # Disable resume capability

Python API

from hfdl import HFDownloader

downloader = HFDownloader(
    model_id="username/model_name",
    download_dir="custom_dir",     # default: "downloads"
    num_threads=0,                 # 0=auto, or positive integer
    repo_type="model",            # "model", "dataset", or "space"
    verify=False,                 # verify downloads
    force=False,                  # force fresh download
    resume=True                   # allow resume
)
downloader.download()

Technical Implementation

Core Components

  1. API Integration:

    • Uses official huggingface_hub methods
    • Proper HfApi instance management
    • Built-in LFS support
    • Automatic caching
  2. Thread Management:

    • Auto-scales based on system capabilities
    • Conservative thread allocation
    • Built-in optimization
  3. Download Management:

    • Automatic resume capability
    • Progress tracking
    • Cache utilization
    • Error handling
  4. State Management:

    • Managed by huggingface_hub
    • Automatic cache handling
    • Built-in progress tracking
    • File verification

Directory Structure

downloads/
└── model-name/
    ├── config.json
    ├── model.safetensors
    └── pytorch_model.bin

Best Practices

  1. Thread Management:

    • Use 'auto' for optimal thread allocation
    • Or specify a positive integer for manual control
    • System will optimize based on available resources
  2. Download Options:

    • Enable resume for reliable downloads
    • Use verify for extra safety
    • Force download when needed
    • Choose appropriate repo type
  3. Error Handling:

    • Clear error messages
    • Proper validation
    • Automatic retry
    • Progress feedback

Development

# Install with dev dependencies
pip install -e .[dev]

# Run tests
pytest tests/

# Linting
flake8 hfdl/
mypy hfdl/

License

MIT - See LICENSE

Acknowledgments

  • Hugging Face Hub API for core functionality
  • tqdm for progress bars

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hfdl-0.2.3.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hfdl-0.2.3-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file hfdl-0.2.3.tar.gz.

File metadata

  • Download URL: hfdl-0.2.3.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for hfdl-0.2.3.tar.gz
Algorithm Hash digest
SHA256 4f7eefb07081daa15210f825341f6c2d0fd9ddd40181af64960c303c98f3c624
MD5 602a205656475b3d239e6606e156398c
BLAKE2b-256 bbe29a97141eb735408309e49f9d48c750be230668d245879484206c1028e956

See more details on using hashes here.

File details

Details for the file hfdl-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: hfdl-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for hfdl-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24d71bd367947c69562cce5b108e03ba367e5142038364b024f91e6f3f788a28
MD5 895a5d0d2bc7ac7e18f979f4a8bc30b7
BLAKE2b-256 6542cdab5e96f02865421cd9fdd4ae0ee6c18a280d7ee84835aaa29c6aa534ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page