gcs_client.bucket module

class gcs_client.bucket.Bucket(name=None, credentials=None, retry_params=None)[source]

Bases: gcs_client.base.Fillable, gcs_client.base.Listable

GCS Bucket Object representation.

Variables:
  • kind (string) – The kind of item this is. For buckets, this is always storage#bucket.
  • name (string) – The name of the bucket.
  • timeCreated (string) – The creation time of the bucket in RFC 3339 format.
  • updated (string) – The modification time of the bucket in RFC 3339 format.
  • id (string) – The ID of the bucket.
  • metageneration (long) – The metadata generation of this bucket.
  • location (string) – The location of the bucket. Object data for objects in the bucket resides in physical storage within this region. Defaults to US. See the developer’s guide for the authoritative list: https://cloud.google.com/storage/docs/bucket-locations
  • owner (dict) – The owner of the object. This will always be the uploader of the object. Contains entity and entityId keys.
  • etag (string) – HTTP 1.1 Entity tag for the object.
  • projectNumber (long) – The project number of the project the bucket belongs to.
  • selfLink (string) – The link to this object.
  • storageClass (string) – Storage class of the object.

Initialize a Bucket object.

Parameters:
  • name (String) – Name of the bucket to use.
  • credentials (gcs_client.Credentials) – A credentials object to authorize the connection.
  • retry_params (RetryParams or NoneType) – Retry configuration used for communications with GCS. If None is passed default retries will be used.
delete(*args, **kwargs)[source]

Permanently deletes an empty bucket from a Project.

The authenticated user in credentials must be a member of the project’s team as an editor or owner.

Parameters:
  • if_metageneration_match (long) – If set, only deletes the bucket if its metageneration matches this value.
  • if_metageneration_not_match (long) – If set, only deletes the bucket if its metageneration does not match this value.
Returns:

None

exists(*args, **kwargs)

Check if exists in GCS server.

list(prefix=None, maxResults=None, versions=None, delimiter=None, projection=None, pageToken=None)[source]

List Objects matching the criteria contained in the Bucket.

In conjunction with the prefix filter, the use of the delimiter parameter allows the list method to operate like a directory listing, despite the object namespace being flat. For example, if delimiter were set to “/”, then listing objects from a bucket that contains the objects “a/b”, “a/c”, “d”, “e”, “e/f” would return objects “d” and “e”, and prefixes “a/” and “e/”.

The authenticated user must have READER permissions on the bucket.

Object list operations are eventually consistent. This means that if you upload an object to a bucket and then immediately perform a list operation on the bucket in which the object is stored, the uploaded object might not immediately appear in the returned list of objects. However, you can always immediately download a newly-created object and get its ACLs because object uploads are strongly consistent.

Parameters:
  • prefix (String) – Filter results to objects whose names begin with this prefix.
  • maxResults (Unsigned integer) – Maximum number of items plus prefixes to return. As duplicate prefixes are omitted, fewer total results may be returned than requested. The default value of this parameter is 1,000 items.
  • versions (bool) – If True, lists all versions of an object as distinct results. The default is False.
  • delimiter (String) – Returns results in a directory-like mode. Objects whose names, aside from the prefix, do not contain delimiter with be returned as Object instances. Objects whose names, aside from the prefix, contain delimiter will be returned as Prefix instances. Duplicate prefixes are omitted.
  • projection (String) –

    Set of properties to return. Defaults to noAcl. Acceptable values are:

    “full”: Include all properties. “noAcl”: Omit the acl property.
  • pageToken (String) – A previously-returned page token representing part of the larger set of results to view. The pageToken is an encoded field representing the name and generation of the last object in the returned list. In a subsequent request using the pageToken, items that come after the pageToken are shown (up to maxResults). Object list operations are eventually consistent. In addition, if you start a listing and then create an object in the bucket before using a pageToken to continue listing, you will not see the new object in subsequent listing results if it is in part of the object namespace already listed.
Returns:

List of objects and prefixes that match the criteria.

Return type:

List of gcs_client.Object and gcs_client.Prefix.

open(name, mode='r', generation=None, chunksize=None)[source]

Open an object from the Bucket.

Parameters:
  • name (String) – Name of the file to open.
  • mode (String) – Mode to open the file with, ‘r’ for read and ‘w’ for writing are only supported formats. Default is ‘r’ if this argument is not provided.
  • generation (long) – If present, selects a specific revision of this object (as opposed to the latest version, the default).
  • chunksize (int) – Size in bytes of the payload to send/receive to/from GCS. Default is gcs_client.DEFAULT_BLOCK_SIZE
credentials

Credentials used to connect to GCS server.

kind = 'storage#buckets'
retry_params

Get retry configuration used by this instance for accessing GCS.