Download

Download service for pyfetcher.

Purpose:

Provide file-oriented download helpers that reuse the shared fetch service and streaming models.

Design:
  • Downloads are async-first using streamed chunks.

  • Files are written incrementally to avoid holding entire responses in memory.

  • Parent directories are created automatically.

Examples

>>> service = DownloadService()
>>> hasattr(service, "adownload_to_path")
True
class pyfetcher.download.service.DownloadService(*, fetch_service=None)[source]

Async download service built on streamed fetches.

Wraps a FetchService to provide file-oriented download capabilities. Files are streamed incrementally to disk to minimize memory usage for large downloads.

Parameters:

fetch_service (FetchService | None) – Optional fetch service instance. A default is created if not provided.

Examples

>>> service = DownloadService()
>>> hasattr(service, "adownload_to_path")
True
async adownload_to_path(request, destination)[source]

Download a resource to a destination file path.

Streams the response body in chunks and writes each chunk to disk as it arrives. Parent directories are created automatically.

Parameters:
  • request (FetchRequest) – The fetch request for the resource to download.

  • destination (str | Path) – Target file path (string or Path).

Returns:

The resolved Path where the file was written.

Raises:

Exception – Any streaming or file I/O failure.

Return type:

Path

Examples

>>> service = DownloadService()
>>> hasattr(service, "adownload_to_path")
True