Class Blob (2.6.0)

Blob(name,bucket,chunk_size=None,encryption_key=None,kms_key_name=None,generation=None,)

A wrapper around Cloud Storage's concept of anObject.

Parameters

NameDescription
namestr

The name of the blob. This corresponds to the unique path of the object in the bucket. If bytes, will be converted to a unicode object. Blob / object names can contain any sequence of valid unicode characters, of length 1-1024 bytes when UTF-8 encoded.

bucketBucket

The bucket to which this blob belongs.

chunk_sizeint

(Optional) The size of a chunk of data whenever iterating (in bytes). This must be a multiple of 256 KB per the API specification. If not specified, the chunk_size of the blob itself is used. If that is not specified, a default value of 40 MB is used.

encryption_keybytes

(Optional) 32 byte encryption key for customer-supplied encryption. Seehttps://cloud.google.com/storage/docs/encryption#customer-supplied.

kms_key_namestr

(Optional) Resource name of Cloud KMS key used to encrypt the blob's contents.

generationlong

(Optional) If present, selects a specific revision of this object.

Properties

acl

Create our ACL on demand.

bucket

Bucket which contains the object.

Returns
TypeDescription
BucketThe object's bucket.

cache_control

Scalar property getter.

chunk_size

Get the blob's default chunk size.

Returns
TypeDescription
int orNoneTypeThe current blob's chunk size, if it is set.

client

The client bound to this blob.

component_count

Returns
TypeDescription
int orNoneTypeThe component count (in case of a composed object) orNone if the blob's resource has not been loaded from the server. This property will not be set on objects not created viacompose.

content_disposition

Scalar property getter.

content_encoding

Scalar property getter.

content_language

Scalar property getter.

content_type

Scalar property getter.

crc32c

Scalar property getter.

custom_time

Retrieve the custom time for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
datetime.datetime orNoneTypeDatetime object parsed from RFC3339 valid timestamp, orNone if the blob's resource has not been loaded from the server (seereload).

encryption_key

Retrieve the customer-supplied encryption key for the object.

Returns
TypeDescription
bytes orNoneTypeThe encryption key orNone if no customer-supplied encryption key was used, or the blob's resource has not been loaded from the server.

etag

Retrieve the ETag for the object.

SeeRFC 2616 (etags) andAPI reference docs.

Returns
TypeDescription
str orNoneTypeThe blob etag orNone if the blob's resource has not been loaded from the server.

event_based_hold

Scalar property getter.

generation

Retrieve the generation for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
int orNoneTypeThe generation of the blob orNone if the blob's resource has not been loaded from the server.

id

Retrieve the ID for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

The ID consists of the bucket name, object name, and generation number.

Returns
TypeDescription
str orNoneTypeThe ID of the blob orNone if the blob's resource has not been loaded from the server.

kms_key_name

Resource name of Cloud KMS key used to encrypt the blob's contents.

Returns
TypeDescription
str orNoneTypeThe resource name orNone if no Cloud KMS key was used, or the blob's resource has not been loaded from the server.

md5_hash

Scalar property getter.

media_link

Retrieve the media download URI for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
str orNoneTypeThe media link for the blob orNone if the blob's resource has not been loaded from the server.

metadata

Retrieve arbitrary/application specific metadata for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

:setter: Update arbitrary/application specific metadata for the object.:getter: Retrieve arbitrary/application specific metadata for the object.

Returns
TypeDescription
dict orNoneTypeThe metadata associated with the blob orNone if the property is not set.

metageneration

Retrieve the metageneration for the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
int orNoneTypeThe metageneration of the blob orNone if the blob's resource has not been loaded from the server.

owner

Retrieve info about the owner of the object.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
dict orNoneTypeMapping of owner's role/ID, orNone if the blob's resource has not been loaded from the server.

path

Getter property for the URL path to this Blob.

Returns
TypeDescription
strThe URL path to this Blob.

public_url

The public URL for this blob.

Usemake_public to enable anonymous access via the returnedURL.

Returns
TypeDescription
stringThe public URL for this blob.

retention_expiration_time

Retrieve timestamp at which the object's retention period expires.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
datetime.datetime orNoneTypeDatetime object parsed from RFC3339 valid timestamp, orNone if the property is not set locally.

self_link

Returns
TypeDescription
str orNoneTypeThe self link for the blob orNone if the blob's resource has not been loaded from the server.

size

Returns
TypeDescription
int orNoneTypeThe size of the blob orNone if the blob's resource has not been loaded from the server.

storage_class

Scalar property getter.

temporary_hold

Scalar property getter.

time_created

Retrieve the timestamp at which the object was created.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
datetime.datetime orNoneTypeDatetime object parsed from RFC3339 valid timestamp, orNone if the blob's resource has not been loaded from the server (seereload).

time_deleted

Retrieve the timestamp at which the object was deleted.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
datetime.datetime orNoneTypeDatetime object parsed from RFC3339 valid timestamp, orNone if the blob's resource has not been loaded from the server (seereload). If the blob has not been deleted, this will never be set.

updated

Retrieve the timestamp at which the object was updated.

Seehttps://cloud.google.com/storage/docs/json_api/v1/objects

Returns
TypeDescription
datetime.datetime orNoneTypeDatetime object parsed from RFC3339 valid timestamp, orNone if the blob's resource has not been loaded from the server (seereload).

user_project

Project ID billed for API requests made via this blob.

Derived from bucket's value.

Methods

Blob

Blob(name,bucket,chunk_size=None,encryption_key=None,kms_key_name=None,generation=None,)

propertyname Get the blob's name.

compose

compose(sources,client=None,timeout=60,if_generation_match=None,if_metageneration_match=None,if_source_generation_match=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Concatenate source blobs into this one.

Ifuser_project is set on the bucket, bills the API requestto that project.

SeeAPI reference docsand acode sample.

Parameters
NameDescription
sourceslist ofBlob

Blobs whose contents will be composed into this blob.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

if_generation_matchlong

(Optional) Makes the operation conditional on whether the destination object's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the object. Note: In a previous version, this argument worked identically to theif_source_generation_match argument. For backwards-compatibility reasons, if a list is passed in, this argument will behave likeif_source_generation_match and also issue a DeprecationWarning.

if_metageneration_matchlong

(Optional) Makes the operation conditional on whether the destination object's current metageneration matches the given value. If a list of long is passed in, no match operation will be performed. (Deprecated: type(list of long) is supported for backwards-compatability reasons only.)

if_source_generation_matchlist of long

(Optional) Makes the operation conditional on whether the current generation of each source blob matches the corresponding generation. The list must matchsources item-to-item.

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

create_resumable_upload_session

create_resumable_upload_session(content_type=None,size=None,origin=None,client=None,timeout=60,checksum=None,predefined_acl=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Create a resumable upload session.

Resumable upload sessions allow you to start an upload session fromone client and complete the session in another. This method is calledby the initiator to set the metadata and limits. The initiator thenpasses the session URL to the client that will upload the binary data.The client performs a PUT request on the session URL to complete theupload. This process allows untrusted clients to upload to anaccess-controlled bucket.

For more details, see thedocumentation onsigned URLs.

The content type of the upload will be determined in orderof precedence:

  • The value passed in to this method (if not :data:None)
  • The value stored on the current blob
  • The default value ('application/octet-stream')

Note:The effect of uploading to an existing blob depends on the"versioning" and "lifecycle" policies defined on the blob'sbucket. In the absence of those policies, upload willoverwrite any existing contents. See theobject versioning andlifecycle API documents for details.

Ifencryption_key is set, the blob will be encrypted withacustomer-suppliedencryption key.

Ifuser_project is set on the bucket, bills the API requestto that project.

Parameters
NameDescription
sizeint

(Optional) The maximum number of bytes that can be uploaded using this session. If the size is not known when creating the session, this should be left blank.

content_typestr

(Optional) Type of content being uploaded.

originstr

(Optional) If set, the upload can only be completed by a user-agent that uploads from the given origin. This can be useful when passing the session to a web client.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. After the upload is complete, the server-computed checksum of the resulting object will be checked and google.resumable_media.common.DataCorruption will be raised on a mismatch. On a validation failure, the client will attempt to delete the uploaded object automatically. Supported values are "md5", "crc32c" and None. The default is None.

predefined_aclstr

(Optional) Predefined access control list

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_generation_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
GoogleCloudErrorif the session creation response returns an error status.
Returns
TypeDescription
strThe resumable upload session URL. The upload can be completed by making an HTTP PUT request with the file's contents.

delete

delete(client=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Deletes a blob from Cloud Storage.

Ifuser_project is set on the bucket, bills the API requestto that project.

Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Exceptions
TypeDescription
NotFound(propagated fromdelete_blob).

download_as_bytes

download_as_bytes(client=None,start=None,end=None,raw_download=False,if_etag_match=None,if_etag_not_match=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,checksum='md5',retry=<google.api_core.retry.Retryobject>)

Download the contents of this blob as a bytes object.

Ifuser_project is set on the bucket, bills the API requestto that project.

Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

startint

(Optional) The first byte in a range to be downloaded.

endint

(Optional) The last byte in a range to be downloaded.

raw_downloadbool

(Optional) If true, download the object without any expansion.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. The response headers must contain a checksum of the requested type. If the headers lack an appropriate checksum (for instance in the case of transcoded or ranged downloads where the remote service does not know the correct checksum, including downloads where chunk_size is set) an INFO-level log will be emitted. Supported values are "md5", "crc32c" and None. The default is "md5".

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
NotFound
Returns
TypeDescription
bytesThe data stored in this blob.

download_as_string

download_as_string(client=None,start=None,end=None,raw_download=False,if_etag_match=None,if_etag_not_match=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,retry=<google.api_core.retry.Retryobject>)

(Deprecated) Download the contents of this blob as a bytes object.

Ifuser_project is set on the bucket, bills the API requestto that project.

Note:Deprecated alias fordownload_as_bytes.
Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

startint

(Optional) The first byte in a range to be downloaded.

endint

(Optional) The last byte in a range to be downloaded.

raw_downloadbool

(Optional) If true, download the object without any expansion.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
NotFound
Returns
TypeDescription
bytesThe data stored in this blob.

download_as_text

Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

startint

(Optional) The first byte in a range to be downloaded.

endint

(Optional) The last byte in a range to be downloaded.

raw_downloadbool

(Optional) If true, download the object without any expansion.

encodingstr

(Optional) encoding to be used to decode the downloaded bytes. Defaults to thecharset param of attr:content_type, or else to "utf-8".

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Returns
TypeDescription
textThe data stored in this blob, decoded to text.

download_to_file

Parameters
NameDescription
file_objfile

A file handle to which to write the blob's data.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

startint

(Optional) The first byte in a range to be downloaded.

endint

(Optional) The last byte in a range to be downloaded.

raw_downloadbool

(Optional) If true, download the object without any expansion.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. The response headers must contain a checksum of the requested type. If the headers lack an appropriate checksum (for instance in the case of transcoded or ranged downloads where the remote service does not know the correct checksum, including downloads where chunk_size is set) an INFO-level log will be emitted. Supported values are "md5", "crc32c" and None. The default is "md5".

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
NotFound

download_to_filename

download_to_filename(filename,client=None,start=None,end=None,raw_download=False,if_etag_match=None,if_etag_not_match=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,checksum='md5',retry=<google.api_core.retry.Retryobject>)

Download the contents of this blob into a named file.

Ifuser_project is set on the bucket, bills the API requestto that project.

See acode sampleto download a file with acustomer-supplied encryption key.

Parameters
NameDescription
filenamestr

A filename to be passed toopen.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

startint

(Optional) The first byte in a range to be downloaded.

endint

(Optional) The last byte in a range to be downloaded.

raw_downloadbool

(Optional) If true, download the object without any expansion.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. The response headers must contain a checksum of the requested type. If the headers lack an appropriate checksum (for instance in the case of transcoded or ranged downloads where the remote service does not know the correct checksum, including downloads where chunk_size is set) an INFO-level log will be emitted. Supported values are "md5", "crc32c" and None. The default is "md5".

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
NotFound

exists

exists(client=None,if_etag_match=None,if_etag_not_match=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,retry=<google.api_core.retry.Retryobject>)

Determines whether or not this blob exists.

Ifuser_project is set on the bucket, bills the API requestto that project.

Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Returns
TypeDescription
boolTrue if the blob exists in Cloud Storage.

from_string

from_string(uri,client=None)

Get a constructor for blob object by URI.

from google.cloud importstoragefrom google.cloud.storage.blob importBlobclient =storage.Client()blob =Blob.from_string("gs://bucket/object", client=client)
Parameters
NameDescription
uristr

The blob uri pass to get blob object.

clientClient

(Optional) The client to use. Application code shouldalways passclient.

Returns
TypeDescription
BlobThe blob object created.

generate_signed_url

generate_signed_url(expiration=None,api_access_endpoint="https://storage.googleapis.com",method="GET",content_md5=None,content_type=None,response_disposition=None,response_type=None,generation=None,headers=None,query_parameters=None,client=None,credentials=None,version=None,service_account_email=None,access_token=None,virtual_hosted_style=False,bucket_bound_hostname=None,scheme="http",)

Generates a signed URL for this blob.

Note:If you are on Google Compute Engine, you can't generate a signedURL using GCE service account.If you'd like to be able to generate a signed URL from GCE,you can use a standard service account from a JSON file ratherthan a GCE service account.See acode sample.

This is particularly useful if you don't want publiclyaccessible blobs, but don't want to require users to explicitlylog in.

Ifbucket_bound_hostname is set as an argument ofapi_access_endpoint,https works only if using aCDN.

Parameters
NameDescription
expirationUnion[Integer, datetime.datetime, datetime.timedelta]

Point in time when the signed URL should expire. If adatetime instance is passed without an explicittzinfo set, it will be assumed to beUTC.

api_access_endpointstr

(Optional) URI base.

methodstr

The HTTP verb that will be used when requesting the URL.

content_md5str

(Optional) The MD5 hash of the object referenced byresource.

content_typestr

(Optional) The content type of the object referenced byresource.

response_dispositionstr

(Optional) Content disposition of responses to requests for the signed URL. For example, to enable the signed URL to initiate a file ofblog.png, use the value'attachment; filename=blob.png'.

response_typestr

(Optional) Content type of responses to requests for the signed URL. Ignored if content_type is set on object/blob metadata.

generationstr

(Optional) A value that indicates which generation of the resource to fetch.

headersdict

(Optional) Additional HTTP headers to be included as part of the signed URLs. See:https://cloud.google.com/storage/docs/xml-api/reference-headers Requests using the signed URLmust pass the specified header (name and value) with each request for the URL.

query_parametersdict

(Optional) Additional query parameters to be included as part of the signed URLs. See:https://cloud.google.com/storage/docs/xml-api/reference-headers#query

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

credentialsgoogle.auth.credentials.Credentials

(Optional) The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment.

versionstr

(Optional) The version of signed credential to create. Must be one of 'v2' 'v4'.

service_account_emailstr

(Optional) E-mail address of the service account.

access_tokenstr

(Optional) Access token for a service account.

virtual_hosted_stylebool

(Optional) If true, then construct the URL relative the bucket's virtual hostname, e.g., '

bucket_bound_hostnamestr

(Optional) If passed, then construct the URL relative to the bucket-bound hostname. Value can be a bare or with scheme, e.g., 'example.com' or 'http://example.com'. See:https://cloud.google.com/storage/docs/request-endpoints#cname

schemestr

(Optional) Ifbucket_bound_hostname is passed as a bare hostname, use this value as the scheme.https will work only when using a CDN. Defaults to"http".

Exceptions
TypeDescription
`ValueErrorwhen version is invalid.
`TypeErrorwhen expiration is not a valid type.
`AttributeErrorif credentials is not an instance ofgoogle.auth.credentials.Signing.
Returns
TypeDescription
strA signed URL you can use to access the resource until expiration.

get_iam_policy

get_iam_policy(client=None,requested_policy_version=None,timeout=60,retry=<google.api_core.retry.Retryobject>)
Parameters
NameDescription
clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the current object's bucket.

requested_policy_versionint orNoneType

(Optional) The version of IAM policies to request. If a policy with a condition is requested without setting this, the server will return an error. This must be set to a value of 3 to retrieve IAM policies containing conditions. This is to prevent client code that isn't aware of IAM conditions from interpreting and modifying policies incorrectly. The service might return a policy with version lower than the one that was requested, based on the feature syntax in the policy fetched.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Returns
TypeDescription
google.api_core.iam.Policythe policy instance, based on the resource returned from thegetIamPolicy API request.

make_private

Parameters
NameDescription
clientClient orNoneType

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

make_public

Parameters
NameDescription
clientClient orNoneType

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

open

Create a file handler for file-like I/O to or from this blob.

This method can be used as a context manager, just like Python'sbuilt-in 'open()' function.

While reading, as with other read methods, if blob.generation is not setthe most recent blob generation will be used. Because the file-like IOreader downloads progressively in chunks, this could result in data frommultiple versions being mixed together. If this is a concern, useeither bucket.get_blob(), or blob.reload(), which will download thelatest generation number and set it; or, if the generation is known, setit manually, for instance with bucket.blob(generation=123456).

Checksumming (hashing) to verify data integrity is disabled for readsusing this feature because reads are implemented using request ranges,which do not provide checksums to validate. Seehttps://cloud.google.com/storage/docs/hashes-etags for details.

See acode sample.

Keyword arguments to pass to the underlying API calls.For both uploads and downloads, the following arguments aresupported:

  • if_generation_match
  • if_generation_not_match
  • if_metageneration_match
  • if_metageneration_not_match
  • timeout
  • retry

For downloads only, the following additional arguments are supported:

  • raw_download

For uploads only, the following additional arguments are supported:

  • content_type
  • num_retries
  • predefined_acl
  • checksum
Note:num_retries is supported for backwards-compatibilityreasons only; please useretry with a Retry object orConditionalRetryPolicy instead.
Parameters
NameDescription
modestr

(Optional) A mode string, as per standard Pythonopen() semantics.The first character must be 'r', to open the blob for reading, or 'w' to open it for writing. The second character, if present, must be 't' for (unicode) text mode, or 'b' for bytes mode. If the second character is omitted, text mode is the default.

chunk_sizelong

(Optional) For reads, the minimum number of bytes to read at a time. If fewer bytes than the chunk_size are requested, the remainder is buffered. For writes, the maximum number of bytes to buffer before sending data to the server, and the size of each request when data is sent. Writes are implemented as a "resumable upload", so chunk_size for writes must be exactly a multiple of 256KiB as with other resumable uploads. The default is 40 MiB.

ignore_flushbool

(Optional) For non text-mode writes, makes flush() do nothing instead of raising an error. flush() without closing is not supported by the remote service and therefore calling it normally results in io.UnsupportedOperation. However, that behavior is incompatible with some consumers and wrappers of file objects in Python, such as zipfile.ZipFile or io.TextIOWrapper. Setting ignore_flush will cause flush() to successfully do nothing, for compatibility with those contexts. The correct way to actually flush data to the remote server is to close() (using a context manager, such as in the example, will cause this to happen automatically).

encodingstr

(Optional) For text mode only, the name of the encoding that the stream will be decoded or encoded with. If omitted, it defaults to locale.getpreferredencoding(False).

errorsstr

(Optional) For text mode only, an optional string that specifies how encoding and decoding errors are to be handled. Pass 'strict' to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass 'ignore' to ignore errors. (Note that ignoring encoding errors can lead to data loss.) Other more rarely-used options are also available; see the Python 'io' module documentation for 'io.TextIOWrapper' for a complete list.

newlinestr

(Optional) For text mode only, controls how line endings are handled. It can be None, '', '\n', '\r', and '\r\n'. If None, reads use "universal newline mode" and writes use the system default. See the Python 'io' module documentation for 'io.TextIOWrapper' for details.

patch

Parameters
NameDescription
clientClient orNoneType

the client to use. If not passed, falls back to theclient stored on the current object.

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

path_helper

Parameters
NameDescription
bucket_pathstr

The URL path for a bucket.

blob_namestr

The name of the blob.

Returns
TypeDescription
strThe relative URL path forblob_name.

reload

Parameters
NameDescription
clientClient orNoneType

the client to use. If not passed, falls back to theclient stored on the current object.

projectionstr

(Optional) If used, must be 'full' or 'noAcl'. Defaults to'noAcl'. Specifies the set of properties to return.

if_etag_matchUnion[str, Set[str]]

(Optional) See :ref:using-if-etag-match

if_etag_not_matchUnion[str, Set[str]])

(Optional) See :ref:using-if-etag-not-match

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

rewrite

Parameters
NameDescription
sourceBlob

blob whose contents will be rewritten into this blob.

tokenstr

(Optional) Token returned from an earlier, not-completed call to rewrite the same source blob. If passed, result will include updated status, total bytes written.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

if_generation_matchlong

(Optional) See :ref:using-if-generation-match Note that the generation to be matched is that of thedestination blob.

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match Note that the generation to be matched is that of thedestination blob.

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match Note that the metageneration to be matched is that of thedestination blob.

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match Note that the metageneration to be matched is that of thedestination blob.

if_source_generation_matchlong

(Optional) Makes the operation conditional on whether the source object's generation matches the given value.

if_source_generation_not_matchlong

(Optional) Makes the operation conditional on whether the source object's generation does not match the given value.

if_source_metageneration_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration matches the given value.

if_source_metageneration_not_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration does not match the given value.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Returns
TypeDescription
tuple(token, bytes_rewritten, total_bytes), wheretoken is a rewrite token (None if the rewrite is complete),bytes_rewritten is the number of bytes rewritten so far, andtotal_bytes is the total number of bytes to be rewritten.

set_iam_policy

Parameters
NameDescription
policygoogle.api_core.iam.Policy

policy instance used to update bucket's IAM policy.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the current bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Returns
TypeDescription
google.api_core.iam.Policythe policy instance, based on the resource returned from thesetIamPolicy API request.

test_iam_permissions

Parameters
NameDescription
permissionslist of string

the permissions to check

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the current bucket.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

Returns
TypeDescription
list of stringthe permissions returned by thetestIamPermissions API request.

update

Parameters
NameDescription
clientClient orNoneType

the client to use. If not passed, falls back to theclient stored on the current object.

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

update_storage_class

Parameters
NameDescription
new_classstr

new storage class for the object. One of:NEARLINE_STORAGE_CLASS,COLDLINE_STORAGE_CLASS,ARCHIVE_STORAGE_CLASS,STANDARD_STORAGE_CLASS,MULTI_REGIONAL_LEGACY_STORAGE_CLASS, orREGIONAL_LEGACY_STORAGE_CLASS.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

if_generation_matchlong

(Optional) See :ref:using-if-generation-match Note that the generation to be matched is that of thedestination blob.

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match Note that the generation to be matched is that of thedestination blob.

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match Note that the metageneration to be matched is that of thedestination blob.

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match Note that the metageneration to be matched is that of thedestination blob.

if_source_generation_matchlong

(Optional) Makes the operation conditional on whether the source object's generation matches the given value.

if_source_generation_not_matchlong

(Optional) Makes the operation conditional on whether the source object's generation does not match the given value.

if_source_metageneration_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration matches the given value.

if_source_metageneration_not_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration does not match the given value.

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. See:configuring_retries

upload_from_file

upload_from_file(file_obj,rewind=False,size=None,content_type=None,num_retries=None,client=None,predefined_acl=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,checksum=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Upload the contents of this blob from a file-like object.

The content type of the upload will be determined in orderof precedence:

  • The value passed in to this method (if not :data:None)
  • The value stored on the current blob
  • The default value ('application/octet-stream')

Note:The effect of uploading to an existing blob depends on the"versioning" and "lifecycle" policies defined on the blob'sbucket. In the absence of those policies, upload willoverwrite any existing contents. See theobject versioning andlifecycle API documents for details.

If the size of the data to be uploaded exceeds 8 MB a resumable mediarequest will be used, otherwise the content and the metadata will beuploaded in a single multipart upload request.

For more fine-grained over the upload process, check outgoogle-resumable-media.

Ifuser_project is set on the bucket, bills the API requestto that project.

Parameters
NameDescription
file_objfile

A file handle opened in binary mode for reading.

rewindbool

If True, seek to the beginning of the file handle before writing the file to Cloud Storage.

sizeint

The number of bytes to be uploaded (which will be read fromfile_obj). If not provided, the upload will be concluded oncefile_obj is exhausted.

content_typestr

(Optional) Type of content being uploaded.

num_retriesint

Number of upload retries. By default, only uploads with if_generation_match set will be retried, as uploads without the argument are not guaranteed to be idempotent. Setting num_retries will override this default behavior and guarantee retries even when if_generation_match is not set. (Deprecated: This argument will be removed in a future release.)

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

predefined_aclstr

(Optional) Predefined access control list

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. If the upload is completed in a single request, the checksum will be entirely precomputed and the remote server will handle verification and error handling. If the upload is too large and must be transmitted in multiple requests, the checksum will be incrementally computed and the client will handle verification and error handling, raising google.resumable_media.common.DataCorruption on a mismatch and attempting to delete the corrupted file. Supported values are "md5", "crc32c" and None. The default is None.

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_generation_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Exceptions
TypeDescription
GoogleCloudErrorif the upload response returns an error status.

upload_from_filename

upload_from_filename(filename,content_type=None,num_retries=None,client=None,predefined_acl=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,checksum=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Upload this blob's contents from the content of a named file.

The content type of the upload will be determined in orderof precedence:

  • The value passed in to this method (if not :data:None)
  • The value stored on the current blob
  • The value given bymimetypes.guess_type
  • The default value ('application/octet-stream')

Note:The effect of uploading to an existing blob depends on the"versioning" and "lifecycle" policies defined on the blob'sbucket. In the absence of those policies, upload willoverwrite any existing contents. See theobject versioning andlifecycle API documents for details.

Ifuser_project is set on the bucket, bills the API requestto that project.

See acode sampleto upload a file with acustomer-supplied encryption key.

Parameters
NameDescription
filenamestr

The path to the file.

content_typestr

(Optional) Type of content being uploaded.

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

num_retriesint

Number of upload retries. By default, only uploads with if_generation_match set will be retried, as uploads without the argument are not guaranteed to be idempotent. Setting num_retries will override this default behavior and guarantee retries even when if_generation_match is not set. (Deprecated: This argument will be removed in a future release.)

predefined_aclstr

(Optional) Predefined access control list

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. If the upload is completed in a single request, the checksum will be entirely precomputed and the remote server will handle verification and error handling. If the upload is too large and must be transmitted in multiple requests, the checksum will be incrementally computed and the client will handle verification and error handling, raising google.resumable_media.common.DataCorruption on a mismatch and attempting to delete the corrupted file. Supported values are "md5", "crc32c" and None. The default is None.

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_generation_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

upload_from_string

upload_from_string(data,content_type='text/plain',num_retries=None,client=None,predefined_acl=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,timeout=60,checksum=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)
Parameters
NameDescription
databytes or str

The data to store in this blob. If the value is text, it will be encoded as UTF-8.

content_typestr

(Optional) Type of content being uploaded. Defaults to'text/plain'.

num_retriesint

Number of upload retries. By default, only uploads with if_generation_match set will be retried, as uploads without the argument are not guaranteed to be idempotent. Setting num_retries will override this default behavior and guarantee retries even when if_generation_match is not set. (Deprecated: This argument will be removed in a future release.)

clientClient

(Optional) The client to use. If not passed, falls back to theclient stored on the blob's bucket.

predefined_aclstr

(Optional) Predefined access control list

if_generation_matchlong

(Optional) See :ref:using-if-generation-match

if_generation_not_matchlong

(Optional) See :ref:using-if-generation-not-match

if_metageneration_matchlong

(Optional) See :ref:using-if-metageneration-match

if_metageneration_not_matchlong

(Optional) See :ref:using-if-metageneration-not-match

timeoutfloat or tuple

(Optional) The amount of time, in seconds, to wait for the server response. See:configuring_timeouts

checksumstr

(Optional) The type of checksum to compute to verify the integrity of the object. If the upload is completed in a single request, the checksum will be entirely precomputed and the remote server will handle verification and error handling. If the upload is too large and must be transmitted in multiple requests, the checksum will be incrementally computed and the client will handle verification and error handling, raising google.resumable_media.common.DataCorruption on a mismatch and attempting to delete the corrupted file. Supported values are "md5", "crc32c" and None. The default is None.

retrygoogle.api_core.retry.Retry orgoogle.cloud.storage.retry.ConditionalRetryPolicy

(Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. Agoogle.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_generation_match is set. See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-05 UTC.