Google Cloud Bigtable C++ Client  2.1.0
A C++ Client Library for Google Cloud Bigtable
Google Cloud Platform Bigtable C++ Client Library


Cloud Bigtable is Google's NoSQL Big Data database service. It's the same database that powers many core Google services, including Search, Analytics, Maps, and Gmail.

The Cloud Bigtable C++ Client library offers types and functions to access Cloud Bigtable from C++ applications (Read more about Cloud Bigtable). It offers access to the Cloud Bigtable API, including operations to list, read, write, and delete Instances and Clusters, Tables and Application Profiles.


The following instructions show you how to perform basic tasks in Cloud Bigtable using the C++ client library.

Before you begin

  1. Select or create a Google Cloud Platform (GCP) project using the manage resource page. Make a note of the project id, you will need to use it later.
  2. Make sure that billing is enabled for your project.
  3. Learn about key terms and concepts for Cloud Bigtable.
  4. Setup the authentication for the examples:

Setting up your repo

In order to use the Cloud Bigtable C++ client library from your own code, you'll need to configure your build system how to fetch and compile the Cloud C++ client library. The Cloud C++ client library natively supports the Bazel and CMake build systems. We've created a minimal, "Hello world", quickstart repo that includes detailed instructions on how to compile the library for use in your application. You can fetch the source from GitHub as normal:

git clone
cd google-cloud-cpp/google/cloud/bigtable/quickstart
Example: Quickstart

The following shows the code that you'll run in the google/cloud/bigtable/quickstart/ directory, which should give you a taste of the Cloud Bigtable C++ client library API.

// Copyright 2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
// [START bigtable_quickstart]
int main(int argc, char* argv[]) try {
if (argc != 4) {
std::string const cmd = argv[0];
auto last_slash = std::string(cmd).find_last_of('/');
std::cerr << "Usage: " << cmd.substr(last_slash + 1)
<< " <project_id> <instance_id> <table_id>\n";
return 1;
std::string const project_id = argv[1];
std::string const instance_id = argv[2];
std::string const table_id = argv[3];
// Create a namespace alias to make the code easier to read.
namespace cbt = ::google::cloud::bigtable;
cbt::Table table(cbt::MakeDataConnection(),
cbt::TableResource(project_id, instance_id, table_id));
std::string row_key = "r1";
std::string column_family = "cf1";
std::cout << "Getting a single row by row key:" << std::flush;
table.ReadRow(row_key, cbt::Filter::FamilyRegex(column_family));
if (!result) throw std::runtime_error(result.status().message());
if (!result->first) {
std::cout << "Cannot find row " << row_key << " in the table: " << table_id
<< "\n";
return 0;
cbt::Cell const& cell = result->second.cells().front();
std::cout << cell.family_name() << ":" << cell.column_qualifier() << " @ "
<< cell.timestamp().count() << "us\n"
<< '"' << cell.value() << '"' << "\n";
return 0;
} catch (std::exception const& ex) {
std::cerr << "Standard C++ exception raised: " << ex.what() << "\n";
return 1;
// [END bigtable_quickstart]
Status const & status() const &
std::string const & message() const
std::shared_ptr< DataConnection > MakeDataConnection(Options options={})
Returns a DataConnection object that can be used for interacting with the Cloud Bigtable Data API.

API Notes

  • GOOGLE_CLOUD_PROJECT=... is used in examples and integration tests to configure the GCP project.
  • BIGTABLE_EMULATOR_HOST=host:port tells the library to connect to the specified emulator rather than the default endpoint.
  • GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc turns on tracing for most gRPC calls, the library injects an additional Stub decorator that prints each gRPC request and response. Unless you have configured you own logging backend, you should also set GOOGLE_CLOUD_CPP_ENABLE_CLOG to produce any output on the program's console.
  • GOOGLE_CLOUD_CPP_TRACING_OPTIONS=... modifies the behavior of gRPC tracing, including whether messages will be output on multiple lines, or whether string/bytes fields will be truncated.
  • GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes turns on logging in the library, basically the library always "logs" but the logging infrastructure has no backend to actually print anything until the application sets a backend or they set this environment variable.

Next Steps