Setting Up Your Development Environment for Snowpark Python

Set up your preferred local development environment to build client applications with Snowpark Python.

If you are writing a stored procedure with Snowpark Python, consider setting up a Python worksheet instead.

Prerequisites

The supported versions of Python are:

  • 3.8

  • 3.9

  • 3.10

  • 3.11

Note

Python 3.9 depends on Snowpark client version 1.5.0. Python 3.10 depends on Snowpark client version 1.5.1. Python 3.11 depends on Snowpark client version 1.9.0.

You can create a Python virtual environment for a particular Python version 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 --override-channels -c https://repo.anaconda.com/pkgs/snowflake python=3.8 numpy pandas pyarrow
Copy

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

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

Prerequisites for Using Pandas DataFrames

The Snowpark API provides methods for writing data to and from Pandas DataFrames. Pandas is a library for data analysis. With Pandas, you use a data structure called a DataFrame to analyze and manipulate two-dimensional data.

These methods require the following libraries:

Note

If you do not have PyArrow installed, you do not need to install PyArrow yourself; installing Snowpark automatically installs the appropriate version of PyArrow.

If you have already installed any version of the PyArrow library other than the recommended version listed above, uninstall PyArrow before installing Snowpark.

Do not re-install a different version of PyArrow after installing Snowpark.

Installation Instructions

Note

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

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

conda install snowflake-snowpark-python
Copy

-or-

pip install snowflake-snowpark-python
Copy

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 pyarrow
Copy

-or-

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

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, do the following:

  1. Install Jupyter Notebooks:

    pip install notebook
    
    Copy
  2. Start a Jupyter Notebook:

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

  4. In a cell, create a session. For more information, see Creating a Session.

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.

To use features for authoring and debugging Snowpark Python stored procedures in VS Code, install the Snowflake Extension for Visual Studio Code. The extension enables you to connect to Snowflake and execute SQL statements directly in VS Code.

Important

You must manually select the Python 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
Copy