Skip to main content

RESTful Python Client for Google Cloud

Project description

This project is a collection of Google Cloud client libraries for the REST-only APIs; its raison d’etre is to implement a simple CloudTasks API as well as a more abstract TaskManager. That… isn’t as relevant now that Google has deprecated PullQueue-style tasks, but this library will continue to be OSS to provide support to anyone looking for a concurrency-friendly approach to interacting with the GCP APIs in Python 2 and 3.

If you don’t need to support Python 2, you probably want to use gcloud-aio, which has support for all the same APIs (and more!) and additionally includes native support for asyncio.

Latest PyPI Version CircleCI Test Status Code Coverage Python Version Support

Some of the client libraries live in separate packages:

Note that all the modules will eventually be released separately, and the gcloud-rest package will be deprecated.


$ pip install --upgrade gcloud-rest

(or, for the packages released independently):

$ pip install --upgrade gcloud-rest-datastore


This project currently exposes interfaces to CloudTasks, Datastore, KMS, and Storage.

For the libraries that are packaged separately, you can find usage examples in the corresponding README file.

For the others, keep reading.

Storage (see

from import Bucket

bk = Bucket('my-project', 'bucket-name')

# list all objects
objects_in_bucket = bk.list_objects()
# list objects with prefix
objects_in_bucket = bk.list_objects(prefix='in/subdir/')

object ='object-name')
object_contents = bk.download_as_string('object-name')

KMS (see

from import KMS
from import encode

kms = KMS('my-project', 'my-keyring', 'my-key-name')

# encrypt
plaintext = 'the-best-animal-is-the-aardvark'
ciphertext = kms.encrypt(encode(plaintext))

# decrypt
assert kms.decode(encode(ciphertext)) == plaintext

TaskQueue (for CloudTasks, see

from import decode
from import encode
from import TaskQueue

tq = TaskQueue('my-project', 'taskqueue-name')

# create a task
payload = 'aardvarks-are-awesome'

# list and get tasks
tasks = tq.list()
random_task = tasks.get('tasks')[42]
random_task_body = tq.get(random_task['name'])

# lease, renew, and ack/cancel/delete tasks
task_leases =
tasks = task_lease.get('tasks')
# assert len(tasks) <= 3

for task in tasks:
    payload = decode(task['pullMessage']['payload']).decode()

    # you'll need to renew the task if you take longer than
    # task['scheduleTime'] to process it

    # do something with payload

    if success:
    elif temporary_failure:
    elif permanent_failure:

TaskManager (for CloudTasks, see

from import FailFastError
from import TaskManager

def worker_method(payloads):
    for task in payloads:
        # do something with the task

        if success:
            yield 'anything'
        elif temporary_failure:
            yield Exception('insert message here')
        elif permanent_failure:
            yeild FailFastError('insert message here')

tm = TaskManager('my-project', 'taskqueue-name', worker_method)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for gcloud-rest, version 2.0.0
Filename, size & hash File type Python version Upload date
gcloud_rest-2.0.0-py2.py3-none-any.whl (16.5 kB) View hashes Wheel py2.py3
gcloud-rest-2.0.0.tar.gz (12.9 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page