Skip to content

Commit

Permalink
Update and clarify connections, especially Snowflake (#1175)
Browse files Browse the repository at this point in the history
* Move Snowflake configuration examples

* Add Snowflake landing page

* Temporary streamlit.json

* Revert "Temporary streamlit.json"

This reverts commit ac6b641.

* Update connection docs

* Temporary streamlit.json

* Move Snowflake configuration into docstring

* Temporary streamlit.json

* Update Snowflake connection tutorial

* Remove copy pasta

* Edit Snowflake tutorial

* Edit SiS quickstart

* Review edits

* Update Snowsight screenshots

* Copy SnowflakeConnection description and examples

* Copy SQLConnection description and examples

* Remove temporary 1.40.0 docstrings

* Remove canary icon

* Edit

* Style edit

* SPSC trial limitation
  • Loading branch information
sfc-gh-dmatthews authored Nov 6, 2024
1 parent 7246208 commit 08877cc
Show file tree
Hide file tree
Showing 29 changed files with 333 additions and 264 deletions.
8 changes: 4 additions & 4 deletions content/deploy/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Get all the information you need to deploy your app and share it with your users
icon="cloud"
bold="Streamlit Community Cloud."
href="/deploy/streamlit-community-cloud"
>Deploy your app on our free platform and join a community of developers who share their apps around the world.</InlineCallout>
>Deploy your app on our free platform and join a community of developers who share their apps around the world. This is a great place for your non-commerical, personal, and educational apps.</InlineCallout>
<InlineCallout
color="lightBlue-70"
icon="ac_unit"
bold="Streamlit in Snowflake"
href="https://docs.snowflake.com/developer-guide/streamlit/about-streamlit"
>Deploy your app in Snowflake for a secure, enterprise-grade environment.</InlineCallout>
bold="Snowflake."
href="/deploy/snowflake"
>Deploy your app in Snowflake for a secure, enterprise-grade environment. This is a great place for your business apps.</InlineCallout>
<InlineCallout
color="lightBlue-70"
icon="bolt"
Expand Down
61 changes: 61 additions & 0 deletions content/deploy/snowflake/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: Streamlit in Snowflake
slug: /deploy/snowflake
---

# Deploy Streamlit apps in Snowflake

Host your apps alongside your data in a single, global platform. Snowflake provides industry-leading features that ensure the highest levels of security for your account, users, data, and apps. If you're looking for an enterprise hosting solution, try Snowflake!

<TileContainer>
<Tile
icon="rocket_launch"
title="Streamlit in Snowflake Quickstart"
text="Create a free trial account and deploy an app with Streamlit in Snowflake."
link="/get-started/installation/streamlit-in-snowflake"
background="lightBlue-70"
/>
<Tile
icon="code"
title="Examples"
text="Explore a plethora of example apps in Snowflake Labs' snowflake-demo-streamlit repository."
link="https://github.com/Snowflake-Labs/snowflake-demo-streamlit"
background="lightBlue-70"
/>
<Tile
icon="book"
title="Get started with Snowflake"
text="Learn more in Snowflake's documentation."
link="https://docs.snowflake.com/user-guide-getting-started"
background="lightBlue-70"
/>
</TileContainer>

There are three ways to host Streamlit apps in Snowflake.

<InlineCalloutContainer>
<InlineCallout
color="lightBlue-70"
icon="bolt"
bold="Streamlit in Snowflake."
href=""
>Run your Streamlit app as a native object in Snowflake. Enjoy an in-browser editor and minimal work to configure your environment. Share your app with other users in your Snowflake account through role-based access control. This is a great way to deploy apps internally for your business. Check out Snowflake docs!</InlineCallout>
<InlineCallout
color="lightBlue-70"
icon="ac_unit"
bold="Snowflake Native Apps."
href="https://docs.snowflake.com/en/developer-guide/native-apps/adding-streamlit"
>Package your app with data and share it with other Snowflake accounts. This is a great way to share apps and their underlying data with other organizations who use Snowflake so they can run it in their own account. Check out Snowflake docs!</InlineCallout>
<InlineCallout
color="lightBlue-70"
icon="web_asset"
bold="Snowpark Container Services."
href="https://docs.snowflake.com/en/developer-guide/snowpark-container-services/overview"
>Deploy your app in a container that's optimized to run in Snowflake. This is the most flexible option where you can use any library. Share your app publicly or privately. Check out Snowflake docs!</InlineCallout>
</InlineCalloutContainer>

<Note>

Using Snowpark Container Services to deploy a Streamlit app requires a compute pool, which is not available in a trial account at this time.

</Note>
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,12 @@ slug: /develop/api-reference/connections/st.connections.snowflakeconnection

<Tip>

This page only contains the `st.connections.SnowflakeConnection` class. For a deeper dive into creating and managing data connections within Streamlit apps, read [Connecting to data](/develop/concepts/connections/connecting-to-data).
This page only contains the `st.connections.SnowflakeConnection` class. For a deeper dive into creating and managing data connections within Streamlit apps, see [Connect Streamlit to Snowflake](/develop/tutorials/databases/snowflake) and [Connecting to data](/develop/concepts/connections/connecting-to-data).

</Tip>

<Autofunction function="streamlit.connections.SnowflakeConnection" />

### Configuration

{/**
Internal note: This section is deep-linked from the library in 1.28.1 via /st.connections.snowflakeconnection-configuration through a redirect.
Maintain the redirect if moved or modified.
**/}

`st.connection("snowflake")` can be configured using [Streamlit secrets](/develop/concepts/connections/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:

```toml
# .streamlit/secrets.toml

[connections.snowflake]
account = "<ACCOUNT ID>"
user = "<USERNAME>"
authenticator = "EXTERNALBROWSER"
```

Learn more about [account indentifier here](https://docs.snowflake.com/en/user-guide/admin-account-identifier). You could also specify the full configuration and credentials in your secrets file, as in the [example here](/develop/tutorials/databases/snowflake#add-connection-parameters-to-your-local-app-secrets).

#### Using existing Snowflake configuration

Snowflake's python driver also supports a [connection configuration file](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example#connecting-using-the-connections-toml-file), which is well integrated with Streamlit `SnowflakeConnection`. If you already have one or more connections configured, all you need to do is pass Streamlit the name of the connection to use. This can be done in several ways:

- Set `connection_name` in your app code, such as `st.connnection("<name>", type="snowflake")`.
- Set `connection_name = "<name>"` in the `[connections.snowflake]` section of your Streamlit secrets.
- Set the environment variable `SNOWFLAKE_DEFAULT_CONNECTION_NAME=<name>`.
- [Set a default connection](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example#setting-a-default-connection) in your Snowflake configuration.

When available in [Streamlit in Snowflake](https://docs.snowflake.com/en/developer-guide/streamlit/about-streamlit), `st.connection("snowflake")` will connect automatically using the [app owner role](https://docs.snowflake.com/en/developer-guide/streamlit/owners-rights) and does not require any configuration.

Learn more about setting up connections in the [Connecting Streamlit to Snowflake tutorial](/develop/tutorials/databases/snowflake) and [Connecting to data](/develop/concepts/connections/connecting-to-data).

<Autofunction function="streamlit.connections.SnowflakeConnection.cursor" />

<Autofunction function="streamlit.connections.SnowflakeConnection.query" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ title: st.connections.SnowparkConnection
slug: /develop/api-reference/connections/st.connections.snowparkconnection
---

<Important>

This is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click [here](/develop/quick-reference/prerelease#experimental-features).

</Important>

<Tip>

This page only contains the `st.connections.SnowparkConnection` class. For a deeper dive into creating and managing data connections within Streamlit apps, read [Connecting to data](/develop/concepts/connections/connecting-to-data).
Expand Down
52 changes: 0 additions & 52 deletions content/develop/api-reference/connections/connections-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,6 @@ This page only contains the `st.connections.SQLConnection` class. For a deeper d

<Autofunction function="streamlit.connections.SQLConnection" />

### Basic usage:

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

```python
import streamlit as st

conn = st.connection("sql")
df = conn.query("select * from pet_owners")
st.dataframe(df)
```

In case you want to pass a connection URL (or other parameters) directly, it also works:

```python
conn = st.connection(
"local_db",
type="sql",
url="mysql://user:pass@localhost:3306/mydb"
)
```

Or specify parameters in [secrets](/develop/concepts/connections/secrets-management):

```toml
# .streamlit/secrets.toml
[connections.mydb]
dialect = "mysql"
username = "myuser"
password = "password"
host = "localhost"
database = "mydb"
```

```python
# streamlit_app.py
conn = st.connection("mydb", type="sql", autocommit=True)
```

As described above, some cloud databases use extra `**kwargs` to specify credentials. These can be passed via secrets using the `create_engine_kwargs` section:

```toml
# .streamlit/secrets.toml
[connections.snowflake]
url = "snowflake://<username>@<account>/"

[connections.snowflake.create_engine_kwargs.connect_args]
authenticator = "externalbrowser"
role = "..."
# ...
```

<Autofunction function="streamlit.connections.SQLConnection.connect" />

<Autofunction function="streamlit.connections.SQLConnection.query" />
Expand Down
2 changes: 1 addition & 1 deletion content/develop/tutorials/databases/neon.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This guide explains how to securely access a [Neon database](https://neon.tech/)

## Create a Neon project

If you already have a Neon project that you want to use, feel free to [skip to the next step](#add-neon-connection-string-to-your-local-app-secrets).
If you already have a Neon project that you want to use, you can [skip to the next step](#add-neon-connection-string-to-your-local-app-secrets).

1. Log in to the Neon console and navigate to the [Projects](https://console.neon.tech/app/projects) section.
1. If you see a prompt to enter your project name, skip to the next step. Otherwise, click the "**New Project**" button to create a new project.
Expand Down
2 changes: 1 addition & 1 deletion content/develop/tutorials/databases/private-gsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This tutorial requires `streamlit>=1.28` and `st-gsheets-connection` in your Pyt

## Create a Google Sheet

If you already have a Sheet that you want to use, feel free to [skip to the next step](#enable-the-sheets-api).
If you already have a Sheet that you want to use, you can [skip to the next step](#enable-the-sheets-api).

Create a spreadsheet with this example data.

Expand Down
2 changes: 1 addition & 1 deletion content/develop/tutorials/databases/public-gsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This tutorial requires `streamlit>=1.28` and `st-gsheets-connection` in your Pyt

## Create a Google Sheet and turn on link sharing

If you already have a Sheet that you want to access, feel free to [skip to the next step](#add-the-sheets-url-to-your-local-app-secrets). See Google's documentation on how to [share spreadsheets](https://support.google.com/docs/answer/9331169?hl=en#6.1) for more information.
If you already have a Sheet that you want to access, you can [skip to the next step](#add-the-sheets-url-to-your-local-app-secrets). See Google's documentation on how to [share spreadsheets](https://support.google.com/docs/answer/9331169?hl=en#6.1) for more information.

Create a spreadsheet with this example data and create a share link. The link should have "Anyone with the link" set as a "Viewer."

Expand Down
Loading

0 comments on commit 08877cc

Please sign in to comment.