Google Cloud Bigtable: Python

To use the API, the Client class defines a high-level interface which handles authorization and creating other objects:

from gcloud_bigtable.client import Client
cluster = Client()

This will use the Google Application Default Credentials if you don’t pass any credentials of your own.

The Cluster Admin API has been fully implemented. Create a Cluster to get a high-level interface to cluster management:

cluster = client.cluster(zone, cluster_id)

List Clusters

If you want a comprehensive list of all existing clusters, make a ListClusters request:

clusters = client.list_clusters()

This will return a list of Cluster s.

List Zones

If you aren’t sure which zone to create a cluster in, find out which zones your project has access to with a ListZones request:

zones = client.list_clusters()

This will return a list of string s.

Create a new Cluster

After creating the cluster object, make a CreateCluster API request:

cluster.display_name = 'My very own cluster'
cluster.create()

If you would like more than the minimum number of nodes (3) in your cluster:

cluster.serve_nodes = 10
cluster.create()

Note

When modifying a cluster (via a CreateCluster, UpdateCluster or UndeleteCluster request), the Bigtable API will return a long-running Operation. This will be stored on the object after each of create(), update() and undelete() are called.

Check on Current Operation

You can check if a long-running operation (for a create(), update() or undelete()) has finished by making a GetOperation request:

>>> cluster.operation_finished()
True

Note

The operation data is stored in protected fields on the Cluster: _operation_type, _operation_id and _operation_begin. If these are unset, then operation_finished() will fail. Also, these will be removed after a long-running operation has completed (checked via this method). We could easily surface these properties publicly, but it’s unclear if end-users would need them.

Get metadata for an existing Cluster

After creating the cluster object, make a GetCluster API request:

cluster.reload()

This will load serve_nodes and display_name for the existing cluster in addition to the cluster_id, zone and project_id already set on the Cluster object.

Update an existing Cluster

After creating the cluster object, make an UpdateCluster API request:

client.display_name = 'New display_name'
cluster.update()

Delete an existing Cluster

Make a DeleteCluster API request:

cluster.delete()

Undelete a deleted Cluster

Make a UndeleteCluster API request:

cluster.undelete()

Indices and tables