Skip to main content
Version: Beta 🚧

Connect Notebooks to Snowflake

You can use any Python-supported notebook software to explore feature values and create training datasets with Tecton on Snowflake. Jupyter is recommended.

Configuration Steps​

Configure your notebook to use a supported Python version​

Your notebook can use Python >=3.8, <3.12.

If you are using Jupyter, you can use a notebook with a specific Python version by following these steps:

  1. Install the ipykernel package in the root directory of your Python installing using the command:

    sudo <root directory of the version to install>/pip install ipykernel

  2. Make sure you have run tecton login (see previous section).

  3. Run jupyter notebook to start the notebook server and open the UI in your browser. Then goto Kernel | Change Kernel and select the Python version.

For an example of using a Snowpark DataFrame in a notebook, see Constructing Training Data Using a Notebook.

Install Tecton​

In your notebook, install Tecton by running

pip install tecton[snowflake]

If using Python version 3.9, you must have snowflake-snowpark-python>=1.5 installed.

Authenticate your Tecton user​

To authenticate as a user, run the following in your notebook, replacing "https://example.tecton.ai" with the URL of your Tecton instance:


tecton.login("https://example.tecton.ai")

Then follow the directions to open the login link in your browser, sign in to the Tecton instance as your user, and copy and paste the authorization code from the Identity Verified web page back into your notebook's input box. Please be aware the authorization code is one-time use only.

note

If the notebook is launched from an environment where you are authenticated with the Tecton CLI (e.g. your local machine), those credentials will be loaded into the notebook session. If you run into any trouble logging in within the notebook, try quitting the notebook, running tecton logout locally, relaunching the notebook, and then running tecton.login() again.

Connect to Snowflake​

Run the following commands in your notebook to connect to Snowflake.

# Import Tecton and other libraries
import logging
import os
import tecton
import pandas as pd
import snowflake.connector
from datetime import datetime, timedelta
from pprint import pprint

# The following two lines log only warnings to the console. To log all events to the console, remove the two lines.
logging.getLogger('snowflake.connector').setLevel(logging.WARNING)
logging.getLogger('snowflake.snowpark').setLevel(logging.WARNING)

# connection_parameters assumes the Snowflake connection credentials are stored in the environment
# variables `SNOWFLAKE_USER`,`SNOWFLAKE_PASSWORD` and `SNOWFLAKE_ACCOUNT`.
# Uncomment the "authenticator" parameter below, only if authenticating through a browser.
# If the "authenticator" parameter is included, do not include the password parameter below.
connection_parameters = {
# "authenticator": "externalbrowser",
"user": os.environ['SNOWFLAKE_USER'], # Your username in the Snowflake account that you're using with Tecton
"password": os.environ['SNOWFLAKE_PASSWORD'], # Your password in the Snowflake account that you're using with Tecton. Not needed if using the authenticator parameter above.
"account": os.environ['SNOWFLAKE_ACCOUNT'], # The Snowflake account you're using with Tecton (takes the form \<SNOWFLAKE_ACCOUNT\>.snowflakecomputing.com
"warehouse": "TRIAL_WAREHOUSE",
# Database and schema are required to create various temporary objects by tecton
"database": "TECTON",
"schema": "PUBLIC"
}
conn = snowflake.connector.connect(**connection_parameters)
tecton.snowflake_context.set_connection(conn) # Tecton will use this Snowflake connection for all interactive queries

# Quick helper function to query snowflake from a notebook
# Make sure to replace with the appropriate connection details for your own account
def query_snowflake(query):
df = conn.cursor().execute(query).fetch_pandas_all()
return df

# Set the compute mode to snowflake
tecton.conf.set("TECTON_COMPUTE_MODE", "snowflake")

tecton.version.summary()

If the commands above are successful, tecton.version.summary() will return the version number and other information.

Was this page helpful?

🧠 Hi! Ask me anything about Tecton!

Floating button icon