Predictive Hacks

How to Access Snowpark with OKTA via Jupyter Notebook

Currently, Snowpark API supports only Python 3.8. We can create a virtual environment with Python 3.8 using conda and installing the numpy and pandas packages by typing:

conda create --name py38_env --override-channels -c https://repo.anaconda.com/pkgs/snowflake python=3.8 numpy pandas

Then, we should activate the py38_env and install the following packages:

conda install snowflake-snowpark-python
conda install snowflake-snowpark-python pandas
pip install notebook

Note that there is a known issue with running Snowpark Python on Apple M1 chips due to memory handling in pyOpenSSL. The error message displayed is, “Cannot allocate write+execute memory for ffi.callback()”.

As a workaround, set up a virtual environment that uses x86 Python using these commands:

CONDA_SUBDIR=osx-64 conda create -n snowpark python=3.8 numpy pandas --override-channels -c https://repo.anaconda.com/pkgs/snowflake
conda activate snowpark
conda config --env --set subdir osx-64

Access Snowpark with OKTA via Jupyter Notebook

Within the “py38_env” virtual environment, we can type to start the Jupyter Notebook

jupyter notebook

Once we open the Jupyter Notebook we can type:

from snowflake.snowpark import Session

connection_parameters = {
    "user":'<your_email>@<domain>.<com>',
    "authenticator" : 'https://<company_domain>.okta.com',
    "password":'<your_password>',
    "account":'<your account>',
    "warehouse":'COMPUTE_WH',
    "database":'GPIPIS_DB',
    "schema":'PUBLIC',
    "role" : 'SYSADMIN'
 }  
    
new_session = Session.builder.configs(connection_parameters).create() 
# we get: <snowflake.snowpark.session.Session at 0x25f127ff530>

new_session.sql("SELECT count(*) FROM test_table").collect()
#we get [Row(COUNT(*)=229)]

#close the session
new_session.close() 
 

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s