Setting Up Your Development Environment for Snowpark Python

This set of topics provides instructions for setting up different types of application development environments to use Snowpark.

In this Topic:

Prerequisites

The Snowpark API requires Python 3.8.

You can create a Python 3.8 virtual environment using tools like Anaconda, Miniconda, or virtualenv.

For example, to use conda to create a Python 3.8 virtual environment, add the Snowflake conda channel, and install the numpy and pandas packages, type:

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

Creating a new conda environment locally with the Snowflake channel is recommended in order to have the best experience when using UDFs. For more information, see Local Development and Testing.

Note

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 -c https://repo.anaconda.com/pkgs/snowflake
conda activate snowpark
conda config --env --set subdir osx-64

Then, install Snowpark within this environment as described in the next section.

Installation Instructions

Note

Before running the commands in this section, make sure you are in a Python 3.8 environment. You can check this by typing the command python -V. If the version displayed is not Python 3.8, refer to the previous section.

Install the Snowpark Python package into the Python 3.8 virtual environment by using conda or pip.

conda install snowflake-snowpark-python

-or-

pip install snowflake-snowpark-python

Optionally, specify packages that you want to install in the environment such as, for example, the Pandas data analysis package:

conda install snowflake-snowpark-python pandas

-or-

pip install "snowflake-snowpark-python[pandas]"

You can view the Snowpark Python project description on the Python Package Index (PyPi) repository.

Setting Up a Jupyter Notebook for Snowpark

To get started using Snowpark with Jupyter Notebooks, here are some quick start instructions:

  1. Install Jupyter Notebooks:

    pip install notebook
    
  2. Start a Jupyter Notebook:

    jupyter notebook
    
  3. In the top-right corner of the web page that opened, select New » Python 3 Notebook.

  4. Run the following commands in a cell to create a session:

    >>> import os
    >>> from snowflake.snowpark import Session
    
    >>> connection_parameters = {
    ...    "account": os.environ["snowflake_account"],
    ...    "user": os.environ["snowflake_user"],
    ...    "password": os.environ["snowflake_password"],
    ...    "role": os.environ["snowflake_user_role"],
    ...    "warehouse": os.environ["snowflake_warehouse"],
    ...    "database": os.environ["snowflake_database"],
    ...    "schema": os.environ["snowflake_schema"]
    ...  }
    
    >>> test_session = Session.builder.configs(connection_parameters).create()
    
  5. Run the following commands in a cell to test the connection and print information about current warehouse, database, and schema.

    >>> print(test_session.sql("select current_warehouse(), current_database(), current_schema()").collect())  
    >>> test_session.close()
    

    Note

    Operations are lazy so, to trigger queries, you will need to call an action function such as the collect() Dataframe function.

Setting Up an IDE for Snowpark

You can use Snowpark with an integrated development environment (IDE).

To use Snowpark with Microsoft Visual Studio Code, install the Python extension and then specify the Python environment to use.

Important

You must manually select the Python 3.8 environment that you created when you set up your development environment. To do this, use the Python: Select Interpreter command from the Command Palette. For more information, see Using Python environments in VS Code in the Microsoft Visual Studio documentation.

Importing Modules

The main classes for the Snowpark API are in the snowflake.snowpark module.

To import particular names from a module, specify the names. For example:

>>> from snowflake.snowpark.functions import avg
Back to top