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;
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;
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 역할 활성화하기.
Sign in to Snowsight.
Select Admin » Billing & Terms.
In the Anaconda section, select Enable.
In the Anaconda Packages dialog, click the link to review the External Offerings Terms page.
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:
Sign in to Snowsight.
Select Notebooks.
Select + Notebook.
Enter a title for your notebook.
(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.
Select a database and schema in which to store your notebook.
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.
Sign in to Snowsight.
Select Notebooks.
Using the file browser, browse to and open the file that you want to import.
Enter a title for your notebook. The title defaults to the file name.
(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.
Select a database and schema in which to store your notebook.
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:
Sign in to Snowsight.
Select Notebooks.
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.
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.
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:
Sign in to Snowsight.
Select Notebooks.
Open the notebook that you want to duplicate.
Select the name of the notebook to open the options menu, and then select Duplicate.
Optionally enter a name for the duplicate notebook, and then select Duplicate.
The duplicate notebook is created.
In the confirmation dialog, select Close to return to the original notebook, or Open notebook to open the duplicate.