Use this template to start writing data applications on Snowflake using Python.
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).
Create and activate a conda environment using Anaconda:
conda env create --file environment.yml
conda activate snowpark
Press Ctrl
+Shift
+P
to open the command palette, then select Python: Select Interpreter and select the snowpark interpreter under the Conda list.
Go to File > Settings > Project > Python Interpreter and select the snowpark interpreter.
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.)
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/ |
------------------------------------------------------
You can run the test suite locally from the project root:
python -m pytest
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
.
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!