google.resumable_media.requests.download module

Support for downloading media from Google APIs.

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

Bases: google.resumable_media.requests._helpers.RequestsMixin, google.resumable_media._download.ChunkedDownload

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.
  • headers (Optional [ Mapping [ str, str ] ]) – Extra headers that should be sent with each request, e.g. headers for data encryption key headers.
media_url

str – The URL containing the media to be downloaded.

start

Optional [ int ] – The first byte in a range to be downloaded.

end

Optional [ int ] – The last byte in a range to be downloaded.

chunk_size

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

Raises:ValueError – If start is negative.
bytes_downloaded

int – Number of bytes that have been downloaded.

consume_next_chunk(transport)

Consume the next chunk of the resource to be downloaded.

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

bool – Flag indicating if the download has completed.

invalid

bool – Indicates if the download is in an invalid state.

This will occur if a call to consume_next_chunk() fails.

total_bytes

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

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

Bases: google.resumable_media.requests._helpers.RequestsMixin, google.resumable_media._download.Download

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.
  • headers (Optional [ Mapping [ str, str ] ]) – Extra headers that should be sent with the request, e.g. headers for encrypted data.
media_url

str – The URL containing the media to be downloaded.

start

Optional [ int ] – The first byte in a range to be downloaded.

end

Optional [ int ] – The last byte in a range to be downloaded.

consume(transport)

Consume the resource to be downloaded.

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

bool – Flag indicating if the download has completed.