Class Bucket (2.1.0)

Bucket(client,name=None,user_project=None)

A class representing a Bucket on Cloud Storage.

Parameters

NameDescription
clientClient

A client which holds credentials and project configuration for the bucket (which requires a project).

namestr

The name of the bucket. Bucket names must start and end with a number or letter.

user_projectstr

(Optional) the project ID to be billed for API requests made via this instance.

Properties

acl

Create our ACL on demand.

client

The client bound to this bucket.

cors

Returns
TypeDescription
list of dictionariesA sequence of mappings describing each CORS policy.

default_event_based_hold

default_kms_key_name

Retrieve / set default KMS encryption key for objects in the bucket.

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

:setter: Set default KMS encryption key for items in this bucket.:getter: Get default KMS encryption key for items in this bucket.

Returns
TypeDescription
strDefault KMS encryption key, orNone if not set.

default_object_acl

Create our defaultObjectACL on demand.

etag

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

iam_configuration

Retrieve IAM configuration for this bucket.

Returns
TypeDescription
IAMConfigurationan instance for managing the bucket's IAM configuration.

id

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

labels

Returns
TypeDescription
dictName-value pairs (string->string) labelling the bucket.

lifecycle_rules

Returns
TypeDescription
generator(dict)A sequence of mappings describing each lifecycle rule.

location

Retrieve location configured for this bucket.

Seehttps://cloud.google.com/storage/docs/json_api/v1/buckets andhttps://cloud.google.com/storage/docs/bucket-locations

ReturnsNone if the property has not been set before creation,or if the bucket's resource has not been loaded from the server.

location_type

Retrieve or set the location type for the bucket.

Seehttps://cloud.google.com/storage/docs/storage-classes

:setter: Set the location type for this bucket.:getter: Gets the the location type for this bucket.

Returns
TypeDescription
str orNoneTypeIf set, one ofMULTI_REGION_LOCATION_TYPE,REGION_LOCATION_TYPE, orDUAL_REGION_LOCATION_TYPE, elseNone.

metageneration

Retrieve the metageneration for the bucket.

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

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

owner

Retrieve info about the owner of the bucket.

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

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

path

The URL path to this bucket.

project_number

Retrieve the number of the project to which the bucket is assigned.

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

Returns
TypeDescription
int orNoneTypeThe project number that owns the bucket orNone if the bucket's resource has not been loaded from the server.

requester_pays

Does the requester pay for API requests for this bucket?

Seehttps://cloud.google.com/storage/docs/requester-pays fordetails.

:setter: Update whether requester pays for this bucket.:getter: Query whether requester pays for this bucket.

Returns
TypeDescription
boolTrue if requester pays for API requests for the bucket, else False.

retention_period

Retrieve or set the retention period for items in the bucket.

Returns
TypeDescription
int orNoneTypenumber of seconds to retain items after upload or release from event-based lock, orNone if the property is not set locally.

retention_policy_effective_time

Retrieve the effective time of the bucket's retention policy.

Returns
TypeDescription
datetime.datetime orNoneTypepoint-in time at which the bucket's retention policy is effective, orNone if the property is not set locally.

retention_policy_locked

Retrieve whthere the bucket's retention policy is locked.

Returns
TypeDescription
boolTrue if the bucket's policy is locked, or else False if the policy is not locked, or the property is not set locally.

rpo

Get the RPO (Recovery Point Objective) of this bucket

See:https://cloud.google.com/storage/docs/managing-turbo-replication

"ASYNC_TURBO" or "DEFAULT"

self_link

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

storage_class

Retrieve or set the storage class for the bucket.

Seehttps://cloud.google.com/storage/docs/storage-classes

:setter: Set the storage class for this bucket.:getter: Gets the the storage class for this bucket.

Returns
TypeDescription
str orNoneTypeIf set, one ofNEARLINE_STORAGE_CLASS,COLDLINE_STORAGE_CLASS,ARCHIVE_STORAGE_CLASS,STANDARD_STORAGE_CLASS,MULTI_REGIONAL_LEGACY_STORAGE_CLASS,REGIONAL_LEGACY_STORAGE_CLASS, orDURABLE_REDUCED_AVAILABILITY_LEGACY_STORAGE_CLASS, elseNone.

time_created

Retrieve the timestamp at which the bucket was created.

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

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

user_project

Project ID to be billed for API requests made via this bucket.

If unset, API requests are billed to the bucket owner.

A user project is required for all operations on Requester Pays buckets.

Seehttps://cloud.google.com/storage/docs/requester-pays#requirements for details.

versioning_enabled

Is versioning enabled for this bucket?

Seehttps://cloud.google.com/storage/docs/object-versioning fordetails.

:setter: Update whether versioning is enabled for this bucket.:getter: Query whether versioning is enabled for this bucket.

Returns
TypeDescription
boolTrue if enabled, else False.

Methods

Bucket

Bucket(client,name=None,user_project=None)

propertyname Get the bucket's name.

add_lifecycle_delete_rule

add_lifecycle_delete_rule(**kw)

Add a "delete" rule to lifestyle rules configured for this bucket.

Seehttps://cloud.google.com/storage/docs/lifecycle andhttps://cloud.google.com/storage/docs/json_api/v1/buckets

.. literalinclude:: snippets.py :start-after: [START add_lifecycle_delete_rule] :end-before: [END add_lifecycle_delete_rule] :dedent: 4

add_lifecycle_set_storage_class_rule

add_lifecycle_set_storage_class_rule(storage_class,**kw)

Add a "delete" rule to lifestyle rules configured for this bucket.

Seehttps://cloud.google.com/storage/docs/lifecycle andhttps://cloud.google.com/storage/docs/json_api/v1/buckets

.. literalinclude:: snippets.py :start-after: [START add_lifecycle_set_storage_class_rule] :end-before: [END add_lifecycle_set_storage_class_rule] :dedent: 4

Parameter
NameDescription
storage_classstr, one ofSTORAGE_CLASSES.

new storage class to assign to matching items.

blob

blob(blob_name,chunk_size=None,encryption_key=None,kms_key_name=None,generation=None)
Parameters
NameDescription
blob_namestr

The name of the blob to be instantiated.

chunk_sizeint

The size of a chunk of data whenever iterating (in bytes). This must be a multiple of 256 KB per the API specification.

encryption_keybytes

(Optional) 32 byte encryption key for customer-supplied encryption.

kms_key_namestr

(Optional) Resource name of KMS key used to encrypt blob's content.

generationlong

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

Returns
TypeDescription
BlobThe blob object created.

clear_lifecyle_rules

configure_website

configure_website(main_page_suffix=None,not_found_page=None)
Parameters
NameDescription
main_page_suffixstr

The page to use as the main page of a directory. Typically something like index.html.

not_found_pagestr

The file to use when a page isn't found.

copy_blob

Parameters
NameDescription
blobBlob

The blob to be copied.

destination_bucketBucket

The bucket into which the blob should be copied.

new_namestr

(Optional) The new name for the copied file.

clientClient orNoneType

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

preserve_aclbool

DEPRECATED. This argument is not functional! (Optional) Copies ACL from old blob to new blob. Default: True.

source_generationlong

(Optional) The generation of the blob to be copied.

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
BlobThe new Blob. .. rubric:: Example Copy a blob including ACL. >>> from google.cloud import storage >>> client = storage.Client(project="project") >>> bucket = client.bucket("bucket") >>> dst_bucket = client.bucket("destination-bucket") >>> blob = bucket.blob("file.ext") >>> new_blob = bucket.copy_blob(blob, dst_bucket) >>> new_blob.acl.save(blob.acl)

create

Parameters
NameDescription
clientClient orNoneType

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

projectstr

(Optional) The project under which the bucket is to be created. If not passed, uses the project set on the client.

locationstr

(Optional) The location of the bucket. If not passed, the default location, US, will be used. Seehttps://cloud.google.com/storage/docs/bucket-locations

predefined_aclstr

(Optional) Name of predefined ACL to apply to bucket. See:https://cloud.google.com/storage/docs/access-control/lists#predefined-acl

predefined_default_object_aclstr

(Optional) Name of predefined ACL to apply to bucket's objects. See:https://cloud.google.com/storage/docs/access-control/lists#predefined-acl

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
ValueErrorifproject is None and client'sproject is also None.

delete

Parameters
NameDescription
forcebool

If True, empties the bucket's objects then deletes it.

clientClient orNoneType

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

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the blob'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

Exceptions
TypeDescription
`ValueErrorifforce isTrue and the bucket contains more than 256 objects / blobs.

delete_blob

Parameters
NameDescription
blob_namestr

A blob name to delete.

clientClient orNoneType

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

generationlong

(Optional) If present, permanently deletes a specific revision of this 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

Exceptions
TypeDescription
NotFound(to suppress the exception, calldelete_blobs, passing a no-opon_error callback, e.g.: .. literalinclude:: snippets.py :start-after: [START delete_blobs] :end-before: [END delete_blobs] :dedent: 4

delete_blobs

Parameters
NameDescription
blobslist

A list ofBlob-s or blob names to delete.

on_errorcallable

(Optional) Takes single argument:blob. Called called once for each blob raisingNotFound; otherwise, the exception is propagated.

clientClient

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

if_generation_matchlist of long

(Optional) See :ref:using-if-generation-match Note that the length of the list must match the length of The list must matchblobs item-to-item.

if_generation_not_matchlist of long

(Optional) See :ref:using-if-generation-not-match The list must matchblobs item-to-item.

if_metageneration_matchlist of long

(Optional) See :ref:using-if-metageneration-match The list must matchblobs item-to-item.

if_metageneration_not_matchlist of long

(Optional) See :ref:using-if-metageneration-not-match The list must matchblobs item-to-item.

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(ifon_error is not passed). .. rubric:: Example Delete blobs using generation match preconditions. >>> from google.cloud import storage >>> client = storage.Client() >>> bucket = client.bucket("bucket-name") >>> blobs = [bucket.blob("blob-name-1"), bucket.blob("blob-name-2")] >>> if_generation_match = [None] * len(blobs) >>> if_generation_match[0] = "123" # precondition for "blob-name-1" >>> bucket.delete_blobs(blobs, if_generation_match=if_generation_match)

disable_logging

disable_website

disable_website()

Disable the website configuration for this bucket.

This is really just a shortcut for setting the website-relatedattributes toNone.

enable_logging

enable_logging(bucket_name,object_prefix="")

Enable access logging for this bucket.

Seehttps://cloud.google.com/storage/docs/access-logs

Parameters
NameDescription
bucket_namestr

name of bucket in which to store access logs

object_prefixstr

prefix for access log filenames

exists

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

Determines whether or not this bucket exists.

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
clientClient orNoneType

(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

if_etag_matchUnion[str, Set[str]]

(Optional) Make the operation conditional on whether the bucket's current ETag matches the given value.

if_etag_not_matchUnion[str, Set[str]])

(Optional) Make the operation conditional on whether the bucket's current ETag does not match the given value.

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the bucket's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the bucket's current metageneration does not match the given value.

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

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

Returns
TypeDescription
boolTrue if the bucket exists in Cloud Storage.

from_string

from_string(uri,client=None)

Get a constructor for bucket object by URI.

Parameters
NameDescription
uristr

The bucket uri pass to get bucket object.

clientClient orNoneType

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

Returns
TypeDescription
BucketThe bucket object created. .. rubric:: Example Get a constructor for bucket object by URI.. >>> from google.cloud import storage >>> from google.cloud.storage.bucket import Bucket >>> client = storage.Client() >>> bucket = Bucket.from_string("gs://bucket", client=client)

generate_signed_url

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

Generates a signed URL for this bucket.

Note:If you are on Google Compute Engine, you can't generate a signedURL using GCE service account. FollowIssue 50_ for updates onthis. 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.If you have a bucket that you want to allow access to for a setamount of time, you can use this method to generate a URL thatis only valid within a certain time period.

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

.. rubric:: Example

Generates a signed URL for this bucket using bucket_bound_hostname and scheme.

from google.cloud import storageclient = storage.Client()bucket = client.get_bucket('my-bucket-name')url = bucket.generate_signed_url(expiration='url-expiration-time', bucket_bound_hostname='mydomain.tld', version='v4')url = bucket.generate_signed_url(expiration='url-expiration-time', bucket_bound_hostname='mydomain.tld', version='v4',scheme='https') # If usingCDN

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

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.

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 orNoneType

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

credentialsgoogle.auth.credentials.Credentials orNoneType

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'.

virtual_hosted_stylebool

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

bucket_bound_hostnamestr

(Optional) If pass, then construct the URL relative to the bucket-bound hostname. Value cane 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.

generate_upload_policy

Parameters
NameDescription
expirationdatetime

(Optional) Expiration in UTC. If not specified, the policy will expire in 1 hour.

conditionslist

A list of conditions as described in thepolicy documents_ documentation.

clientClient

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

Returns
TypeDescription
dictA dictionary of (form field name, form field value) of form fields that should be added to your HTML upload form in order to attach the signature.

get_blob

get_blob(blob_name,client=None,encryption_key=None,generation=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>,**kwargs)

Get a blob object by name.

This will return None if the blob doesn't exist:

.. literalinclude:: snippets.py :start-after: [START get_blob] :end-before: [END get_blob] :dedent: 4

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
blob_namestr

The name of the blob to retrieve.

clientClient orNoneType

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

encryption_keybytes

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

generationlong

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

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
Blob or NoneThe blob object if it exists, otherwise None.

get_iam_policy

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

Retrieve the IAM policy for the bucket.

Seehttps://cloud.google.com/storage/docs/json_api/v1/buckets/getIamPolicy

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
clientClient orNoneType

(Optional) The client to use. If not passed, falls back to theclient stored on the current 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. Example: .. code-block:: python from google.cloud.storage.iam import STORAGE_OBJECT_VIEWER_ROLE policy = bucket.get_iam_policy(requested_policy_version=3) policy.version = 3 # Add a binding to the policy via it's bindings property policy.bindings.append({ "role": STORAGE_OBJECT_VIEWER_ROLE, "members": {"serviceAccount:account@project.iam.gserviceaccount.com", ...}, # Optional: "condition": { "title": "prefix" "description": "Objects matching prefix" "expression": "resource.name.startsWith("projects/project-name/buckets/bucket-name/objects/prefix")" } }) bucket.set_iam_policy(policy)

get_logging

get_logging()

Return info about access logging for this bucket.

Seehttps://cloud.google.com/storage/docs/access-logs#status

Returns
TypeDescription
dict or Nonea dict w/ keys,logBucket andlogObjectPrefix (if logging is enabled), or None (if not).

get_notification

get_notification(notification_id,client=None,timeout=60,retry=<google.api_core.retry.Retryobject>)

Get Pub / Sub notification for this bucket.

See:https://cloud.google.com/storage/docs/json_api/v1/notifications/get

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
notification_idstr

The notification id to retrieve the notification configuration.

clientClient orNoneType

(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
.BucketNotificationnotification instance. .. rubric:: Example Get notification using notification id. >>> from google.cloud import storage >>> client = storage.Client() >>> bucket = client.get_bucket('my-bucket-name') # API request. >>> notification = bucket.get_notification(notification_id='id') # API request.

list_blobs

list_blobs(max_results=None,page_token=None,prefix=None,delimiter=None,start_offset=None,end_offset=None,include_trailing_delimiter=None,versions=None,projection='noAcl',fields=None,client=None,timeout=60,retry=<google.api_core.retry.Retryobject>)
Parameters
NameDescription
max_resultsint

(Optional) The maximum number of blobs to return.

page_tokenstr

(Optional) If present, return the next batch of blobs, using the value, which must correspond to thenextPageToken value returned in the previous response. Deprecated: use thepages property of the returned iterator instead of manually passing the token.

prefixstr

(Optional) Prefix used to filter blobs.

delimiterstr

(Optional) Delimiter, used withprefix to emulate hierarchy.

start_offsetstr

(Optional) Filter results to objects whose names are lexicographically equal to or afterstartOffset. IfendOffset is also set, the objects listed will have names betweenstartOffset (inclusive) andendOffset (exclusive).

end_offsetstr

(Optional) Filter results to objects whose names are lexicographically beforeendOffset. IfstartOffset is also set, the objects listed will have names betweenstartOffset (inclusive) andendOffset (exclusive).

include_trailing_delimiterboolean

(Optional) If true, objects that end in exactly one instance ofdelimiter will have their metadata included initems in addition toprefixes.

versionsbool

(Optional) Whether object versions should be returned as separate blobs.

projectionstr

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

fieldsstr

(Optional) Selector specifying which fields to include in a partial response. Must be a list of fields. For example to get a partial response with just the next page token and the name and language of each blob returned:'items(name,contentLanguage),nextPageToken'. See:https://cloud.google.com/storage/docs/json_api/v1/parameters#fields

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.page_iterator.IteratorIterator of allBlob in this bucket matching the arguments. .. rubric:: Example List blobs in the bucket with user_project. >>> from google.cloud import storage >>> client = storage.Client() >>> bucket = storage.Bucket(client, "my-bucket-name", user_project="my-project") >>> all_blobs = list(client.list_blobs(bucket))

list_notifications

Parameters
NameDescription
clientClient orNoneType

(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.BucketNotificationnotification instances

lock_retention_policy

lock_retention_policy(client=None,timeout=60,retry=<google.api_core.retry.Retryobject>)

Lock the bucket's retention policy.

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

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

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

Exceptions
TypeDescription
ValueErrorif the bucket has no metageneration (i.e., new or never reloaded); if the bucket has no retention policy assigned; if the bucket's retention policy is already locked.

make_private

make_private(recursive=False,future=False,client=None,timeout=60,if_metageneration_match=None,if_metageneration_not_match=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Update bucket's ACL, revoking read access for anonymous users.

Parameters
NameDescription
recursivebool

If True, this will make all blobs inside the bucket private as well.

futurebool

If True, this will make all objects created in the future private as well.

clientClient orNoneType

(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

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration does not match the given value.

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

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

Exceptions
TypeDescription
ValueErrorIfrecursive is True, and the bucket contains more than 256 blobs. This is to prevent extremely long runtime of this method. For such buckets, iterate over the blobs returned bylist_blobs and callmake_private for each blob.

make_public

make_public(recursive=False,future=False,client=None,timeout=60,if_metageneration_match=None,if_metageneration_not_match=None,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)

Update bucket's ACL, granting read access to anonymous users.

Parameters
NameDescription
recursivebool

If True, this will make all blobs inside the bucket public as well.

futurebool

If True, this will make all objects created in the future public as well.

clientClient orNoneType

(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

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration does not match the given value.

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

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

Exceptions
TypeDescription
ValueErrorIfrecursive is True, and the bucket contains more than 256 blobs. This is to prevent extremely long runtime of this method. For such buckets, iterate over the blobs returned bylist_blobs and callmake_public for each blob.

notification

notification(topic_name=None,topic_project=None,custom_attributes=None,event_types=None,blob_name_prefix=None,payload_format="NONE",notification_id=None,)

Factory: create a notification resource for the bucket.

See:.BucketNotification for parameters.

patch

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

Sends all changed properties in a PATCH request.

Updates the_properties with the response from the backend.

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
clientClient orNoneType

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

timeoutfloat or tuple

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

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration does not match the given value.

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

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

path_helper

path_helper(bucket_name)

Relative URL path for a bucket.

Parameter
NameDescription
bucket_namestr

The bucket name in the path.

Returns
TypeDescription
strThe relative URL path forbucket_name.

reload

reload(client=None,projection='noAcl',timeout=60,if_etag_match=None,if_etag_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,retry=<google.api_core.retry.Retryobject>)

Reload properties from Cloud Storage.

Ifuser_project is set, bills the API request to that project.

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.

timeoutfloat or tuple

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

if_etag_matchUnion[str, Set[str]]

(Optional) Make the operation conditional on whether the bucket's current ETag matches the given value.

if_etag_not_matchUnion[str, Set[str]])

(Optional) Make the operation conditional on whether the bucket's current ETag does not match the given value.

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the bucket's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the bucket's current metageneration does not match the given value.

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

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

rename_blob

rename_blob(blob,new_name,client=None,if_generation_match=None,if_generation_not_match=None,if_metageneration_match=None,if_metageneration_not_match=None,if_source_generation_match=None,if_source_generation_not_match=None,if_source_metageneration_match=None,if_source_metageneration_not_match=None,timeout=60,retry=<google.cloud.storage.retry.ConditionalRetryPolicyobject>)
Parameters
NameDescription
blobBlob

The blob to be renamed.

new_namestr

The new name for this blob.

clientClient orNoneType

(Optional) The client to use. If not passed, falls back to theclient stored on the current 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. Also used in the (implied) delete request.

if_source_generation_not_matchlong

(Optional) Makes the operation conditional on whether the source object's generation does not match the given value. Also used in the (implied) delete request.

if_source_metageneration_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration matches the given value. Also used in the (implied) delete request.

if_source_metageneration_not_matchlong

(Optional) Makes the operation conditional on whether the source object's current metageneration does not match the given value. Also used in the (implied) delete request.

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
BlobThe newly-renamed blob.

set_iam_policy

Parameters
NameDescription
policygoogle.api_core.iam.Policy

policy instance used to update bucket's IAM policy.

clientClient orNoneType

(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

test_iam_permissions(permissions,client=None,timeout=60,retry=<google.api_core.retry.Retryobject>)

API call: test permissions

Seehttps://cloud.google.com/storage/docs/json_api/v1/buckets/testIamPermissions

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
permissionslist of string

the permissions to check

clientClient orNoneType

(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

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

Sends all properties in a PUT request.

Updates the_properties with the response from the backend.

Ifuser_project is set, bills the API request to that project.

Parameters
NameDescription
clientClient orNoneType

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

timeoutfloat or tuple

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

if_metageneration_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration matches the given value.

if_metageneration_not_matchlong

(Optional) Make the operation conditional on whether the blob's current metageneration does not match the given value.

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

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

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.