Notebooks API C++ Client 2.8.0
A C++ Client Library for the Notebooks API
No Matches
Notebooks API C++ Client Library

An idiomatic C++ client library for the Notebooks API. Use this API to programmatically manage notebooks in Google Cloud. Learn more about notebooks at the Vertex AI Workbench site.

While this library is GA, please note Google Cloud C++ client libraries do not follow Semantic Versioning.

This library requires a C++14 compiler. It is supported (and tested) on multiple Linux distributions, as well as Windows and macOS. The README on GitHub provides detailed instructions to install the necessary dependencies, as well as how to compile the client library.

Setting up your repo

In order to use the Notebooks API C++ client library from your own code, you'll need to configure your build system to discover and compile the Cloud C++ client libraries. In some cases your build system or package manager may need to download the libraries too. The Cloud C++ client libraries natively support Bazel and CMake as build systems. We've created a minimal, "Hello World", quickstart 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/notebooks/quickstart
Example: Quickstart

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

#include "google/cloud/notebooks/managed_notebook_client.h"
#include <iostream>
int main(int argc, char* argv[]) try {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " project-id location-id\n";
return 1;
namespace notebooks = ::google::cloud::notebooks;
auto client = notebooks::ManagedNotebookServiceClient(
auto const parent =
std::string{"projects/"} + argv[1] + "/locations/" + argv[2];
for (auto r : client.ListRuntimes(parent)) {
if (!r) throw std::move(r).status();
std::cout << r->DebugString() << "\n";
return 0;
} catch (google::cloud::Status const& status) {
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return 1;

Environment Variables

  • GOOGLE_CLOUD_CPP_MANAGED_NOTEBOOK_SERVICE_ENDPOINT=... overrides the EndpointOption (which defaults to "") used by MakeManagedNotebookServiceConnection().
  • GOOGLE_CLOUD_CPP_NOTEBOOK_SERVICE_ENDPOINT=... overrides the EndpointOption (which defaults to "") used by MakeNotebookServiceConnection().
  • 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 your own logging backend, you should also set GOOGLE_CLOUD_CPP_ENABLE_CLOG to produce any output on the program's console.
  • GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc-streams turns on tracing for streaming gRPC calls. This can produce a lot of output, so use with caution!
  • 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 it sets this environment variable.

Error Handling

This library never throws exceptions to signal error, but you can use exceptions to detect errors in the returned objects. In general, the library returns a StatusOr<T> if an error is possible. This is an "outcome" type, when the operation is successful a StatusOr<T> converts to true in boolean context (and its .ok() member function returns true), the application can then use operator-> or operator* to access the T value. When the operation fails a StatusOr<T> converts to false (and .ok() returns false). It is undefined behavior to use the value in this case.

If you prefer to use exceptions on error, you can use the .value() accessor. It will return the T value or throw on error.

For operations that do not return a value the library simply returns google::cloud::Status.

Override the default endpoint

In some cases, you may need to override the default endpoint used by the client library. Use the google::cloud::EndpointOption when initializing the client library to change this default.

For example, this will override the default endpoint for notebooks_v1::ManagedNotebookServiceClient:

// This configuration is common with Private Google Access:
Options & set(ValueTypeT< T > v)
API v1 service for Managed Notebooks.
Definition: managed_notebook_client.h:62
std::shared_ptr< ManagedNotebookServiceConnection > MakeManagedNotebookServiceConnection(Options options={})
A factory function to construct an object of type ManagedNotebookServiceConnection.

Follow these links to find examples for other *Client classes: notebooks_v1::ManagedNotebookServiceClient notebooks_v1::NotebookServiceClient

Override the authentication configuration

Some applications cannot use the default authentication mechanism (known as Application Default Credentials). You can override this default using google::cloud::UnifiedCredentialsOption. The following example shows how to explicitly load a service account key file.

[](std::string const& keyfile) {
auto is = std::ifstream(keyfile);
is.exceptions(std::ios::badbit); // Minimal error handling in examples
auto contents = std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
auto options =
std::shared_ptr< Credentials > MakeServiceAccountCredentials(std::string json_object, Options opts={})

Follow these links to find examples for other *Client classes: notebooks_v1::ManagedNotebookServiceClient notebooks_v1::NotebookServiceClient

Keep in mind that we chose this as an example because it is relatively easy to understand. Consult the Best practices for managing service account keys guide for more details.

See also
Authentication Components - for more information on the factory functions to create google::cloud::Credentials objects.

Retry, Backoff, and Idempotency Policies.

The library automatically retries requests that fail with transient errors, and uses exponential backoff to backoff between retries. Application developers can override the default policies.