Skip to main content

Accelerate file downloads by overcoming common throttling restrictions.

Project description

ThrottleBuster

PyPI version PyPI - Python Version PyPI - License Ruff Hits Downloads

ThrottleBuster is a Python library designed to accelerate file downloads by overcoming common throttling restrictions. It leverages multi-threading and asynchronous techniques to optimize download speeds, making it ideal for downloading large files.

Features

  • Concurrent downloading across multiple threads
  • Fully asynchronous with synchronous support
  • Ready to use commandline tool

Installation

$ pip install "throttlebuster[cli]"

Usage

For testing purposes, you can use this config example for Nginx server.

# Test server

# Copy it to /etc/sites-enabled or add it to default nginx.conf file

server {
    listen 8888;
    server_name throttlebuster.test;

    location / {
        limit_rate 500k;  # Limit rate to 500 KB/s
        root /home/smartwa/y2mate;  # Set your own directory
        index index.html;
    }
}

Developer

from throttlebuster import ThrottleBuster

async def main():
    throttlebuster = ThrottleBuster(threads=4)
    downloaded_file = await throttlebuster.run(
        "http://localhost:8888/test.1.opus",
    )
    print(
        downloaded_file
    )

if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Custom progress hook

from throttlebuster import DownloadTracker, ThrottleBuster


async def callback_function(data: DownloadTracker):
    percent = (data.downloaded_size / data.expected_size) * 100
    print(f"> Downloading {data.saved_to.name} {percent:.2f}%", end="\r")


async def main():
    throttlebuster = ThrottleBuster(threads=1)
    downloaded_file await throttlebuster.run(
        "http://localhost:8888/test.1.opus", progress_hook=callback_function
    )
    print(
        downloaded_file
    )


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Synchronous

from throttlebuster import ThrottleBuster

throttlebuster = ThrottleBuster()

downloaed_file = throttlebuster.run_sync("http://localhost:8888/test.1.opus")

print(
    downloaded_file
)

Commandline

$ python -m throttlebuster --help
Usage: python -m throttlebuster [OPTIONS] COMMAND [ARGS]...

  Accelerate file downloads by overcoming common throttling restrictions
  envvar-prefix : THROTTLEBUSTER.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  download  Download file using http protocol
  estimate  Estimate download duration for different threads

Download

$ python -m throttlebuster download http://localhost:8888/test.1.opus --threads 14
$ python -m throttlebuster download --help
Usage: python -m throttlebuster download [OPTIONS] URL

  Download file using http protocol

Options:
  -T, --threads INTEGER RANGE     Number of threads to carry out the download
                                  : 2  [1<=x<=1000]
  -C, --chunk-size INTEGER        Streaming download chunk size in kilobytes :
                                  256
  -D, --dir DIRECTORY             Directory for saving the downloaded file to
                                  : PWD
  -P, --part-dir DIRECTORY        Directory for temporarily saving the
                                  downloaded file-parts to : PWD
  -E, --part-extension TEXT       Filename extension for download parts :
                                  .part
  -H, --request-headers TEXT...   Httpx request headers : default
  -B, --merge-buffer-size INTEGER RANGE
                                  Buffer size for merging the separated files
                                  in kilobytes : 256  [1<=x<=102400]
  -F, --filename TEXT             Filename for the downloaded content
  -M, --download-mode [start|resume|auto]
                                  Whether to start or resume incomplete
                                  download : auto
  -L, --file_size INTEGER         Size of the file to be downloaded : None
  -K, --colour TEXT               Progress bar display color : cyan
  -k, --keep-parts                Whether to retain the separate download
                                  parts : False
  -s, --simple                    Show percentage and bar only in progressbar
                                  : False
  -t, --test                      Just test if download is possible but do not
                                  actually download : False
  -a, --ascii                     Use unicode (smooth blocks) to fill the
                                  progress-bar meter : False
  -l, --no-leave                  Do not keep all leaves of the progressbar :
                                  False
  -z, --disable-progress-bar      Do not show progress_bar : False
  -q, --quiet                     Do not show any interactive information :
                                  False
  -v, --verbose                   Show more detailed information : 0
  --help                          Show this message and exit.

[!TIP] Shortcuts for $ python -m throttlebuster are $ throttlebuster & $ tbust

Estimate

$ python -m throttlebuster estimate --url http://localhost:8888/miel-martin.webm 260000
         337.88 MB at 260.00 KB/s         
┏━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Threads ┃ Duration   ┃ Load per thread ┃
┡━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ 20      │ 1.08 Mins  │ 16.89 MB        │
│ 19      │ 1.14 Mins  │ 17.78 MB        │
│ 18      │ 1.20 Mins  │ 18.77 MB        │
│ 17      │ 1.27 Mins  │ 19.88 MB        │
│ 16      │ 1.35 Mins  │ 21.12 MB        │
│ 15      │ 1.44 Mins  │ 22.53 MB        │
│ 14      │ 1.55 Mins  │ 24.13 MB        │
│ 13      │ 1.67 Mins  │ 25.99 MB        │
│ 12      │ 1.80 Mins  │ 28.16 MB        │
│ 11      │ 1.97 Mins  │ 30.72 MB        │
│ 10      │ 2.17 Mins  │ 33.79 MB        │
│ 9       │ 2.41 Mins  │ 37.54 MB        │
│ 8       │ 2.71 Mins  │ 42.24 MB        │
│ 7       │ 3.09 Mins  │ 48.27 MB        │
│ 6       │ 3.61 Mins  │ 56.31 MB        │
│ 5       │ 4.33 Mins  │ 67.58 MB        │
│ 4       │ 5.41 Mins  │ 84.47 MB        │
│ 3       │ 7.22 Mins  │ 112.63 MB       │
│ 2       │ 10.83 Mins │ 168.94 MB       │
└─────────┴────────────┴─────────────────┘
$ python -m throttlebuster estimate --help
Usage: python -m throttlebuster estimate [OPTIONS] THROTTLE

  Estimate download duration for different threads

Options:
  -U, --url TEXT               Url to the target file
  -S, --size INTEGER           Size in bytes of the targeted file
  -T, --threads INTEGER RANGE  Threads amount to base the estimate on : Range
                               (2-30)  [1<=x<=1000]
  -j, --json                   Stdout estimates in json format
  --help                       Show this message and exit.

Throttle unit is bytes.

Motive

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

throttlebuster-0.1.2.tar.gz (31.4 kB view details)

Uploaded Source

Built Distribution

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

throttlebuster-0.1.2-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file throttlebuster-0.1.2.tar.gz.

File metadata

  • Download URL: throttlebuster-0.1.2.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.31

File hashes

Hashes for throttlebuster-0.1.2.tar.gz
Algorithm Hash digest
SHA256 027f85b0db3b7582eb3d354c69e6af5da99bd3b33081a3a9fa4476808965bb00
MD5 201e3c7a1c4e725e1ef916b0a2c210d9
BLAKE2b-256 ea2fce19c1edc7aac4bdcb219408a9c1c92dabf4dd3c4ceb3357489d8263f59b

See more details on using hashes here.

File details

Details for the file throttlebuster-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for throttlebuster-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4539406e7fc8429f8925fe93634c697ade1bd718513b8e34d5408877911c8bf0
MD5 daa6f06c366124c9262c010a73aaa2f6
BLAKE2b-256 1a8fb8912f366c4e6930225ca1b7e1a2c4d123fe17c80c8b44ee1b3433169694

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