This example is a "hello world" application, written in Python, that illustrates how to do the following:

  • Set up authentication.
  • Connect to a Bigtable instance.
  • Create a new table.
  • Write data to the table.
  • Read the data back.
  • Delete the table.

The Python client library for Bigtable offers two APIs, asyncio and a synchronous API. If your application is asynchronous, use asyncio.

Set up authentication

To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

  1. Install the Google Cloud CLI.

  2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  3. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

For more information, see Set up authentication for a local development environment.

Run the sample

This example uses the Bigtable package of the Cloud Client Libraries for Python to communicate with Bigtable. The Bigtable package is the best choice for new applications. If you need to move an existing HBase workload to Bigtable, see the "hello world" example that uses the HappyBase package.

To run this sample program, follow the instructions for the sample on GitHub.

Use the Cloud Client Libraries with Bigtable

The sample application connects to Bigtable and demonstrates some operations.

Install and import the client library

Use PIP to install the required Python packages into a virtualenv environment. The sample includes a requirements file defining the needed packages.

Import the modules.

Connect to Bigtable

Connect to Bigtable using a bigtable.Client.

Create a table

Instantiate a table object using Instance.table(). Create a column family and set its garbage collection policy, then pass the column family to Table.create() to create the table.

Write rows to a table

Loop through a list of greeting strings to create some new rows for the table. In each iteration, use Table.row() to define a row and assign it a row key; call Row.set_cell() to set a value for the current cell; and append the new row to an array of rows. Finally, call Table.mutate_rows() to add the rows to the table.

Create a filter

Before you read the data that you wrote, create a filter using row_filters.CellsColumnLimitFilter() to limit the data that Bigtable returns. This filter tells Bigtable to return only the most recent cell in each column, even if the table contains older cells that haven't been removed yet during garbage collection.

Read a row by its row key

Call the table's Table.read_row() method to get a reference to the row with a specific row key, passing in the key and the filter, to get one version of each value in that row.

Scan all table rows

Use Table.read_rows() to read a range of rows from a table.

Delete a table

Delete a table with Table.delete().

Put it all together

Here is the full example without comments.

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 2026-03-30 UTC.