Create and manage Snowflake Notebooks

With Snowflake Notebooks you can write and execute code, visualize results, capture notes, and share insights with other Snowflake users.

This topic provides details for creating, setting up, and sharing Snowflake Notebooks.

Setup steps for using Snowflake Notebooks

Before you start using Snowflake Notebooks, perform these additional setup steps:

Create a dedicated database and schema

To simplify storing and managing Snowflake Notebooks, Snowflake recommends that you create a specific database and schema to contain them.

For example, to create a dedicated NOTEBOOKS database and schema to contain your Snowflake Notebooks, run the following SQL commands:

CREATE DATABASE notebooks;
USE DATABASE notebooks;
CREATE SCHEMA notebooks;
Copy

Privileges required to create or modify a notebook

To help you manage who can create notebooks, Snowflake provides a dedicated schema-level privilege. When you create a notebook, the role that owns the notebook is the active role in your session. Any user with the role can open, run, and edit notebooks owned by that role. You cannot share the notebook with other roles.

Because each Snowflake Notebook is owned by a role, you might want to create a dedicated role for creating and running notebooks.

To create a notebook, you must use a role that has the following privileges:

Privilege

Object

USAGE

Database

USAGE or OWNERSHIP

Schema

CREATE NOTEBOOK

Schema

Grant those privileges on the database and schema that you created to contain your notebooks to a custom role. For example, run the following SQL commands to grant the required privileges on a database named notebooks and a schema named notebooks to a role named create_notebooks:

GRANT USAGE ON DATABASE notebooks TO ROLE create_notebooks;
GRANT USAGE ON SCHEMA notebooks TO ROLE create_notebooks;
GRANT CREATE NOTEBOOK ON SCHEMA notebooks TO ROLE create_notebooks;
Copy

Accept the Anaconda Terms to import libraries

Before you start using the packages provided by Anaconda inside Snowflake, you must acknowledge the External Offerings Terms.

참고

You must be the organization administrator (use the ORGADMIN role) to accept the terms. You only need to accept the terms once for your Snowflake account. See 계정에서 ORGADMIN 역할 활성화하기.

  1. Sign in to Snowsight.

  2. Select Admin » Billing & Terms.

  3. In the Anaconda section, select Enable.

  4. In the Anaconda Packages dialog, click the link to review the External Offerings Terms page.

  5. If you agree to the terms, select Acknowledge & Continue.

If you see an error when attempting to accept the terms of service, your user profile might be missing a first name, last name, or email address. If you have an administrator role, refer to 사용자 프로필에 사용자 세부 정보 추가하기 to update your profile using Snowsight. Otherwise, contact an administrator to update your account.

Create a Snowflake Notebook

After performing the setup steps, you can start creating Snowflake Notebooks.

참고

You must use a role with the required privileges.

To create a Snowflake Notebook, follow these steps:

  1. Sign in to Snowsight.

  2. Select Notebooks.

  3. Select + Notebook.

  4. Enter a title for your notebook.

  5. (Optional) Change the selected warehouse to use to run your notebook.

    For guidance on what size warehouse to use, see Warehouse recommendations for running Snowflake Notebooks.

  6. Select a database and schema in which to store your notebook.

  7. Select Create to create and open your notebook.

For information about adding cells, see Write and run SQL and Python code in a Snowflake Notebook.

Import a notebook

You can also create a notebook in Snowflake by importing a file with the .ipynb extension.

  1. Sign in to Snowsight.

  2. Select Notebooks.

  3. Select Import .ipynb file Import .ipynb file.

  4. Using the file browser, browse to and open the file that you want to import.

  5. Enter a title for your notebook. The title defaults to the file name.

  6. (Optional) Change the selected warehouse to use to run your notebook.

    For guidance on what size warehouse to use, see Warehouse recommendations for running Snowflake Notebooks.

  7. Select a database and schema in which to store your notebook.

  8. Select Create to create and open your notebook.

참고

If your notebook imports Python packages, you must add the packages to the notebook before you can run the imported notebook. See Import packages to use in notebooks. If the package you use in your imported notebook is not available, your code might not run.

For information about adding cells, see Write and run SQL and Python code in a Snowflake Notebook.

Open an existing notebook

To open an existing notebook, follow these steps:

  1. Sign in to Snowsight.

  2. Select Notebooks.

  3. Review the list of notebooks.

    You can see all notebooks owned by your active role or owned by a role inherited by your active role.

  4. Select a notebook to open it for editing.

    For details about editing notebooks, see Write and run SQL and Python code in a Snowflake Notebook.

When you open a notebook, you can see cached results from the last time you ran any cells in the notebook. The notebook is in the Not connected state by default, but if you select that state or run any cell, your notebook connects to your virtual warehouse.

Sharing notebooks

You can collaborate on data analysis in a Snowflake Notebook with other users.

Each Snowflake Notebook is owned by a role, so other users that are granted or inherit the owner role can open, run, and edit notebooks owned by that role. You cannot share the notebook with other roles.

All edits are automatically saved every three seconds. Other users with the owner role might be concurrently editing and could overwrite your changes.

Export a notebook

You can export notebooks with the .ipynb extension to share notebooks with others.

  1. Sign in to Snowsight.

  2. Select Notebooks.

  3. Open the notebook that you want to export.

  4. Select the name of the notebook to open the options menu, and then select Export.

  5. Acknowledge that some commands might not be supported in other notebook tools, and select Export.

    A file named notebook_app is downloaded. You can then import the exported notebook into another Snowflake account or another tool that supports .ipynb files.

Collapse cells to present notebooks to others

You can collapse the code in a cell to see only the output. For example, collapse a Python cell to show only the visualizations produced by your code, or collapse a SQL cell to show only the results table.

  • To change what is visible for the cell, select Collapse cell.

Duplicate a notebook

You can duplicate any Snowflake Notebook, for example, to test out some code changes without altering the original notebook version.

When you duplicate a notebook, the copied notebook is created with the same role and warehouse as the original notebook, and is contained in the same database and schema as the notebook being duplicated. Because of this, you cannot duplicate a notebook to move it to a different database and schema, or to be owned by a different role.

To duplicate a notebook, complete the following steps:

  1. Sign in to Snowsight.

  2. Select Notebooks.

  3. Open the notebook that you want to duplicate.

  4. Select the name of the notebook to open the options menu, and then select Duplicate.

  5. Optionally enter a name for the duplicate notebook, and then select Duplicate.

    The duplicate notebook is created.

  6. In the confirmation dialog, select Close to return to the original notebook, or Open notebook to open the duplicate.