Skip to content

Python project template for Snowpark development

License

Notifications You must be signed in to change notification settings

Snowflake-Labs/snowpark-python-template

Repository files navigation

Python Project Template for Snowpark

Use this template to start writing data applications on Snowflake using Python.

Setup

Set the following environment variables with your Snowflake account information:

# Linux/MacOS
export SNOWSQL_ACCOUNT=<replace with your account identifer>
export SNOWSQL_USER=<replace with your username>
export SNOWSQL_ROLE=<replace with your role>
export SNOWSQL_PWD=<replace with your password>
export SNOWSQL_DATABASE=<replace with your database>
export SNOWSQL_SCHEMA=<replace with your schema>
export SNOWSQL_WAREHOUSE=<replace with your warehouse>
# Windows/PowerShell
$env:SNOWSQL_ACCOUNT = "<replace with your account identifer>"
$env:SNOWSQL_USER = "<replace with your username>"
$env:SNOWSQL_ROLE = "<replace with your role>"
$env:SNOWSQL_PWD = "<replace with your password>"
$env:SNOWSQL_DATABASE = "<replace with your database>"
$env:SNOWSQL_SCHEMA = "<replace with your schema>"
$env:SNOWSQL_WAREHOUSE = "<replace with your warehouse>"

Optional: You can set this env var permanently by editing your bash profile (on Linux/MacOS) or using the System Properties menu (on Windows).

Install dependencies

Create and activate a conda environment using Anaconda:

conda env create --file environment.yml
conda activate snowpark

Configure IDE

VS Code

Press Ctrl+Shift+P to open the command palette, then select Python: Select Interpreter and select the snowpark interpreter under the Conda list.

PyCharm

Go to File > Settings > Project > Python Interpreter and select the snowpark interpreter.

Prereqs

To develop your applications locally, you will need

  • A Snowflake account
  • Python 3.8 or greater
  • An IDE or code editor (VS Code, PyCharm, etc.)

Usage

Once you've set your credentials and installed the packages, you can test your connection to Snowflake by executing the stored procedure in app.py:

python src/app.py

You should see the following output:

------------------------------------------------------
|Hello world                                         |
------------------------------------------------------
|Welcome to Snowflake!                               |
|Learn more: https://www.snowflake.com/snowpark/     |
------------------------------------------------------

Run tests

You can run the test suite locally from the project root:

python -m pytest

Deploy to Snowflake

The GitHub Actions workflow file allows you to continously deploy your objects to Snowflake. When you're ready, create secrets in your GitHub repository with the same name and values as the environment variables you created earler (SNOWSQL_PWD, SNOWSQL_ACCOUNT, etc.). The workflow will create a stage, upload the Python source code, and create the stored procedure object. For more information, see resources.sql.

Docs

Contributing

Have a question or ran into a bug? Please file an issue and let us know.

Have an idea for an improvement? Fork this repository and open a PR with your idea!