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.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 (https://www.anaconda.com/), Miniconda (https://docs.conda.io/en/latest/miniconda.html), or virtualenv (https://docs.python.org/3/tutorial/venv.html).
For example, to use conda to create a Python 3.9 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.9 numpy pandas pyarrow
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.9 numpy pandas pyarrow --override-channels -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.
Prerequisites for Using Pandas DataFrames¶
The Snowpark API provides methods for writing data to and from Pandas DataFrames. Pandas (https://pandas.pydata.org/) 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:
Pandas 1.0.0 (or higher).
PyArrow library (https://arrow.apache.org/docs/python/) version 8.0.0.
Note
If you have already installed any version of the PyArrow library other than the recommended version listed above, uninstall PyArrow before installing Snowpark.
Installing Snowpark using pip automatically installs the appropriate version of PyArrow.
If you use conda to install Snowpark, you must specify pyarrow
in the list of packages.
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
-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 pyarrow
-or-
pip install "snowflake-snowpark-python[pandas]"
You can view the Snowpark Python project description on the Python Package Index (PyPi) repository (https://pypi.org/project/snowflake-snowpark-python/).
Setting Up a Jupyter Notebook for Snowpark¶
To get started using Snowpark with Jupyter Notebooks, do the following:
Install Jupyter Notebooks:
pip install notebook
Start a Jupyter Notebook:
jupyter notebook
In the top-right corner of the web page that opened, select New » Python 3 Notebook.
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 (https://code.visualstudio.com/docs/languages/python).
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 (https://code.visualstudio.com/docs/python/environments)
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