This example is a very simple "hello world" application, written in Python, that illustrates how to:
- Connect to a Cloud Bigtable instance.
- Create a new table.
- Write data to the table.
- Read the data back.
- Delete the table.
Running the sample
This example uses the HappyBase package of the Google Cloud Client Library for Python, an implementation of the HappyBase APIs, to communicate with Cloud Bigtable. Use the HappyBase package if you need to move an existing HBase workload to Cloud Bigtable. For new applications, see the "hello world" example that uses the Cloud Bigtable package.
To run this sample program, follow the instructions for the sample on GitHub.
Using the HappyBase APIs with Cloud Bigtable
The sample application connects to Cloud Bigtable and demonstrates some simple operations.
Installing and importing the client library
The required Python packages can be installed using PIP into a virtualenv environment. The sample includes a requirements file defining the needed packages.
The modules can then be imported.
Connecting to Cloud Bigtable
Connect to the Cloud Bigtable by passing a
bigtable.Client
to a
happybase.Connection
.
Creating a table
Use Connection.create_table()
to
create a table and its column families.
Writing rows to a table
Get an existing Table
with
Connection.table()
. Use
Table.put()
to write a row to the table.
Reading a row by its key
Get a row directly using its key with Table.row()
.
Scanning all table rows
Use Table.scan()
to get a range of rows.
Deleting a table
Delete a table with
Connection.delete_table()
.
Putting it all together
Here is the full example without comments.