Hide
Python

Migrating from the Google Cloud Storage API

If your code currently uses the Google Cloud Storage API, sometimes referred to as the Files API, the migration to the GCS client library is straightforward, as the client library supports very similar functionality. The one exception is bulk deletes, which are only available in the Google Cloud Storage API. The client library does not support bulk deletes. Instead, you will need to specify each file to be deleted in a separate call.

The following table compares the functionality provided by the deprecated Files API and the new client library:

Feature Cloud Storage API (Files API) Client Library Differences
Distribution google.appengine.api.files package in the SDK. Download the library into your project. client-side only library
Imports from google.appengine.api import files import cloudstorage
Create files.gs.create() No longer needed. Client library combines create/open in one call, cloudstorage.open().
Open files.open() cloudstorage.open() supports everything in old open.
List bucket Contents files.listdir() cloudstorage.listbucket Same options and behavior; cloudstorage.listbucket() returns an iterator object, GCSFileStat. However, the new listbucket also has a directory emulation mode.
Delete File files.delete() cloudstorage.delete() Client library doesn't support bulk deletes.
File metadata None cloudstorage.stat() Client library returns last-modified time, header-length, content type for the specified file.
Read/write/tell/seek/close files.File.write(),files.File.read(), files.File.tell(), files.File.seek(), files.File.close() Standard Python write, read, tell,seek, and close. Direct replacement.
Finalize files.File.finalize() No longer needed. (Standard Python close finalizes the file.)
Buffering BufferedFile() class "Built-in" buffering Client library buffers all reads, and includes a prefetch buffer that gets filled while your app processes from the read buffer.