Stay organized with collections Save and categorize content based on your preferences.
The App Engine client library for Cloud Storage provides the following functions:
Functions
Once cloudstorage.open()
is invoked to return the file-like object representing the Cloud Storage object specified, you can use the standard Python file functions, such as write()
and close()
, to write an object to the Cloud Storage bucket, or read()
to read an object from the Cloud Storage bucket.
Classes
FunctionsCopies the specified file to the new specified filename, by default copying over the metadata as well. Optionally, you can overwrite the metadata in the copy by providing the optional metadata
param.
Raises cloudstorage.NotFoundError if the specified Cloud Storage object doesn't exist or cloudstorage.AuthorizationError if authorization failed.
Arguments
/bucket/object_name
. Must be a full filename and can include the delimiter `/`.
/bucket/object_name
. Must be a full filename and can include the delimiter `/`.
{'x-goog-meta-foo': 'bar'}
. If you supply the metadata param, none of the original metadata is copied over to the new file. If no metadata is supplied, (None
), all of the source file metadata is copied over.
Example
import cloudstorage try: cloudstorage.copy2('/my_bucket/README', '/my_bucket/README2', metadata={'x-goog-meta-zzzzz': 'zzzzz'}) except cloudstorage.NotFoundError: pass
Deletes the specified file from the Cloud Storage bucket.
Raises cloudstorage.NotFoundError if the specified Cloud Storage object doesn't exist.
Arguments
/bucket/object_name
. Must be a full filename and can include the delimiter `/`.
Example
import cloudstorage try: cloudstorage.delete(filename) except cloudstorage.NotFoundError: pass
This function operates in two different modes depending on whether you use the delimiter
argument or not:
delimiter
argument, it is used as a path separator to emulate a hierarchy of directories.Arguments
/bucket
or /bucket/prefix
, for example, /bucket/foo/2001
. Only objects whose fullpath starts with path_prefix
will be returned.
superduperfoo3.txt
to be listed, you specify the file immediately preceding superduperfoo3.txt
, for example:
stat = cloudstorage.listbucket("/my_bucket/foo", marker='/my_bucket/foo/superduperfoo2.txt')One way to use this parameter is to use it with
max_keys
to "page through" the bucket file names.
marker
to page through filenames in a bucket.
stats = cloudstorage.listbucket(bucket + '/foo', max_keys=page_size, marker=stat.filename)
Result Value
Returns an iterator of GCSFileStat objects over the matched files, sorted by filename. In regular mode, the returned GCSFileStat
objects have the following data:
filename
etag
(The hex representation of the MD5 hash of the file's contents)st_size
(content length of headers)st_ctime
is_dir
Note: If the GCSFileStat
object's is_dir
property is True
, then the only other property in the object is filename
. If is_dir
is False
, then the GCSFileStat
contains all of the other properties as well.
In read mode (r
) opens the specified Cloud Storage object for read. In write mode w
, if the specified file exists, it opens it for an overwrite (append is not supported). If the file doesn't exist, it is created in the specified bucket.
When you finish writing, if you want to read the file and/or store it at Cloud Storage, close the file using the close
function. It is not an error if you don't call close
, but the file will not be readable or persisted at Cloud Storage.
Raises:
Arguments
/bucket/object
. For example,/my_bucket/lyrics/southamerica/list5.txt
.
binary/octet-stream
when it serves the object.
Dict. Used only in write mode. Supported options are x-goog-acl
, x-goog-meta-
, cache-control
, content-disposition
and content-encoding
.
If you don't supply an x-goog-acl
option, Cloud Storage uses the bucket's default ACL. The valid values for x-goog-acl
are listed in the Cloud Storage documentation for x-goog-acl.
You can specify custom object metadata using x-goog-meta- headers. For example:
gcs_file = cloudstorage.open(filename, 'w', content_type='text/plain', options={'x-goog-acl': 'private','x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'})
read_buffer_size
for optimum prefetch performance.
Result Value
Returns a reading or writing buffer, supporting a file-like interface on which you can invoke standard Python read
, write
, and close
functions. This buffer must be closed after you finish reading or writing.
Returns a GCSFileStat object containing file metadata.
Raises cloudstorage.NotFoundError if the specified Cloud Storage object doesn't exist.
Arguments
/bucket/object
. For example,/my_bucket/lyrics/southamerica/list5.txt
Result Value
Returns a GCSFileStat object containing file metadata.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-18 UTC."],[[["The `cloudstorage` library enables interaction with Cloud Storage buckets, offering functions to manage files within them."],["`cloudstorage.copy2()` allows copying a file to a new location within the same bucket, with the option to modify metadata during the copy process."],["`cloudstorage.delete()` removes a specified object from a Cloud Storage bucket, raising an error if the file doesn't exist."],["`cloudstorage.listbucket()` retrieves a list of objects in a bucket, supporting both flat listing and directory-like structures via the `delimiter` parameter."],["`cloudstorage.open()` provides file-like object access to Cloud Storage objects for reading or overwriting, enabling interaction through standard Python file functions like `read()`, `write()`, and `close()`."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4