google.resumable_media.download module

Support for downloading media from Google APIs.

class google.resumable_media.download.ChunkedDownload(media_url, chunk_size, stream, start=0, end=None)

Bases: google.resumable_media.download._DownloadBase

Download a resource in chunks from a Google API.

Parameters:
  • media_url (str) – The URL containing the media to be downloaded.
  • chunk_size (int) – The number of bytes to be retrieved in each request.
  • stream (IO[bytes]) – A write-able stream (i.e. file-like object) that will be used to concatenate chunks of the resource as they are downloaded.
  • start (int) – The first byte in a range to be downloaded. If not provided, defaults to 0.
  • end (int) – The last byte in a range to be downloaded. If not provided, will download to the end of the media.
Raises:

ValueError – If start is negative.

bytes_downloaded

int – Number of bytes that have been downloaded.

chunk_size = None

int – The number of bytes to be retrieved in each request.

consume_next_chunk(transport)

Consume the next chunk of the resource to be downloaded.

Parameters:transport (object) – An object which can make authenticated requests.
Returns:The HTTP response returned by transport.
Return type:object
Raises:ValueError – If the current download has finished.
finished

bool – Flag indicating if the download has completed.

total_bytes

Optional [ int ] – The total number of bytes to be downloaded.

class google.resumable_media.download.Download(media_url, start=None, end=None)

Bases: google.resumable_media.download._DownloadBase

Helper to manage downloading a resource from a Google API.

“Slices” of the resource can be retrieved by specifying a range with start and / or end. However, in typical usage, neither start nor end is expected to be provided.

Parameters:
  • media_url (str) – The URL containing the media to be downloaded.
  • start (int) – The first byte in a range to be downloaded. If not provided, but end is provided, will download from the beginning to end of the media.
  • end (int) – The last byte in a range to be downloaded. If not provided, but start is provided, will download from the start to the end of the media.
consume(transport)

Consume the resource to be downloaded.

Parameters:transport (object) – An object which can make authenticated requests.
Returns:The HTTP response returned by transport.
Return type:object
Raises:ValueError – If the current Download has already finished.
finished

bool – Flag indicating if the download has completed.