gcs_client.prefix module

class gcs_client.prefix.Prefix(name, prefix, delimiter=None, credentials=None, retry_params=None)[source]

Bases: gcs_client.base.Listable

GCS Prefix Object representation.

Represents prefixes returned from listing objects inside a bucket using a delimiter.

A Prefix object can be thought of as a directory in a filesystem.

Variables:
  • kind (string) – The kind of item this is. For buckets, this is always storage#prefix.
  • name (string) – Bucket name that this prefix belongs to.
  • prefix (string) – Prefix name (like the full path of a directory).
  • delimiter (string) – Delimiter used to generate this prefix.

Initialize a prefix representation.

Parameters:
  • name (String) – Name of the bucket this prefix belongs to.
  • prefix (String) – Prefix name (like the full path of a directory).
  • delimiter (String) – Delimiter used on the listing
  • 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.
exists(*args, **kwargs)

Check if exists in GCS server.

list(prefix='', 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.

This differs slightly from bucket listing, because if no delimiter is provided it will use the delimiter that was used on the listing that generated the instance. Likewise for the prefix.

Parameters:
  • prefix (String) – Filter results in this ‘directory’ to objects whose names begin with this prefix. Default is to list all objects in the directory.
  • 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. Default use delimiter that was used to create this prefix.
  • 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.

credentials

Credentials used to connect to GCS server.

kind = 'storage#prefix'
retry_params

Get retry configuration used by this instance for accessing GCS.