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.1.tar.gz (5.6 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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for batch_downloader-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2dc457d68b0a5c930ed00f26c0fb6e493026737bbcd67b10eae07ac8449b8d28
MD5 0c3fa8ab73f4e7eace0b14372e57581d
BLAKE2b-256 02f8eba7855b81efe3bd9f689504420670ccc1d35b8372d7b4dd38b89fe24c4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batch_downloader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7553bb2ae9c06694890c610a069c7e8aa7bf007b096f45bf07d0e2fc30bdfa7
MD5 881f728d24310955b8a9c7778573684c
BLAKE2b-256 46ddba8d6672813f2f322632f5a6ee5a966f7c042807b33b3ea45ad96f3db12b

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