Skip to content

Connecting Snowflake Notebooks

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

If you are defining transformations using @transformation mode="snowpark", your notebook must use Python 3.8. Otherwise, your notebook can use Python 3.8 or 3.9.

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. 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.

  3. If you want to use Snowpark DataFrames in a notebook, install Snowpark in the notebook, as follows:

    pip install snowflake-snowpark-python
    

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

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`.
connection_parameters = {
    "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
    "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

tecton.version.summary()

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