Docs/API reference

Downloader · Python

Save a response to a local file or receive its bytes in memory.

Download .md
Developers3 min read11 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Purpose and lifecycle

allowResume uses HTTP Range when resuming an existing file. Inspect resumed and status rather than assuming the server honored the range.

The underlying transport buffers the response and applies its response-size cap. This is not an unlimited streaming downloader; chunk_size controls file writes, not network memory.

maxBytes/max_bytes limits the bytes retained/written after fetching. It does not make the upstream transfer stop at that exact byte count.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

class Downloader
python1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

from crawlingo import Downloader
result = Downloader().allow_resume(True).max_bytes(1048576).download(
    "https://example.com/", "page.html"
)
print(result.status, result.bytes_written, result.resumed)
python5 lines · copy-ready

Members

MemberKindReturn / value typeSource status
__init__methodNot annotated; see behavior notesPresent in source
chunk_sizemethod'Downloader'Present in source
allow_resumemethod'Downloader'Present in source
max_bytesmethod'Downloader'Present in source
downloadmethodDownloadResultPresent in source
download_to_memorymethodTuple[DownloadResult, bytes]Present in source

__init__()

Create a downloader using a supplied session or a fresh default session. Configure limits and call download or download_to_memory.

Returns / value: Not annotated; see behavior notes.

def __init__(self, session: Optional[Session]=None)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
sessionOptional[Session]Default: NoneShared request state. Omit only where the signature provides a default.

chunk_size()

Choose the Python file-write chunk size in bytes; default 65536.

Returns / value: 'Downloader'.

def chunk_size(self, size: int) -> 'Downloader'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
sizeintRequiredSize in bytes.

allow_resume()

Enable or disable range-based continuation of an existing destination file.

Returns / value: 'Downloader'.

def allow_resume(self, enabled: bool=True) -> 'Downloader'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledboolDefault: TrueEnable or disable this behavior.

max_bytes()

Limit the returned/written body bytes. Choose a positive integer.

Returns / value: 'Downloader'.

def max_bytes(self, n: int) -> 'Downloader'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
nintRequiredCount or index; see the method description.

download()

Fetch into the destination and return DownloadResult. This can append or replace depending on resume/server response.

Returns / value: DownloadResult.

def download(self, url: str, dest: str) -> DownloadResult
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.
deststrRequiredDestination file path; existing content may be replaced or resumed.

download_to_memory()

Return result metadata and the response bytes; retain only small downloads this way.

Returns / value: Tuple[DownloadResult, bytes].

def download_to_memory(self, url: str) -> Tuple[DownloadResult, bytes]
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.

Errors and operational limits

Network, timeout and filesystem failures can propagate. Node uses typed native errors; Python downloader methods may propagate native exceptions directly.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.