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, headers=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.
- headers (
Optional
[Mapping
[str
,str
] ]) – Extra headers that should be sent with each request, e.g. headers for data encryption key headers.
Raises: ValueError
– Ifstart
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.
-
invalid
¶ bool – Indicates if the download is in an invalid state.
This will occur if a call to
consume_next_chunk()
fails.
-
class
google.resumable_media.download.
Download
(media_url, start=None, end=None, headers=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 / orend
. However, in typical usage, neitherstart
norend
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 toend
of the media. - end (int) – The last byte in a range to be downloaded. If not
provided, but
start
is provided, will download from thestart
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.
-
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 currentDownload
has already finished.
-
finished
¶ bool – Flag indicating if the download has completed.