Skip to main content

A simple batch downloader with chunked downloads

Project description

Batch Downloader

A simple Python package for downloading multiple files in parallel with chunked downloads.

Installation

pip install batch_downloader

Usage

def progress_callback(url: str, downloaded_size: int, total_size: int):
    if total_size > 0:
        progress = (downloaded_size / total_size) * 100
        print(f"Downloading {url}: {progress:.2f}%")
    else:
        print(f"Downloading {url}: {downloaded_size} bytes (total size unknown)")

downloader = BatchDownloader(
    urls=[
        "xxx",
        "xxx",
        ],
    output_dir="downloads",
    progress_callback=progress_callback,
)

results = downloader.download_all()

Async Usage

class TestAsyncBatchDownloader(unittest.TestCase):

    def progress_callback(self, url: str, downloaded_size: int, total_size: int):
        if total_size > 0:
            progress = (downloaded_size / total_size) * 100
            print(f"Downloading {url.split('/')[-1]}: {progress:.2f}% ({downloaded_size}/{total_size} bytes)")
        else:
            print(f"Downloading {url.split('/')[-1]}: {downloaded_size} bytes (total size unknown)")

    async def async_test_download(self):
        downloader = AsyncBatchDownloader(
            urls=[
                "xxx",
                "xxx",
            ],
            output_dir="downloads",
            progress_callback=self.progress_callback,
        )
        results = await downloader.download_all()
        self.assertTrue(isinstance(results, list))

    def test_download(self):
        asyncio.run(self.async_test_download())

if __name__ == "__main__":
    unittest.main()

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

batch_downloader-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

batch_downloader-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file batch_downloader-0.1.0.tar.gz.

File metadata

  • Download URL: batch_downloader-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for batch_downloader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35ae9192359951aef491fe83a8ed603ea5f1f01a1c57aa37307e532e7e32b15c
MD5 00fd866bd6cfb4f69324b2344a7b0f17
BLAKE2b-256 364f5e614d2461c665fd2579fd3ed9acfa5abe0f372d074e9701c7207c91a815

See more details on using hashes here.

File details

Details for the file batch_downloader-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for batch_downloader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 602e3b1cc262eb63482897e4cf2c46989a57d929dd5902b131c7f0bef248adcb
MD5 714c3a1723514fb1a55821ed121e260c
BLAKE2b-256 d8bf0c94a36fe4ce65653b8e072a6644c4af9e5676137c34f2e2aa6d569366ed

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