Create notebooks

For support during the preview, email bigquery-notebooks-support@google.com.

This document describes how to create Colab Enterprise notebooks in BigQuery. Notebooks are BigQuery Studio code assets powered by Dataform.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the BigQuery API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the BigQuery API.

    Enable the API

Enable BigQuery Studio

Follow the instructions at Enable BigQuery Studio for asset management to save, share, and manage versions of code assets such as notebooks.

Required permissions

Set the appropriate permissions to create, edit, or view notebooks.

All users with the Dataform Admin (roles/dataform.admin) role have owner access to all notebooks created in the project.

For more information about BigQuery Identity and Access Management (IAM), see Access control with IAM.

Permissions to create notebooks

To create and run notebooks, you need the following IAM permissions:

  • resourcemanager.projects.get
  • resourcemanager.projects.list
  • bigquery.config.get
  • bigquery.jobs.create
  • bigquery.readsessions.create
  • bigquery.readsessions.getData
  • bigquery.readsessions.update
  • resourcemanager.projects.get
  • resourcemanager.projects.list
  • dataform.locations.get
  • dataform.locations.list
  • dataform.repositories.create

  • dataform.repositories.list

  • dataform.collections.create

  • dataform.collections.list

  • aiplatform.notebookRuntimeTemplates.apply

  • aiplatform.notebookRuntimeTemplates.get

  • aiplatform.notebookRuntimeTemplates.list

  • aiplatform.notebookRuntimeTemplates.getIamPolicy

  • aiplatform.notebookRuntimes.assign

  • aiplatform.notebookRuntimes.get

  • aiplatform.notebookRuntimes.list

  • aiplatform.operations.list

You can get these permissions from the following IAM roles:

Permissions to edit notebooks

To edit and run notebooks, you need the following IAM roles:

Permissions to view notebooks

To view and run notebooks, you need the following IAM roles:

Create notebooks

Use the following sections to learn how to create a notebook.

Set the default region for code assets

If this is the first time you are creating a code asset, set the default region for code assets. You can't change the region for a code asset after it is created.

Create a notebook from the BigQuery editor

To create a notebook containing a default query for a given table, follow these steps:

  1. Go to the BigQuery page.

    Go to BigQuery

  2. In the tab bar of the editor pane, click the arrow drop down next to the + sign and then click Compose new Python notebook:

    notebook-tab

    The new notebook opens, containing cells that show example queries against the bigquery-public-data.ml_datasets.penguins public dataset.

Create a notebook from a table

To create a notebook containing a default query for a specific table, follow these steps:

  1. Go to the BigQuery page.

    Go to BigQuery

  2. In the Explorer pane, find the table you want to query.

  3. Click View actions next to the table, click Query in > Python notebook.

    The new notebook opens, containing cells that show example queries against the selected table.

Create a notebook to explore the result set of a query

To create a notebook to explore the result set of a query, follow these steps:

  1. Go to the BigQuery page.

    Go to BigQuery

  2. In the editor pane, run a query that generates a query result.

  3. In the Query results pane, click Explore Data and then click Explore with Python notebook.

    The new notebook opens, containing cells with code to return the query SQL and the query results.

Create a notebook from an existing notebook

To open any version of an existing notebook as a new notebook, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Select a notebook.
  2. Select the Activity pane.
  3. Click View actions next to a notebook version and then click Open as new Python notebook.

    A copy of the notebook is opened as a new notebook.

Upload notebooks

You can upload a notebook by using Vertex AI in the Google Cloud console. The uploaded notebook is then also visible in the BigQuery page of the Google Cloud console. For more information, see Upload a notebook.

Connect to a runtime

Use the following sections to learn how to connect a notebook to a Vertex AI runtime. A runtime is a compute resource that runs the code in your notebook.

Connect to the default runtime

The default runtime is a preset runtime that requires minimal setup.

To connect to the default runtime, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Click the name of a notebook to open it.
  2. In the notebook, click Connect, or run any cell in the notebook.

    It might take several minutes to connect to the default runtime if you don't already have an active runtime.

Connect to a non-default runtime

If you want to use a runtime other than the default runtime, you must first create that additional runtime in Vertex AI.

To connect to non-default runtime, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Click the name of a notebook to open it.
  2. In the notebook, click the drop-down next to Connect and then click Connect to a runtime.
  3. Click Connect to an existing runtime.
  4. In Runtimes, select the runtime to use.
  5. Click Connect.

Connect to a new runtime

To connect to a new runtime, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Click the name of a notebook to open it.
  2. In the notebook, click the drop-down next to Connect and then click Connect to a runtime.
  3. Click Create new runtime.
  4. In Runtime Template, select the Vertex AI runtime template to use.
  5. In Runtime name, type a name for the runtime.
  6. Click Connect.

Grant access to notebooks

To grant other users access to a notebook, add those users to an appropriate IAM role.

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Find the notebook you want to grant access to.
  2. Click View actions next to the notebook and then click Manage Permissions.
  3. Click Add Principal.
  4. In the New principals field, enter a principal.
  5. In the Select a role list, select Dataform and then select one of the following roles:

  6. Click Save.

  7. To return to the notebook info, click Close.

Share notebooks

To share a notebook with other users, you can generate and share a link to the notebook. For other users to see the notebook you share, you must first grant access to the notebook.

To run a notebook, users must have access to the data that the notebook accesses. For more information, see Grant access to a dataset.

  1. In the Explorer pane, expand the Notebooks folder and, if necessary, expand the Shared notebooks folder. Find the notebook you want to share.
  2. Click View actions next to the notebook and then click Get link.
  3. Share the link with other users.

Disable notebook output saving

You can prevent sharing saved notebook output with other users who have access to the notebook file by disabling notebook output saving.

When you disable output saving for a selected notebook, BigQuery deletes all output saved in the notebook file and doesn't save the output of subsequent runs.

However, users who have access to the notebook can still view its output in the following ways:

  • Run the notebook to view its current output. This output is not saved.
  • View an archival version of the notebook and its output in revision history.

To disable saving of output for a selected notebook, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and select the notebook for which you want to disable saving output.
  2. Click Toggle header visibility > Edit > Notebook settings.
  3. In the Notebook settings window, select Omit code cell output when saving this notebook.
  4. Click Save.
  5. Click Reload.

Resolve conflicts

If you and another user make conflicting changes in a notebook, the service raises the error Automatic saving failed. This file was updated remotely or in another tab. and provides a Show diff link. To resolve the conflict, follow these steps:

  1. Click the Show diff link. The Review remote changes dialog opens.
  2. Optional: To compare the notebook source code, select the Raw source checkbox.
  3. Optional: To compare the versions inline instead of in separate panes, select the Inline diff checkbox.
  4. Review the changes and decide which to keep, revising your input if necessary.
  5. Click Save your changes.

Rename notebooks

To rename a notebook, follow these steps:

  1. In the Explorer pane, expand the Notebooks folder and if necessary the Shared notebooks folder. Find the notebook that you want to rename.
  2. Click View actions next to the notebook and then click Rename.
  3. Type a name for the notebook and then click Rename.

Troubleshooting

For more information, see Troubleshoot Colab Enterprise.

What's next