A simple, efficient, general-purpose Python multithreaded download library
Project description
auto-download
A simple, efficient, general-purpose Python multithreaded download library.
Installation
pip install autoDownload
Usage
Basic Usage
In Program
import autoDownload
taskConfig = autoDownload.TaskConfig(
url='https://example.com/', # download url
file='example.zip', # save path
method='GET', # download method, default is 'GET'
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36'}, # download headers, default is {}
**kwargs
)
# It will block the current thread until it completes
autoDownload.request(taskConfig)
# It will return an awaitable object (see https://docs.python.org/3.13/library/asyncio-task.html#awaitables), which is useful in asynchronous programming
autoDownload.asyncRequest(taskConfig)
# It will return nothing, and when it completes, the callback function will be called. This is useful in functional programming
autoDownload.callbackRequest(taskConfig, callback)
In Command Line
auto-download [-h] [-f FILE] [-m MAX] [-r RETRY] [-H HEADER] Url
For more information, see:
auto-download -h
Advanced Usage
Customize how tasks are waiting
# It will return a TaskResult object.
res=autoDownload.rawRequest(taskConfig)
# res.event is a threading.Event object, which can be used to wait for the task to complete.
res.event.wait()
# res.ok is a bool object, which indicates whether the task was successful.
if res.ok:
# res.task is a autoDownload.download.Task object, which is the main controller for the task.
print(f"Task{res.task.identity} completed successfully!")
else:
# res.err is a TaskError object, which indicates the reason for the failure.
raise res.err
Customize the threading pool or the adapter
# You can customize almost everything in the threading pool or the adapter
adapter=autoDownload.adapters.Adapter()
pool=autoDownload.pools.Pool(maxThread=10, adapter=adapter)
unit=autoDownload.unit.Unit(pool)
unit.request(taskConfig)
Show the progress of the download in the command line
progress=autoDownload.progress.DownloadProgress(
task1, task2, task3,
showTotal=True, # show the total progress
showParts=True, # show the progress of each part
showMerge=True, # show the progress of the merge
)
with progress:
while True:
progress.refresh()
time.sleep(0.5)
License
The Project is released under the Mulan Public License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autodownload-0.1.2.tar.gz
(19.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autodownload-0.1.2.tar.gz.
File metadata
- Download URL: autodownload-0.1.2.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3bd67dafc719f19bdbbe498f7088f537d1d8e7270cecd4a46de693adeba6e99
|
|
| MD5 |
953545f3dc2f31908edc4a66b2ef5d25
|
|
| BLAKE2b-256 |
bf671934aafdb7a4206db7633233cda109a96b94ce38b607f5eeba1116bc2612
|
File details
Details for the file autoDownload-0.1.2-py3-none-any.whl.
File metadata
- Download URL: autoDownload-0.1.2-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2369cd392ac4ef5fd8e06a062df211394afb5bb672819d9295b79760210e9efb
|
|
| MD5 |
0471ea6bef6ecb06d0f4de794b287f63
|
|
| BLAKE2b-256 |
7abfcce2a0a00437c3f5de04392ca4a5a8901a31ac045493347b68bd93fb1c61
|