Skip to content

Commit

Permalink
Update to show SnowflakeConnection requires snowflake-snowpark-python…
Browse files Browse the repository at this point in the history
… currently (#916)
  • Loading branch information
sfc-gh-jcarroll authored Jan 3, 2024
1 parent 7198a4e commit ee95b73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions content/kb/tutorials/databases/snowflake.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ slug: /knowledge-base/tutorials/databases/snowflake

## Introduction

This guide explains how to securely access a Snowflake database from Streamlit. It uses [st.connection](/library/api-reference/connections/st.connection), the [Snowflake Python Connector](https://docs.snowflake.com/en/developer-guide/snowpark/python/index) library and Streamlit's [Secrets management](/library/advanced-features/secrets-management). The below example code **will only work on Streamlit version >= 1.28**, when `st.connection` was added.
This guide explains how to securely access a Snowflake database from Streamlit. It uses [st.connection](/library/api-reference/connections/st.connection), the [Snowpark library](https://docs.snowflake.com/en/developer-guide/snowpark/python/index) and Streamlit's [Secrets management](/library/advanced-features/secrets-management). The below example code **will only work on Streamlit version >= 1.28**, when `st.connection` was added.

## Create a Snowflake database

Expand Down Expand Up @@ -56,12 +56,12 @@ Once you have executed the queries, you should see a preview of the table in the

Make sure to note down the name of your warehouse, database, and schema. ☝️

## Install snowflake-connector-python
## Install snowflake-snowpark-python

You can find the instructions and prerequisites for installing `snowflake-connector-python` in the [Snowflake Developer Guide](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-install).
You can find the instructions and prerequisites for installing `snowflake-snowpark-python` in the [Snowflake Developer Guide](https://docs.snowflake.com/en/developer-guide/snowpark/python/setup#installation-instructions).

```bash
pip install "snowflake-connector-python"
pip install snowflake-snowpark-python
```

## Add connection parameters to your local app secrets
Expand Down Expand Up @@ -118,7 +118,7 @@ If everything worked out (and you used the example table we created above), your

### Using a Snowpark Session

The same [SnowflakeConnection](/library/api-reference/connections/st.connections.snowflakeconnection) used above also provides access to the [Snowpark Session](https://docs.snowflake.com/en/developer-guide/snowpark/reference/python/session.html) for DataFrame-style operations that run natively inside Snowflake. The [Snowpark Python library](https://docs.snowflake.com/en/developer-guide/snowpark/python/index) is a dependency for this, so be sure to `pip install snowflake-snowpark-python` first. Using this approach, you can rewrite the app above as follows:
The same [SnowflakeConnection](/library/api-reference/connections/st.connections.snowflakeconnection) used above also provides access to the [Snowpark Session](https://docs.snowflake.com/en/developer-guide/snowpark/reference/python/session.html) for DataFrame-style operations that run natively inside Snowflake. Using this approach, you can rewrite the app above as follows:

```python
# streamlit_app.py
Expand Down Expand Up @@ -147,5 +147,5 @@ If everything worked out (and you used the example table we created above), your

This tutorial assumes a local Streamlit app, however you can also connect to Snowflake from apps hosted in Community Cloud. The main additional steps are:

- [Include information about dependencies](/streamlit-community-cloud/deploy-your-app/app-dependencies) using a `requirements.txt` file with `snowflake-connector-python` and any other dependencies.
- [Include information about dependencies](/streamlit-community-cloud/deploy-your-app/app-dependencies) using a `requirements.txt` file with `snowflake-snowpark-python` and any other dependencies.
- [Add your secrets](/streamlit-community-cloud/deploy-your-app/secrets-management#deploy-an-app-and-set-up-secrets) to your Community Cloud app.
2 changes: 2 additions & 0 deletions content/library/api/connections/connections-snowflake.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Maintain the redirect if moved or modified.

`st.connection("snowflake")` can be configured using [Streamlit secrets](/library/advanced-features/secrets-management) or keyword args just like any other connection. It can also use existing Snowflake connection configuration when available.

Note that [snowflake-snowpark-python](https://pypi.org/project/snowflake-snowpark-python/) must be installed to use this connection.

#### Using Streamlit secrets

For example, if your Snowflake account supports SSO, you can set up a quick local connection for development using [browser-based SSO](https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use#how-browser-based-sso-works) and `secrets.toml` as follows:
Expand Down
2 changes: 2 additions & 0 deletions content/library/api/connections/connections-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This page only contains the `st.connections.SQLConnection` class. For a deeper d

### Basic usage:

[SQLAlchemy](https://pypi.org/project/SQLAlchemy/) and any required drivers must be installed to use this connection.

```python
import streamlit as st

Expand Down

0 comments on commit ee95b73

Please sign in to comment.