Google Cloud Notebooks

1.16.0 · active · verified Thu Apr 16

The `google-cloud-notebooks` client library provides Python access to the Google Cloud AI Platform Notebooks API. This managed service offers an integrated and secure JupyterLab environment for data scientists and machine learning developers to experiment, develop, and deploy models into production. The library is currently at version 1.16.0 and is part of the broader `google-cloud-python` ecosystem, which maintains a frequent release cadence, often with monthly updates for various client libraries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the `NotebookServiceClient` and lists existing Notebook instances in a specified Google Cloud project and location. Ensure your `GCP_PROJECT_ID` and `GCP_LOCATION` environment variables are set, or replace the placeholder values. Authentication typically relies on Application Default Credentials, which can be set up using `gcloud auth application-default login` for local development.

import os
from google.cloud.notebooks_v1.services.notebook_service import NotebookServiceClient
from google.cloud.notebooks_v1 import types

# Set your Google Cloud Project ID and desired location (e.g., 'us-central1')
project_id = os.environ.get('GCP_PROJECT_ID', 'your-gcp-project-id')
location = os.environ.get('GCP_LOCATION', 'us-central1')

def list_notebook_instances(project_id: str, location: str):
    """Lists all Notebook instances in a given project and location."""
    client = NotebookServiceClient()
    parent = f"projects/{project_id}/locations/{location}"

    print(f"Listing Notebook instances in {parent}:")
    try:
        request = types.ListInstancesRequest(parent=parent)
        page_result = client.list_instances(request=request)

        for response in page_result:
            print(f"  Instance: {response.name} (State: {response.state.name})")
        if not page_result:
            print("  No instances found.")

    except Exception as e:
        print(f"Error listing instances: {e}")
        print("Ensure the Notebooks API is enabled for your project and location.")
        print("Also, verify that your default credentials are set up (e.g., `gcloud auth application-default login`).")

if __name__ == "__main__":
    list_notebook_instances(project_id, location)

view raw JSON →