# auto-download
A simple, efficient, general-purpose Python multithreaded download library.
## Installation
```bash
pip install autoDownload
```
## Usage
### Basic Usage
#### In Program
```python
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
```bash
auto-download [-h] [-f FILE] [-m MAX] [-r RETRY] [-H HEADER] Url
```
For more information, see:
```bash
auto-download -h
```
### Advanced Usage
#### Customize how tasks are waiting
```python
# 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
```python
# 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
```python
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](./LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/auto-download/",
"name": "autoDownload",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "requests, download, http, thread",
"author": "kuankuan",
"author_email": "2163826131@qq.com",
"download_url": "https://files.pythonhosted.org/packages/e0/65/f6b94b671f7119717c10634a20eed0cd4d5a42e9fe0908c8353f550bf70e/autodownload-0.1.0.tar.gz",
"platform": "windows",
"description": "# auto-download\r\n\r\nA simple, efficient, general-purpose Python multithreaded download library.\r\n\r\n## Installation\r\n\r\n```bash\r\npip install autoDownload\r\n```\r\n\r\n## Usage\r\n\r\n### Basic Usage\r\n\r\n#### In Program\r\n\r\n```python\r\nimport autoDownload\r\n\r\ntaskConfig = autoDownload.TaskConfig(\r\n url='https://example.com/', # download url\r\n file='example.zip', # save path\r\n method='GET', # download method, default is 'GET'\r\n 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 {}\r\n **kwargs\r\n)\r\n\r\n# It will block the current thread until it completes\r\nautoDownload.request(taskConfig)\r\n\r\n# It will return an awaitable object (see https://docs.python.org/3.13/library/asyncio-task.html#awaitables), which is useful in asynchronous programming\r\nautoDownload.asyncRequest(taskConfig)\r\n\r\n# It will return nothing, and when it completes, the callback function will be called. This is useful in functional programming\r\nautoDownload.callbackRequest(taskConfig, callback)\r\n\r\n```\r\n\r\n#### In Command Line\r\n\r\n```bash\r\nauto-download [-h] [-f FILE] [-m MAX] [-r RETRY] [-H HEADER] Url\r\n```\r\n\r\nFor more information, see:\r\n\r\n```bash\r\nauto-download -h\r\n```\r\n\r\n### Advanced Usage\r\n\r\n#### Customize how tasks are waiting\r\n\r\n```python\r\n\r\n# It will return a TaskResult object.\r\nres=autoDownload.rawRequest(taskConfig)\r\n\r\n# res.event is a threading.Event object, which can be used to wait for the task to complete.\r\nres.event.wait()\r\n\r\n# res.ok is a bool object, which indicates whether the task was successful.\r\nif res.ok:\r\n # res.task is a autoDownload.download.Task object, which is the main controller for the task.\r\n print(f\"Task{res.task.identity} completed successfully!\")\r\n\r\nelse:\r\n # res.err is a TaskError object, which indicates the reason for the failure.\r\n raise res.err\r\n\r\n```\r\n\r\n### Customize the threading pool or the adapter\r\n\r\n```python\r\n\r\n# You can customize almost everything in the threading pool or the adapter\r\nadapter=autoDownload.adapters.Adapter()\r\npool=autoDownload.pools.Pool(maxThread=10, adapter=adapter)\r\nunit=autoDownload.unit.Unit(pool)\r\n\r\nunit.request(taskConfig)\r\n```\r\n\r\n### Show the progress of the download in the command line\r\n\r\n```python\r\nprogress=autoDownload.progress.DownloadProgress(\r\n task1, task2, task3,\r\n showTotal=True, # show the total progress\r\n showParts=True, # show the progress of each part\r\n showMerge=True, # show the progress of the merge\r\n)\r\nwith progress:\r\n while True:\r\n progress.refresh()\r\n time.sleep(0.5)\r\n```\r\n\r\n## License\r\n\r\nThe Project is released under the [Mulan Public License 2.0](./LICENSE).\r\n",
"bugtrack_url": null,
"license": "Mulan PSL v2",
"summary": "A simple, efficient, general-purpose Python multithreaded download library",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/auto-download/"
},
"split_keywords": [
"requests",
" download",
" http",
" thread"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b7cccb873b633580e4dc3a5ffcb7ffae7919b98168742fbe01d8d06b29a1c6b5",
"md5": "ef5d7d0c03dc2814ecc1c6acaaa87d80",
"sha256": "9ce84701e1441e7723642ed82c85bac319334c76507287532934d1057a9a5612"
},
"downloads": -1,
"filename": "autoDownload-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ef5d7d0c03dc2814ecc1c6acaaa87d80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 18257,
"upload_time": "2024-12-22T09:45:52",
"upload_time_iso_8601": "2024-12-22T09:45:52.479848Z",
"url": "https://files.pythonhosted.org/packages/b7/cc/cb873b633580e4dc3a5ffcb7ffae7919b98168742fbe01d8d06b29a1c6b5/autoDownload-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e065f6b94b671f7119717c10634a20eed0cd4d5a42e9fe0908c8353f550bf70e",
"md5": "2fbf2a9c248b79d9243d483179cd2ff0",
"sha256": "a15de4d5ef30c75f1950095bd594aff919ae3e58aa9d98098884b838393531a3"
},
"downloads": -1,
"filename": "autodownload-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "2fbf2a9c248b79d9243d483179cd2ff0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17543,
"upload_time": "2024-12-22T09:45:54",
"upload_time_iso_8601": "2024-12-22T09:45:54.130905Z",
"url": "https://files.pythonhosted.org/packages/e0/65/f6b94b671f7119717c10634a20eed0cd4d5a42e9fe0908c8353f550bf70e/autodownload-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-22 09:45:54",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "autodownload"
}