Downloader
provide.foundation.tools.downloader
¶
TODO: Add module docstring.
Classes¶
DownloadError
¶
DownloadError(
message: str,
*,
code: str | None = None,
context: dict[str, Any] | None = None,
cause: Exception | None = None,
**extra_context: Any
)
Bases: FoundationError
Raised when download fails.
Source code in provide/foundation/errors/base.py
ToolDownloader
¶
ToolDownloader(
client: UniversalClient,
time_source: Callable[[], float] | None = None,
async_sleep_func: (
Callable[[float], Awaitable[None]] | None
) = None,
)
Advanced download capabilities for tools.
Features: - Progress reporting with callbacks - Parallel downloads for multiple files - Mirror fallback support - Checksum verification
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Transport client for HTTP requests. |
|
progress_callbacks |
list[Callable[[int, int], None]]
|
List of progress callback functions. |
retry_policy |
Policy for retry behavior on downloads. |
Initialize the downloader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
UniversalClient
|
Universal client for making HTTP requests. |
required |
time_source
|
Callable[[], float] | None
|
Optional time source for testing (defaults to time.time). |
None
|
async_sleep_func
|
Callable[[float], Awaitable[None]] | None
|
Optional async sleep function for testing (defaults to asyncio.sleep). |
None
|
Source code in provide/foundation/tools/downloader.py
Functions¶
add_progress_callback
¶
download_parallel
async
¶
Download multiple files in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
list[tuple[str, Path]]
|
List of (url, destination) tuples. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of downloaded file paths in the same order as input. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If any download fails. |
Source code in provide/foundation/tools/downloader.py
download_with_mirrors
async
¶
Try multiple mirrors until one succeeds using fallback pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mirrors
|
list[str]
|
List of mirror URLs to try. |
required |
dest
|
Path
|
Destination file path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to downloaded file. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If all mirrors fail. |
Source code in provide/foundation/tools/downloader.py
download_with_progress
async
¶
Download a file with progress reporting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to download from. |
required |
dest
|
Path
|
Destination file path. |
required |
checksum
|
str | None
|
Optional checksum for verification. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the downloaded file. |
Raises:
| Type | Description |
|---|---|
DownloadError
|
If download or verification fails. |
Source code in provide/foundation/tools/downloader.py
verify_checksum
¶
Verify file checksum.
Uses Foundation's hash_file() for consistent hashing behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to file to verify. |
required |
expected
|
str
|
Expected checksum (hex string). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if checksum matches, False otherwise. |