DownloadKit
DownloadKit is a simple and easy-to-use multi-threaded file download tool for Python. It supports concurrent downloading of multiple files, automatic large file splitting for multi-threaded downloads, automatic task scheduling, and connection failure retries. The current version is 2.0.7, with frequent updates.
Common errors
-
ModuleNotFoundError: No module named 'DownloadKit'
cause Python module names are case-sensitive. While `pip install downloadkit` (lowercase) works, the actual module to import is `DownloadKit` (capital 'D').fixChange your import statement to `from DownloadKit import DownloadKit`. -
NameError: name 'DownloadKit' is not defined
cause This usually means the `DownloadKit` class was not correctly imported from the `DownloadKit` module, or there's a typo in the class name during usage.fixEnsure you have `from DownloadKit import DownloadKit` at the top of your file and that the class name `DownloadKit` is spelled correctly when instantiated. -
requests.exceptions.ConnectionError: (...)
cause While `DownloadKit` has an auto-retry mechanism, persistent `ConnectionError` indicates underlying network issues, an invalid or unreachable URL, or a server-side problem.fixVerify the URL is correct and accessible, check your network connection, and consider increasing the `retry` count and `interval` when initializing `DownloadKit` if intermittent network issues are expected. Example: `d = DownloadKit(goal_path=..., retry=5, interval=10)`.
Warnings
- gotcha The library's development status is '4 - Beta' on PyPI, indicating that APIs and internal behavior might still be subject to change in future minor versions, though core functionality is stable.
- gotcha When encountering existing files, `DownloadKit` has a `file_exists` parameter (options: 'skip', 'overwrite', 'rename'). If not explicitly configured, the default behavior (which follows the instance's `file_exists` attribute) might lead to unintended file overwrites or skipping downloads.
Install
-
pip install DownloadKit
Imports
- DownloadKit
from downloadkit import DownloadKit
from DownloadKit import DownloadKit
Quickstart
import os
from DownloadKit import DownloadKit
# Create a directory to save files
download_dir = os.path.join(os.getcwd(), 'downloaded_files')
os.makedirs(download_dir, exist_ok=True)
# Initialize the downloader with the target path
d = DownloadKit(goal_path=download_dir)
# Add multiple download tasks
url1 = 'https://www.python.org/static/img/python-logo.png' # Example URL
url2 = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' # Example URL
d.add(url1)
d.add(url2)
print(f'Starting downloads to {download_dir}...')
# The downloads start automatically upon adding tasks in a default setup
# You can also manually start/manage tasks with more advanced usage (not shown in quickstart)
# Wait for downloads to complete (this is a simplified example; actual library has more robust completion handling)
# For simple use-cases, the library manages a queue and threads automatically.
# In a real application, you might use d.wait() or monitor progress.
# For demonstration, we'll just print a message.
print('Downloads initiated. Check the "downloaded_files" directory.')