Set up Snowflake Notebooks¶
With Snowflake Notebooks you can write and execute code, visualize results, capture notes, and share insights with other Snowflake users. This page provides steps for setting up your account to use Snowflake Notebooks.
If you are an admin for your account, see the Administrator setup instructions for Snowflake Notebooks.
If Snowflake Notebooks access has already been set up by an admin for your account, see the User setup instructions for Snowflake Notebooks.
User setup instructions for Snowflake Notebooks¶
Before you start using Snowflake Notebooks, perform these setup steps.
Create a dedicated database and schema (optional)¶
To create a notebook, you need a database and schema to store your notebook. You can use an existing database and schema or create new ones to store and manage Snowflake Notebooks.
To simplify storing and managing Snowflake Notebooks, Snowflake recommends creating a dedicated database and schema.
To create a dedicated churn_analysis
database and schema to store your Snowflake Notebooks, run the following SQL commands:
CREATE DATABASE churn_analysis;
USE DATABASE churn_analysis;
CREATE SCHEMA notebooks_sch;
Note that the database and schema are only required for storing your notebooks. You can query any database and schema your role has access to. Use the USE DATABASE or USE SCHEMA commands in a SQL cell to change the context to a different database or schema.
Having a dedicated location for storing and managing notebooks can also prevent notebooks from being dropped when a database or schema is dropped.
Create compute resources¶
To create a notebook, you must choose a query warehouse for pushdown queries. You can select an existing warehouse or create a new one specifically for your notebooks.
To create a dedicated warehouse, notebooks_wh
, run the following SQL command:
CREATE WAREHOUSE notebooks_wh;
If you’re creating a notebook to run on a container runtime, you must select a compute pool. Compute pools are CPU-based or GPU-based virtual machines managed by Snowflake. For details, see Snowpark Container Services: Working with compute pools.
To create dedicated compute pools for your notebooks, run the following SQL commands:
CREATE COMPUTE POOL CPU_XS
MIN_NODES = 1
MAX_NODES = 15
INSTANCE_FAMILY = CPU_X64_XS;
CREATE COMPUTE POOL GPU_S
MIN_NODES = 1
MAX_NODES = 5
INSTANCE_FAMILY = GPU_NV_S;
When creating a compute pool, set the MAX_NODES parameter to greater than one since each notebook requires one full node to run.
Access control requirements¶
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. A user can also inherit access to notebooks from a role. For example, if a notebook is owned by the PUBLIC role, any user in the account can access and edit notebooks owned by that role. You cannot share the notebook with other roles.
Because each notebook is owned by a role, you might want to create a dedicated role for creating and running notebooks.
To create a notebook on the warehouse runtime, you must use a role that has the following privileges:
Privilege |
Object |
---|---|
USAGE |
Database |
USAGE or OWNERSHIP |
Schema |
USAGE |
Query warehouse |
CREATE NOTEBOOK |
Schema |
To create a notebook on a container runtime, the role must additionally have the following privileges:
Privilege |
Object |
---|---|
USAGE |
Notebook Warehouse |
USAGE |
Compute pool |
CREATE SERVICE |
Schema |
For more information about the Notebook warehouse versus the Query warehouse, see Warehouse recommendations for running Snowflake Notebooks.
Grant those privileges on the database and schema that you created to contain your notebooks to a custom role. For example,
the following SQL commands show how to grant the required privileges on a database named notebooks_db
and a schema named notebooks_sch
to a role named notebook_role
:
GRANT USAGE ON DATABASE notebooks_db TO ROLE notebook_role;
GRANT USAGE ON SCHEMA notebooks_sch TO ROLE notebook_role;
GRANT CREATE NOTEBOOK ON SCHEMA notebooks TO ROLE notebook_role;
The notebook role must also have the following privileges for notebooks on container runtime:
GRANT USAGE ON WAREHOUSE notebooks_wh TO ROLE notebook_role;
GRANT USAGE ON COMPUTE POOL CPU_XS TO ROLE notebook_role;
GRANT USAGE ON COMPUTE POOL GPU_S TO ROLE notebook_role;
GRANT CREATE SERVICE ON SCHEMA notebooks_sch TO ROLE notebook_role;
Set up external access integration (EAI)¶
For notebooks running on container runtime, if you want to install packages from internet repositories such as PyPi and Hugging Face, the ACCOUNTADMIN must set up external network access and grant your role USAGE privileges. With external access integration (EAI), you can enable secure access to specific network locations external to Snowflake and then use that access from within the handler code for user-defined functions (UDFs) and stored procedures.
For details on how to set up EAI for your notebook, see Set up external access for Snowflake Notebooks.
Template for notebook setup¶
The following SQL script summarizes all the steps above to set up your notebooks. Fill in the placeholders with your values and run the script to set up all the access and privileges you need to run notebooks.
----------------------------------
-- Location Setup --
----------------------------------
GRANT USAGE ON DATABASE <database> TO ROLE PUBLIC;
GRANT USAGE ON SCHEMA <database.schema> TO ROLE PUBLIC;
GRANT CREATE NOTEBOOK ON SCHEMA <database.schema> TO ROLE PUBLIC;
-- For Notebooks on Containers
GRANT CREATE SERVICE ON SCHEMA <database.schema> TO ROLE PUBLIC;
----------------------------------
-- Compute Resource Setup --
----------------------------------
GRANT USAGE ON WAREHOUSE <warehouse> TO ROLE PUBLIC;
-- For Notebooks on Containers
CREATE COMPUTE POOL CPU_XS
MIN_NODES = 1
MAX_NODES = 15
INSTANCE_FAMILY = CPU_X64_XS;
CREATE COMPUTE POOL GPU_S
MIN_NODES = 1
MAX_NODES = 5
INSTANCE_FAMILY = GPU_NV_S;
GRANT USAGE ON COMPUTE POOL CPU_XS TO ROLE PUBLIC;
GRANT USAGE ON COMPUTE POOL GPU_S TO ROLE PUBLIC;
-------------------------------------
-- Advanced Setup: External Access --
-------------------------------------
-- Example EAI
CREATE OR REPLACE NETWORK RULE allow_all_rule
MODE = 'EGRESS'
TYPE = 'HOST_PORT'
VALUE_LIST = ('0.0.0.0:443','0.0.0.0:80');
CREATE OR REPLACE EXTERNAL ACCESS INTEGRATION allow_all_integration
ALLOWED_NETWORK_RULES = (allow_all_rule)
ENABLED = true;
GRANT USAGE ON INTEGRATION allow_all_integration TO ROLE PUBLIC;
Warehouse recommendations for running Snowflake Notebooks¶
When you create a notebook, you select a warehouse in which to run the notebook processes and any code. Start by using an X-Small warehouse to minimize credit consumption.
Query Warehouse: Runs any SQL and Snowpark queries issued by the notebook. This warehouse is used on demand and is chosen by the notebook owner.
Notebook Warehouse: Runs the Python kernel and supports interactive use of the notebook. The default is a Snowflake-managed warehouse dedicated to Notebook workloads. Snowflake recommends using this warehouse for running your Notebook kernel. For details about this default warehouse, see Default warehouse for Notebooks.
You can also choose a different warehouse. For example, you might want to run large queries using SQL or perform compute-intensive operations using Snowpark Python that require a larger warehouse. In this case, you have two options:
Specify a warehouse to use for a specific cell or set of cells.
This ensures that the queries in those cells use the larger warehouse, but notebook processes continue to run on the smaller notebook warehouse, so you’ll use less compute when you’re not running queries.
For example, to specify a warehouse called
notebooks
to use for specific cells, you can add a SQL cell with the USE WAREHOUSE command or add the command to the Python code in a Python cell:- SQL::
USE WAREHOUSE notebooks;
- Python::
session.sql('USE WAREHOUSE notebooks;')
After you run any cell specifying
USE WAREHOUSE
, all cells that run in the remainder of the notebook session use the specified warehouse. If you no longer need queries to run with a large warehouse, write a new cell to specify a smaller warehouse to use.Choose a larger warehouse for the entire notebook.
Caution
Choosing this option can dramatically increase credit consumption for the entire notebook, since the larger warehouse is used for the entire notebook session.
To change the notebook warehouse:
Sign in to Snowsight.
Select Projects » Notebooks.
Select on the vertical ellipsis () on the top right of your notebook.
Select Notebook settings.
Select a new warehouse to use.
Administrator setup instructions for Snowflake Notebooks¶
To set up your organization using Snowflake Notebooks, perform these setup steps:
Account and deployment considerations for using Snowflake Notebooks¶
Ensure that *.snowflake.app
is on the allowlist in your network and can connect to Snowflake.
When this domain is on the allowlist, your apps can communicate with Snowflake servers without
any restrictions.
In addition, to prevent any issues connecting to the Snowflake backend, ensure that WebSockets are not blocked in your network configuration.
In addition, the following account considerations apply:
Accounts in the following regions are not currently supported:
Google Cloud Platform (GCP)
Virtual Private Snowflake (VPS)
US government regions that support FedRAMP
Using AWS PrivateLink or Azure Private Link is not supported.
Your account name must be unique within your organization.
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.
Note
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 organization. See Enabling the ORGADMIN role in an account.
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 Add user details to your user profile to update your profile using Snowsight. Otherwise, contact an administrator to update your account.
Billing considerations for running Snowflake Notebooks¶
Running a Snowflake Notebook requires a virtual warehouse.
Similar to billing for a Streamlit app, a Snowflake Notebook uses a websocket connection to run queries. The virtual warehouse remains active while the websocket connection is active. Each notebook has its own session. The connection expires when you close your notebook or when approximately 60 minutes have passed since the notebook last used the connection, whichever is sooner. To allow the notebook to run longer, you can use a different warehouse or change the STATEMENT_TIMEOUT_IN_SECONDS parameter. This parameter is set at the warehouse or account level and ends the notebook session after a set period.
See Warehouse recommendations for running Snowflake Notebooks.
Get started using notebooks by adding data¶
Before you get started using Snowflake Notebooks, add data to Snowflake.
You can add data to Snowflake in several ways:
Add data from a CSV file to a table using the web interface. See Loading data using the web interface.
Add data from external cloud storage:
To load data from Amazon S3, see Bulk loading from Amazon S3.
To load data from Google Cloud Storage, see Bulk loading from Google Cloud Storage.
To load data from Microsoft Azure, see Bulk loading from Microsoft Azure.
Add data in bulk programmatically. See Bulk loading from a local file system.
You can also add data in other ways. See Overview of data loading for complete details.