diff --git a/content/deploy/_index.md b/content/deploy/_index.md index 275ab8cf9..3ab4f81be 100644 --- a/content/deploy/_index.md +++ b/content/deploy/_index.md @@ -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. + >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. Deploy your app in Snowflake for a secure, enterprise-grade environment. + 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. + + + + + +There are three ways to host Streamlit apps in Snowflake. + + + 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! + 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! + 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! + + + + + Using Snowpark Container Services to deploy a Streamlit app requires a compute pool, which is not available in a trial account at this time. + + diff --git a/content/develop/api-reference/connections/connections-snowflake.md b/content/develop/api-reference/connections/connections-snowflake.md index 5e64e52bf..addc1c8ba 100644 --- a/content/develop/api-reference/connections/connections-snowflake.md +++ b/content/develop/api-reference/connections/connections-snowflake.md @@ -5,51 +5,12 @@ slug: /develop/api-reference/connections/st.connections.snowflakeconnection -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). -### 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 = "" -user = "" -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("", type="snowflake")`. -- Set `connection_name = ""` in the `[connections.snowflake]` section of your Streamlit secrets. -- Set the environment variable `SNOWFLAKE_DEFAULT_CONNECTION_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). - diff --git a/content/develop/api-reference/connections/connections-snowpark.md b/content/develop/api-reference/connections/connections-snowpark.md index bdab770fd..dbe969a7d 100644 --- a/content/develop/api-reference/connections/connections-snowpark.md +++ b/content/develop/api-reference/connections/connections-snowpark.md @@ -3,12 +3,6 @@ title: st.connections.SnowparkConnection slug: /develop/api-reference/connections/st.connections.snowparkconnection --- - - -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). - - - 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). diff --git a/content/develop/api-reference/connections/connections-sql.md b/content/develop/api-reference/connections/connections-sql.md index 451a6ea7a..72642481c 100644 --- a/content/develop/api-reference/connections/connections-sql.md +++ b/content/develop/api-reference/connections/connections-sql.md @@ -11,58 +11,6 @@ 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 - -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://@/" - -[connections.snowflake.create_engine_kwargs.connect_args] -authenticator = "externalbrowser" -role = "..." -# ... -``` - diff --git a/content/develop/tutorials/databases/neon.md b/content/develop/tutorials/databases/neon.md index bcf495f06..07ae35ef4 100644 --- a/content/develop/tutorials/databases/neon.md +++ b/content/develop/tutorials/databases/neon.md @@ -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. diff --git a/content/develop/tutorials/databases/private-gsheet.md b/content/develop/tutorials/databases/private-gsheet.md index e3634e02e..06a0348fc 100644 --- a/content/develop/tutorials/databases/private-gsheet.md +++ b/content/develop/tutorials/databases/private-gsheet.md @@ -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. diff --git a/content/develop/tutorials/databases/public-gsheet.md b/content/develop/tutorials/databases/public-gsheet.md index 554091b20..8db330662 100644 --- a/content/develop/tutorials/databases/public-gsheet.md +++ b/content/develop/tutorials/databases/public-gsheet.md @@ -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." diff --git a/content/develop/tutorials/databases/snowflake.md b/content/develop/tutorials/databases/snowflake.md index 379180206..df0f1e766 100644 --- a/content/develop/tutorials/databases/snowflake.md +++ b/content/develop/tutorials/databases/snowflake.md @@ -7,134 +7,202 @@ slug: /develop/tutorials/databases/snowflake ## Introduction -This guide explains how to securely access a Snowflake database from Streamlit. It uses [st.connection](/develop/api-reference/connections/st.connection), the [Snowpark library](https://docs.snowflake.com/en/developer-guide/snowpark/python/index) and Streamlit's [Secrets management](/develop/concepts/connections/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](/develop/api-reference/connections/st.connection), the [Snowpark library](https://docs.snowflake.com/en/developer-guide/snowpark/python/index) and Streamlit's [Secrets management](/develop/concepts/connections/secrets-management). + +### Prerequisites + +- The following packages must be installed in your Python environment: + + ```txt + streamlit>=1.28 + snowflake-snowpark-python>=0.9.0 + snowflake-connector-python>=2.8.0 + ``` + + + Use the correct version of Python required by `snowflake-snowpark-python`. For example, if you use `snowflake-snowpark-python==1.23.0` you must use Python version \>=3.8, \<3.12. + + +- You must have a Snowflake account. To create a trial account, see the [tutorial](/get-started/installation/streamlit-in-snowflake) in _Get started_. +- You should have a basic understanding of [`st.connection`](/develop/api-reference/connections/st.connection) and [Secrets management](/develop/concepts/connections/secrets-management). ## Create a Snowflake database - +If you already have a database that you want to use, you can [skip to the next step](#add-connection-parameters-to-your-local-app-secrets). -If you already have a database that you want to use, feel free to [skip to the next step](#add-username-and-password-to-your-local-app-secrets). +1. Sign in to your Snowflake account at [https://app.snowflake.com](https://app.snowflake.com). +1. In the left navigation, click "**Projects**," then click "**Worksheets**." +1. To create a new worksheet, in the upper-right corner, click the plus icon (add). - + You can use a worksheet to quickly and conveniently execute SQL statements. This is a great way to learn about and experiment with SQL in a trial account. -First, [sign up for Snowflake](https://signup.snowflake.com/) and log into the [Snowflake web interface](https://docs.snowflake.com/en/user-guide/connecting.html#logging-in-using-the-web-interface) (note down your username, password, and [account identifier](https://docs.snowflake.com/en/user-guide/admin-account-identifier.html)!): +1. Optional: To rename your worksheet, in the upper-left corner, hover over the tab with your worksheet name, and click the overflow menu icon (more_vert). Select "**Rename**", enter a new worksheet name (e.g. "Scratchwork"), and press "**Enter**". +1. To create a new database with a table, in your worksheet's SQL editor, type the following SQL statements, and execute them. -![](/images/databases/snowflake-1.png) + ```sql + CREATE DATABASE PETS; -Enter the following queries into the SQL editor in the Worksheets page to create a database and a table with some example values: + CREATE TABLE MYTABLE (NAME varchar(80), PET varchar(80)); -```sql -CREATE DATABASE PETS; + INSERT INTO MYTABLE + VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird'); -CREATE TABLE MYTABLE ( - NAME varchar(80), - PET varchar(80) -); + SELECT * FROM MYTABLE; + ``` -INSERT INTO MYTABLE VALUES ('Mary', 'dog'), ('John', 'cat'), ('Robert', 'bird'); + To execute the statements in a worksheet, select all the lines you want to execute by highlighting them with your mouse. Then, in the upper-right corner, click the play button (play_arrow). Alternatively, if you want to execute everything in a worksheet, click the down arrow (expand_more) next to the play button, and select "**Run All**". -SELECT * FROM MYTABLE; -``` + AWS screenshot 1 -Before you execute the queries, first determine which Snowflake UI / web interface you're using. The examples below use [Snowsight](https://docs.snowflake.com/en/user-guide/ui-snowsight). You can also use [Classic Console Worksheets](https://docs.snowflake.com/en/user-guide/ui-worksheet) or any other means of running Snowflake SQL statements. + -### Execute queries in a Worksheet + If no lines are highlighted and you click the play button, only the line with your cursor will execute. -To execute the queries in a Worksheet, highlight or select all the queries with your mouse, and click the play button in the top right corner. + -AWS screenshot 1 +1. Optional: To view your new database, above the left navigation, select "**Databases**." Click the down arrows (expand_more) to expand "PETS" → "PUBLIC" → "Tables" → "MYTABLE." - + AWS screenshot 2 -Be sure to highlight or select **all** the queries (lines 1-10) before clicking the play button. +1. For your use in later steps, note down your role, warehouse, database, and schema. In the preceding screenshot, these are the following: - + ```toml + role = "ACCOUNTADMIN" + warehouse = "COMPUTE_WH" + database = "PETS" + schema = "PUBLIC" + ``` -Once you have executed the queries, you should see a preview of the table in the **Results** panel at the bottom of the page. Additionally, you should see your newly created database and schema by expanding the accordion on the left side of the page. Lastly, the warehouse name is displayed on the button to the left of the **Share** button. + Because the SQL statements did not specify a schema, they defaulted to the "PUBLIC" schema within the new "PETS" database. The role and warehouse are trial-account defaults. You can see the role and warehouse used by your worksheet in the upper-right corner, to the left of the "**Share**" and play (play_arrow) buttons. -AWS screenshot 2 + In Snowflake, databases provide storage and warehouses provide compute. When you configure your connection, you aren't explicitly required to declare role, warehouse, database, and schema; if these are not specified, the connection will use your account defaults. You can also change these settings within an active connection if you need to use multiple roles, warehouses, or databases. However, declaring these defaults avoids unintentional selections. -Make sure to note down the name of your warehouse, database, and schema. ☝️ +1. To conveniently copy your account identifier, in the lower-left corner, click your profile image, and hover over your account. A popover dialog expands to the right with your organization and account. In the popover, hover over your account, and click the copy icon (content_copy). -## Install snowflake-snowpark-python + The account identifier in your clipboard is period-separated, which is the format used for SQL statements. Paste your account identifier into your notes, and change the period into a hyphen. The Snowflake Connector for Python requires the hyphen-separated format for your account identifier. -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). + ```toml + account = "xxxxxxx-xxxxxxx" + ``` -```bash -pip install snowflake-snowpark-python -``` + For more information, see [Account identifiers](https://docs.snowflake.com/en/user-guide/admin-account-identifier.html) in the Snowflake docs. ## Add connection parameters to your local app secrets -Your local Streamlit app will read secrets from a file `.streamlit/secrets.toml` in your app’s root directory. Learn more about [Streamlit secrets management here](/develop/concepts/connections/secrets-management). Create this file if it doesn’t exist yet and add your Snowflake username, password, [account identifier](https://docs.snowflake.com/en/user-guide/admin-account-identifier.html), and the name of your warehouse, database, and schema as shown below: +There are three places Streamlit looks for your connection parameters: keyword arguments in `st.connection`, `.streamlit/secrets.toml`, and `.snowflake/configuration.toml`. For more information, especially if you want to manage multiple connections, see the examples in the API reference for [`SnowflakeConnnection`](/develop/api-reference/connections/st.connections.snowflakeconnection). -```toml -# .streamlit/secrets.toml +To configure your connection, you must specify the following: -[connections.snowflake] -account = "xxx" -user = "xxx" -password = "xxx" -role = "xxx" -warehouse = "xxx" -database = "xxx" -schema = "xxx" -client_session_keep_alive = true -``` + - Your account identifier (`account`) + - Your username (`user`) + - Some form of authentication parameter (like `password` or `private_key_file`) + +If you don't have MFA on your account, you can just specify your `password`. Alternatively, you can set up [key-pair authentication](https://docs.snowflake.com/en/user-guide/key-pair-auth) on your account and point to your `private_key_file`. If you are just looking for a quick, local connection, you can set `authenticator` to prompt you for credentials in an external browser. + +In addition to the three required parameters to authenticate your connection, it is common to specify the default `role`, `warehouse`, `database`, and `schema` for convenience. For more information about required and optional parameters, see the [Snowflake Connector for Python](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api#functions) documentation. + +### Option 1: Use `.streamlit/secrets.toml` + +1. If you don't already have a `.streamlit/secrets.toml` file in your app's working directory, create an empty secrets file. + + To learn more, see [Secrets Management](/develop/concepts/connections/secrets-management). + + + + Add this file to `.gitignore` and don't commit it to your GitHub repo! If you want to use this connection in multiple repositories, you can create a global `secrets.toml` file instead. For more information, see [`secrets.toml` file location](/develop/api-reference/connections/secrets.toml#file-location). + + + +1. Add your connection parameters to `.streamlit/secrets.toml`: - + ```toml + [connections.snowflake] + account = "xxxxxxx-xxxxxxx" + user = "xxx" + private_key_file = "../xxx/xxx.p8" + role = "xxx" + warehouse = "xxx" + database = "xxx" + schema = "xxx" + ``` -Make sure your account name is in the format `-`. This is the general-purpose identifier format and not the `.`-separated format used for SQL commands. + - + Your account identifier must be hyphen-separated: `-`. This is the general-purpose identifier format and not the period-separated format used within SQL statements. -If you created the database from the previous step, the names of your database and schema are `PETS` and `PUBLIC`, respectively. Streamlit will also use **Snowflake config and credentials** from a [SnowSQL config file](https://docs.snowflake.com/en/user-guide/snowsql-config#snowsql-config-file) if available. + - + In the example above, the connection uses key-pair authentication. Therefore, `private_key_file` is defined instead of `password`. `private_key_file` can be an absolute or relative path. If you use a relative path, it should be relative to your app's working directory (where you execute `streamlit run`). -Add this file to `.gitignore` and don't commit it to your GitHub repo! +### Option 2: Use `.snowflake/connections.toml` - +If you already have your connection configured using [Snowflake's connections file](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-connect#connecting-using-the-connections-toml-file), you can use it as-is. If you are using a default connection, no change is needed in later steps of this tutorial. If you are using a named connection, you will need to include the name in `st.connection`. This is noted in a later step. For information about using named connections, see the examples in the API reference for [`SnowflakeConnnection`](/develop/api-reference/connections/st.connections.snowflakeconnection). + +1. If you don't already have a `.snowflake/configuration.toml` file in your user directory, create an empty connections file. +1. Add your connection parameters to `.snowflake/connection.toml`: + + ```toml + [default] + account = "xxxxxxx-xxxxxxx" + user = "xxx" + private_key_file = "../xxx/xxx.p8" + role = "xxx" + warehouse = "xxx" + database = "xxx" + schema = "xxx" + ``` + + This example uses key-pair authentication as described in the previous option. ## Write your Streamlit app -Copy the code below to your Streamlit app and run it. Make sure to adapt the query to use the name of your table. +1. Copy the code below to your Streamlit app and save it. If you are not using the example database and table from the first section of this tutorial, replace the SQL query and results handling as desired. -```python -# streamlit_app.py + ```python + # streamlit_app.py -import streamlit as st + import streamlit as st -# Initialize connection. -conn = st.connection("snowflake") + conn = st.connection("snowflake") + df = conn.query("SELECT * FROM mytable;", ttl="10m") -# Perform query. -df = conn.query("SELECT * from mytable;", ttl=600) + for row in df.itertuples(): + st.write(f"{row.NAME} has a :{row.PET}:") + ``` -# Print results. -for row in df.itertuples(): - st.write(f"{row.NAME} has a :{row.PET}:") -``` + The `st.connection` command creates a `SnowflakeConnection` object and handles secrets retrieval. The `.query()` method handles query caching and retries. By default, query results are cached without expiring. Setting `ttl="10m"` ensures the query result is cached for no longer than 10 minutes. To disable caching, you can set `ttl=0` instead. Learn more in [Caching](/develop/concepts/architecture/caching). + + + + If you configured your connection using a named connection in `.snowflake/connections.toml` instead of `[default]` (Option 2 above), you must include your connection name in `st.connection`. If you have `[my_connection]` in your connections file, replace the line with `st.connection` as follows: -See `st.connection` above? This handles secrets retrieval, setup, query caching and retries. By default, `query()` results are cached without expiring. In this case, we set `ttl=600` to ensure the query result is cached for no longer than 10 minutes. You can also set `ttl=0` to disable caching. Learn more in [Caching](/develop/concepts/architecture/caching). + ```python + conn = st.connection("my_connection", type="snowflake") + ``` -If everything worked out (and you used the example table we created above), your app should look like this: + -![Finished app screenshot](/images/databases/streamlit-app.png) +1. In your working directory, open a terminal, and run your Streamlit app. -### Using a Snowpark Session + ```bash + streamlit run streamlit_app.py + ``` -The same [SnowflakeConnection](/develop/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: + If everything worked out (and you used the example table from the first section), your app should look like this: + + ![Finished app screenshot](/images/databases/streamlit-app.png) + +### Use a Snowpark Session + +The [SnowflakeConnection](/develop/api-reference/connections/st.connections.snowflakeconnection) used above also provides access to [Snowpark sessions](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 import streamlit as st -# Initialize connection. conn = st.connection("snowflake") -# Load the table as a dataframe using the Snowpark Session. @st.cache_data def load_table(): session = conn.session() @@ -142,16 +210,17 @@ def load_table(): df = load_table() -# Print results. for row in df.itertuples(): st.write(f"{row.NAME} has a :{row.PET}:") ``` -If everything worked out (and you used the example table we created above), your app should look the same as the screenshot from the first example above. +Because this example uses `.session()` instead of `.query()`, caching is added manually for better performance and efficiency. + +If everything worked out (and you used the example table from the first section), your app should look the same as the preceding screenshot. ## Connecting to Snowflake from Community Cloud 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](/deploy/streamlit-community-cloud/deploy-your-app/app-dependencies) using a `requirements.txt` file with `snowflake-snowpark-python` and any other dependencies. -- [Add your secrets](/deploy/streamlit-community-cloud/deploy-your-app/secrets-management) to your Community Cloud app. +- [Add your secrets](/deploy/streamlit-community-cloud/deploy-your-app/secrets-management) to your Community Cloud app. You must use the `.streamlit/secrets.toml` format described in [Option 1](/develop/tutorials/databases/snowflake#option-1-use-streamlitsecretstoml) above. diff --git a/content/get-started/installation/sis.md b/content/get-started/installation/sis.md index 0dc5afbc3..95e38bf7a 100644 --- a/content/get-started/installation/sis.md +++ b/content/get-started/installation/sis.md @@ -5,7 +5,7 @@ slug: /get-started/installation/streamlit-in-snowflake # Use Streamlit in Snowflake to code in a secure environment -Snowflake is a single, global platform that powers the Data Cloud. If you want to use a secure platform with role-based access control, this is the option for you! This page walks you through creating a trial Snowflake account and building a simple "Hello world" app. Your trial account comes with an account credit so you can try out the service without entering any payment information. +Snowflake is a single, global platform that powers the Data Cloud. If you want to use a secure platform with role-based access control, this is the option for you! This page walks you through creating a trial Snowflake account and building a "Hello world" app. Your trial account comes with an account credit so you can try out the service without entering any payment information. @@ -21,114 +21,138 @@ All you need is an email address! Everything else happens in your 30-day trial a 1. Go to signup.snowflake.com. (This link will open in a new tab.) -2. Fill in your information and click "**CONTINUE**." +1. Fill in your information, and click "**CONTINUE**." -3. Select "**Standard**" for your Snowflake edition and "**Amazon Web Services**" for your cloud provider. +1. Select "**Standard**" for your Snowflake edition and "**Amazon Web Services**" for your cloud provider. -4. Choose the region nearest you, accept the terms, and click "**GET STARTED**." +1. Choose the region nearest you, accept the terms, and click "**GET STARTED**."
Choose your Snowflake edition, provider, and region
-5. Answer or skip a few questions to let us know more about yourself. +1. Answer or skip a few questions to let us know more about yourself. -6. A message will display to confirm "You're now signed up!" Go to your email and click on the activation link. (Within your link, note the subdomain. This is your Snowflake account identifier. `https://.snowflakecomputing.com`) +1. A message will display: "You're now signed up!" Go to your email, and click on the activation link. (Within your link, note the subdomain. This is your Snowflake account identifier. `https://.snowflakecomputing.com`) -7. Set your username and password. This will be an admin user account within your Snowflake account. Your Snowflake account can have multiple users within it. +1. Set your username and password. This will be an admin user account within your Snowflake account. Your Snowflake account can have multiple users within it. -8. If you are not signed in after setting your password, follow the instructions to enter your Snowflake account identifier before entering your username and password. If you've accidentally closed your browser, you can log in at [app.snowflake.com](https://app.snowflake.com/). +1. If you are not signed in after setting your password, follow the instructions to enter your Snowflake account identifier, then enter your username and password. If you've accidentally closed your browser, you can log in at [app.snowflake.com](https://app.snowflake.com/). -9. Congratulations! You have a trial Snowflake account. The first thing you will see are some sample databases. (This interface is called Snowsight. Check out the Snowflake docs for a [quick tour](https://docs.snowflake.com/en/user-guide/ui-snowsight-quick-tour).) +Congratulations! You have a trial Snowflake account. - ![Sample databases in your new trial Snowflake account](/images/get-started/SiS-1-landing-page.png) +The displayed interface is called Snowsight. Snowsight provides a web-based, graphical user interface for your Snowflake account. The default page is "**Home**," which provides popular quick actions to get started. You can access your "**Projects**" in the left navigation or at the bottom of your "**Home**" page. "**Projects**" include worksheets, notebooks, Streamlit apps, and dashboards. Check out the Snowflake docs for a [quick tour](https://docs.snowflake.com/en/user-guide/ui-snowsight-quick-tour).) -## Accept the use of Anaconda on your Snowflake account +![Sample databases in your new trial Snowflake account](/images/get-started/SiS-1-landing-page.png) -10. In the left navigation, go to "**Admin**" then "**Billing & Terms**." +## Optional: Create a warehouse -11. In the "**Anaconda**" section, click "**Enable**." +Warehouses provide compute resources for tasks and apps in your Snowflake account. Your trial account already has an XS warehouse which you can use. This is named "COMPUTE_WH." However, if you want to use more compute resources, you can create another warehouse. -12. Accept the terms. The "**Anaconda**" section will now show "**Acknowledged**." +1. In the lower-left corner under your name, confirm that your current role is "ACCOUNTADMIN." If it isn't, click your name, hover over "**Switch Role**," and select "**ACCOUNTADMIN**." -## Create a warehouse and database to hold your Streamlit apps +1. In the left navigation, select "**Admin**" → "**Warehouses**." -13. Click on your name in the left navigation. Hover over "**Switch Role**" and select "**ACCOUNTADMIN**" to use your account in the context of an admin. +1. In the upper-right corner, click the blue "add **Warehouse**" button. -14. In the left navigation under "**Admin**," click on "**Warehouses**." +1. Enter "STREAMLIT_WH" for the name and select a type and size. The default type and size are "Standard" and "X-Small," respectively. Click "**Create Warehouse**." -15. In the upper-right corner, click the blue "add **Warehouse**" button. +## Create a database -16. Enter "STREAMLITWAREHOUSE" for the name and keep the defaults of "Standard" type and "X-Small" size. Click "**Create Warehouse**." +Databases provide storage for data and apps in your Snowflake account. Your trial account comes with a shared database of sample data, but you must create a new database in your account to store your app files. -17. In the left navigation, go to "**Data**" then "**Databases**." (This is back where you started!) +1. In the left navigation, select "**Data**" → "**Databases**." -18. In the upper-right corner, click the blue "add **Database**" button. +1. In the upper-right corner, click the blue "add **Database**" button. -19. Enter "STREAMLITAPPSDB" for the name. Click "**Create**." +1. Enter "STREAMLIT_DB" for the name, and click "**Create**." -20. Yay! You now have a new database to hold all your Streamlit apps. +Yay! You now have a new database to hold all your Streamlit apps. - ![New database in your new trial Snowflake account](/images/get-started/SiS-2-databases.png) +![New database in your new trial Snowflake account](/images/get-started/SiS-2-databases.png) + +The databases in the above screenshot are as follows: + +- "SNOWFLAKE:" A built-in database that stores meta data for your account. +- "SNOWFLAKE_SAMPLE_DATA:" A shared database with sample data. +- "STREAMLIT_DB:" Your new database where you'll put your Streamlit files. ## Create a "Hello World" Streamlit app -21. In the left navigation, click on "**Streamlit**." +1. In the left navigation, select "**Projects**" → "**Streamlit**." + +1. In the upper-right corner, click the blue "add **Streamlit App**" button. + +1. Enter your app details as follows: + + - App title: "Hello World" + - App location: "STREAMLIT_DB" and "PUBLIC" + - App warehouse: "COMPUTE_WH" (default) or "STREAMLIT_WH" (if you created a new warehouse) + + If you can't select your database, refresh the page to ensure the interface is displaying current information. + +1. Click "**Create**." (Note that the app will run with the rights of "ACCOUNTADMIN" for simplicity. You can curate your roles and permissions to choose who can create and access apps.) + + ![Create your first Streamlit in Snowflake app](/images/get-started/SiS-3-create-app.png) + + Your new app is prefilled with example code and opens in editing mode. The left panel shows your code. The right panel shows the resulting app. + +1. Optional: Explore the example app. -22. In the upper-right corner, click the blue "add **Streamlit App**" button. +1. In the left code editor, delete everything, and replace it with the following: -23. Enter "Hello World" for the name of your app. Your new warehouse and database should already be filled in, along with the "PUBLIC" schema for your database. Click "**Create**." (Note that the app will run with the rights of "ACCOUNTADMIN" for simplicity. You can curate your roles and permissions to choose who can create and access apps.) + ```python + import streamlit as st - ![Create your first Streamlit in Snowflake app](/images/get-started/SiS-3-create-app.png) + st.write("Hello World") + ``` -24. Your new app, prefilled with example code, will open in editing mode. The left panel shows your code. The right panel shows the resulting app. + If you want to get back to the sample code later, you can always make another app to edit the same example again. -25. You can explore the example if you want, but we'll proceed here with a simpler example. (Don't worry! You can always make another app to get the same example again.) Delete the code on the left and replace it with: +1. In the upper-right corner, click the blue "play_arrow **Run**" button to make the running app reflect your changes. - ```python - import streamlit as st + Hooray! You just wrote a Streamlit app. - st.write("Hello World") - ``` + ![Hello World in Streamlit in Snowflake app](/images/get-started/SiS-4-hello-world.png) -26. In the upper-right corner, click the blue "play_arrow **Run**" button to make the running app reflect your changes. + -27. Hooray! You just wrote a Streamlit app. + In the lower-left corner of the editing interface, you can click the splitscreen icons to toggle the visibility of your file navigation, code editor, and app preview. -![Hello World in Streamlit in Snowflake app](/images/get-started/SiS-4-hello-world-1.png) + -28. Change `st.write` to `st.title`: +1. Change `st.write` to `st.title`: - ```python - import streamlit as st + ```python + import streamlit as st - st.title("Hello World") - ``` + st.title("Hello World") + ``` -29. In the upper-right corner, click the blue "play_arrow **Run**" button to make the running app reflect your changes. +1. In the upper-right corner, click the blue "play_arrow **Run**" button to make the running app reflect your changes. -30. You've just edited your app. It's that easy. + Your app now displays the larger title text. - ![Hello World in Streamlit in Snowflake app](/images/get-started/SiS-5-hello-world-2.png) +1. Optional: Make more edits to your app. You must interact with your app or click the blue "play_arrow **Run**" button to display the changes. This is different from a local environment where you can save your changes to trigger a rerun. -31. When you're done, click "chevron_left **Streamlit Apps**" in the upper-left corner to go back to Snowsight. +1. To go back to Snowsight, in the upper-left corner, click "chevron_left **Streamlit Apps**." -## Returning to your app +## Return to your app -32. When you are ready to return to your app, go to your Snowsight interface. (If you are returning to the site, you can log in at [app.snowflake.com](https://app.snowflake.com/).) +When you want to view or edit your app again, you can return to it through Snowsight. If you are returning to the site, you can log in at [app.snowflake.com](https://app.snowflake.com/). -33. In the left navigation, go to "**Streamlit**." +1. In the left navigation, select "**Projects**" → "**Streamlit**." -34. Click on "**Hello World**." (If you don't see your app, check that you have your role set to "ACCOUNTADMIN" as above.) +1. In your list of apps, click "**Hello World**." - ![Return to your Streamlit in Snowflake app](/images/get-started/SiS-6-hello-world-return.png) + If you don't see your app, check that you have your role set to "ACCOUNTADMIN" as described in [Optional: Create a warehouse](/get-started/installation/streamlit-in-snowflake#optional-create-a-warehouse). -35. Your app will open in viewing mode. Just click "**Edit**" in the upper-right corner to modify your app again. +1. Your app will open in viewing mode. To edit your app, in the upper-right corner, click "**Edit**." - ![Change to editing mode in Streamlit in Snowflake](/images/get-started/SiS-7-hello-world-edit.png) + ![Change to editing mode in Streamlit in Snowflake](/images/get-started/SiS-5-hello-world-edit.png) ## What's next? -Read about our [Basic concepts](/get-started/fundamentals/main-concepts) and try out more commands in your app. To create more apps in your account, you can proceed from [Create a "Hello World" Streamlit app](#create-a-hello-world-streamlit-app). The warehouse and database setup do not need to be repeated. +Read about our [Basic concepts](/get-started/fundamentals/main-concepts) and try out more commands in your app. Or, create more apps in Snowflake! You can reuse your warehouse and database, so you don't need to repeat those steps. For more information about creating and managing Streamlit in Snowflake apps, check out the [Snowflake docs](https://docs.snowflake.com/en/developer-guide/streamlit/about-streamlit). diff --git a/content/menu.md b/content/menu.md index 595b5d564..50cb16e3d 100644 --- a/content/menu.md +++ b/content/menu.md @@ -790,8 +790,8 @@ site_menu: url: /deploy/streamlit-community-cloud/manage-your-account/delete-your-account - category: Deploy / Streamlit Community Cloud / Status and limitations url: /deploy/streamlit-community-cloud/status - - category: Deploy / Streamlit in Snowflake - url: https://docs.snowflake.com/developer-guide/streamlit/about-streamlit + - category: Deploy / Snowflake + url: /deploy/snowflake - category: Deploy / Other platforms url: /deploy/tutorials - category: Deploy / Other platforms / Docker diff --git a/public/_redirects b/public/_redirects index 21c9d0e12..a5240a9fc 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1145,7 +1145,7 @@ /develop/quick-reference/older-versions /develop/quick-reference/release-notes/2024 # Deep links included in streamlit/streamlit source code -/st.connections.snowflakeconnection-configuration /develop/api-reference/connections/st.connections.snowflakeconnection#configuration +/st.connections.snowflakeconnection-configuration /develop/api-reference/connections/st.connections.snowflakeconnection /st.page.automatic-page-labels /develop/concepts/multipage-apps/overview#how-streamlit-converts-filenames-into-labels-and-titles /st.page.automatic-page-urls /develop/concepts/multipage-apps/overview#how-streamlit-converts-filenames-into-url-pathnames /end-users/enable-peripherals /knowledge-base/using-streamlit/enable-camera diff --git a/public/images/databases/snowflake-1.png b/public/images/databases/snowflake-1.png deleted file mode 100644 index c5ec6514a..000000000 Binary files a/public/images/databases/snowflake-1.png and /dev/null differ diff --git a/public/images/databases/snowflake-2.png b/public/images/databases/snowflake-2.png deleted file mode 100644 index 6557397da..000000000 Binary files a/public/images/databases/snowflake-2.png and /dev/null differ diff --git a/public/images/databases/snowflake-3.png b/public/images/databases/snowflake-3.png deleted file mode 100644 index 71d63b413..000000000 Binary files a/public/images/databases/snowflake-3.png and /dev/null differ diff --git a/public/images/databases/snowflake-4.png b/public/images/databases/snowflake-4.png deleted file mode 100644 index 90e76a0a8..000000000 Binary files a/public/images/databases/snowflake-4.png and /dev/null differ diff --git a/public/images/databases/snowflake-5.png b/public/images/databases/snowflake-5.png deleted file mode 100644 index 88ca1d30a..000000000 Binary files a/public/images/databases/snowflake-5.png and /dev/null differ diff --git a/public/images/databases/snowflake-database-new.png b/public/images/databases/snowflake-database-new.png new file mode 100644 index 000000000..b75e7a870 Binary files /dev/null and b/public/images/databases/snowflake-database-new.png differ diff --git a/public/images/databases/snowflake-worksheet-execute.png b/public/images/databases/snowflake-worksheet-execute.png new file mode 100644 index 000000000..c53e6a23c Binary files /dev/null and b/public/images/databases/snowflake-worksheet-execute.png differ diff --git a/public/images/get-started/SiS-1-landing-page.png b/public/images/get-started/SiS-1-landing-page.png index 472417abd..08d707883 100644 Binary files a/public/images/get-started/SiS-1-landing-page.png and b/public/images/get-started/SiS-1-landing-page.png differ diff --git a/public/images/get-started/SiS-2-databases.png b/public/images/get-started/SiS-2-databases.png index 671200176..2d71a93b8 100644 Binary files a/public/images/get-started/SiS-2-databases.png and b/public/images/get-started/SiS-2-databases.png differ diff --git a/public/images/get-started/SiS-3-create-app.png b/public/images/get-started/SiS-3-create-app.png index b06f7aee4..26a22f06d 100644 Binary files a/public/images/get-started/SiS-3-create-app.png and b/public/images/get-started/SiS-3-create-app.png differ diff --git a/public/images/get-started/SiS-4-hello-world-1.png b/public/images/get-started/SiS-4-hello-world-1.png deleted file mode 100644 index d62fe1620..000000000 Binary files a/public/images/get-started/SiS-4-hello-world-1.png and /dev/null differ diff --git a/public/images/get-started/SiS-4-hello-world.png b/public/images/get-started/SiS-4-hello-world.png new file mode 100644 index 000000000..57d1394c3 Binary files /dev/null and b/public/images/get-started/SiS-4-hello-world.png differ diff --git a/public/images/get-started/SiS-5-hello-world-2.png b/public/images/get-started/SiS-5-hello-world-2.png deleted file mode 100644 index 024552d62..000000000 Binary files a/public/images/get-started/SiS-5-hello-world-2.png and /dev/null differ diff --git a/public/images/get-started/SiS-5-hello-world-edit.png b/public/images/get-started/SiS-5-hello-world-edit.png new file mode 100644 index 000000000..d7f1c526d Binary files /dev/null and b/public/images/get-started/SiS-5-hello-world-edit.png differ diff --git a/public/images/get-started/SiS-6-hello-world-return.png b/public/images/get-started/SiS-6-hello-world-return.png deleted file mode 100644 index df28b975c..000000000 Binary files a/public/images/get-started/SiS-6-hello-world-return.png and /dev/null differ diff --git a/public/images/get-started/SiS-7-hello-world-edit.png b/public/images/get-started/SiS-7-hello-world-edit.png deleted file mode 100644 index 0ff15c5a5..000000000 Binary files a/public/images/get-started/SiS-7-hello-world-edit.png and /dev/null differ diff --git a/python/streamlit.json b/python/streamlit.json index ef5f64ec6..1b0a11751 100644 --- a/python/streamlit.json +++ b/python/streamlit.json @@ -68335,7 +68335,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.28.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -68442,7 +68442,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.28.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -76404,7 +76405,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.29.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -76511,7 +76512,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.29.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -84550,7 +84552,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.30.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -84657,7 +84659,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.30.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -93231,7 +93234,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.31.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -93342,7 +93345,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.31.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -102135,7 +102139,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.32.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -102246,7 +102250,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.32.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -111191,7 +111196,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.33.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -111302,7 +111307,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.33.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -120470,7 +120476,7 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.34.0/lib/streamlit/connections/sql_connection.py#L47", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", "args": [], "returns": [] @@ -120581,7 +120587,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.34.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -129925,8 +129932,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.35.0/lib/streamlit/connections/sql_connection.py#L48", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", - "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 3: Configuration with keyword arguments

\n

You can configure your SQL connection with keyword arguments (with or\nwithout secrets.toml). For example, if you use Microsoft Entra ID with\na Microsoft Azure SQL server, you can quickly set up a local connection for\ndevelopment using interactive authentication.

\n

This example requires the Microsoft ODBC Driver for SQL Server\nfor Windows in addition to the sqlalchemy and pyodbc packages for\nPython.

\n
\nimport streamlit as st\n\nconn = st.connection(\n    "sql",\n    dialect="mssql",\n    driver="pyodbc",\n    host="xxx.database.windows.net",\n    database="xxx",\n    username="xxx",\n    query={\n        "driver": "ODBC Driver 18 for SQL Server",\n        "authentication": "ActiveDirectoryInteractive",\n        "encrypt": "yes",\n    },\n)\n\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", + "description": "

A connection to a SQL database using a SQLAlchemy Engine.

\n

Initialize this connection object using st.connection("sql") or\nst.connection("<name>", type="sql"). Connection parameters for a\nSQLConnection can be specified using secrets.toml and/or **kwargs.\nPossible connection parameters include:

\n
    \n
  • url or keyword arguments for sqlalchemy.engine.URL.create(), except\ndrivername. Use dialect and driver instead of drivername.
  • \n
  • Keyword arguments for sqlalchemy.create_engine(), including custom\nconnect() arguments used by your specific dialect or driver.
  • \n
  • autocommit. If this is False (default), the connection operates\nin manual commit (transactional) mode. If this is True, the\nconnection operates in autocommit (non-transactional) mode.
  • \n
\n

If url exists as a connection parameter, Streamlit will pass it to\nsqlalchemy.engine.make_url(). Otherwise, Streamlit requires (at a\nminimum) dialect, username, and host. Streamlit will use\ndialect and driver (if defined) to derive drivername, then pass\nthe relevant connection parameters to sqlalchemy.engine.URL.create().

\n

In addition to the default keyword arguments for sqlalchemy.create_engine(),\nyour dialect may accept additional keyword arguments. For example, if you\nuse dialect="snowflake" with Snowflake SQLAlchemy,\nyou can pass a value for private_key to use key-pair authentication. If\nyou use dialect="bigquery" with Google BigQuery,\nyou can pass a value for location.

\n

SQLConnection provides the .query() convenience method, which can be\nused to run simple, read-only queries with both caching and simple error\nhandling/retries. More complex database interactions can be performed by\nusing the .session property to receive a regular SQLAlchemy Session.

\n
\n

Important

\n

SQLAlchemy must be installed\nin your environment to use this connection. You must also install your\ndriver, such as pyodbc or psycopg2.

\n
\n", "args": [], "returns": [] }, @@ -130036,7 +130043,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.35.0/lib/streamlit/connections/snowflake_connection.py#L41", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -139701,8 +139709,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.36.0/lib/streamlit/connections/sql_connection.py#L49", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", - "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 3: Configuration with keyword arguments

\n

You can configure your SQL connection with keyword arguments (with or\nwithout secrets.toml). For example, if you use Microsoft Entra ID with\na Microsoft Azure SQL server, you can quickly set up a local connection for\ndevelopment using interactive authentication.

\n

This example requires the Microsoft ODBC Driver for SQL Server\nfor Windows in addition to the sqlalchemy and pyodbc packages for\nPython.

\n
\nimport streamlit as st\n\nconn = st.connection(\n    "sql",\n    dialect="mssql",\n    driver="pyodbc",\n    host="xxx.database.windows.net",\n    database="xxx",\n    username="xxx",\n    query={\n        "driver": "ODBC Driver 18 for SQL Server",\n        "authentication": "ActiveDirectoryInteractive",\n        "encrypt": "yes",\n    },\n)\n\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", + "description": "

A connection to a SQL database using a SQLAlchemy Engine.

\n

Initialize this connection object using st.connection("sql") or\nst.connection("<name>", type="sql"). Connection parameters for a\nSQLConnection can be specified using secrets.toml and/or **kwargs.\nPossible connection parameters include:

\n
    \n
  • url or keyword arguments for sqlalchemy.engine.URL.create(), except\ndrivername. Use dialect and driver instead of drivername.
  • \n
  • Keyword arguments for sqlalchemy.create_engine(), including custom\nconnect() arguments used by your specific dialect or driver.
  • \n
  • autocommit. If this is False (default), the connection operates\nin manual commit (transactional) mode. If this is True, the\nconnection operates in autocommit (non-transactional) mode.
  • \n
\n

If url exists as a connection parameter, Streamlit will pass it to\nsqlalchemy.engine.make_url(). Otherwise, Streamlit requires (at a\nminimum) dialect, username, and host. Streamlit will use\ndialect and driver (if defined) to derive drivername, then pass\nthe relevant connection parameters to sqlalchemy.engine.URL.create().

\n

In addition to the default keyword arguments for sqlalchemy.create_engine(),\nyour dialect may accept additional keyword arguments. For example, if you\nuse dialect="snowflake" with Snowflake SQLAlchemy,\nyou can pass a value for private_key to use key-pair authentication. If\nyou use dialect="bigquery" with Google BigQuery,\nyou can pass a value for location.

\n

SQLConnection provides the .query() convenience method, which can be\nused to run simple, read-only queries with both caching and simple error\nhandling/retries. More complex database interactions can be performed by\nusing the .session property to receive a regular SQLAlchemy Session.

\n
\n

Important

\n

SQLAlchemy must be installed\nin your environment to use this connection. You must also install your\ndriver, such as pyodbc or psycopg2.

\n
\n", "args": [], "returns": [] }, @@ -139812,7 +139820,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.36.0/lib/streamlit/connections/snowflake_connection.py#L42", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -149341,8 +149350,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.37.0/lib/streamlit/connections/sql_connection.py#L49", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", - "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 3: Configuration with keyword arguments

\n

You can configure your SQL connection with keyword arguments (with or\nwithout secrets.toml). For example, if you use Microsoft Entra ID with\na Microsoft Azure SQL server, you can quickly set up a local connection for\ndevelopment using interactive authentication.

\n

This example requires the Microsoft ODBC Driver for SQL Server\nfor Windows in addition to the sqlalchemy and pyodbc packages for\nPython.

\n
\nimport streamlit as st\n\nconn = st.connection(\n    "sql",\n    dialect="mssql",\n    driver="pyodbc",\n    host="xxx.database.windows.net",\n    database="xxx",\n    username="xxx",\n    query={\n        "driver": "ODBC Driver 18 for SQL Server",\n        "authentication": "ActiveDirectoryInteractive",\n        "encrypt": "yes",\n    },\n)\n\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", + "description": "

A connection to a SQL database using a SQLAlchemy Engine.

\n

Initialize this connection object using st.connection("sql") or\nst.connection("<name>", type="sql"). Connection parameters for a\nSQLConnection can be specified using secrets.toml and/or **kwargs.\nPossible connection parameters include:

\n
    \n
  • url or keyword arguments for sqlalchemy.engine.URL.create(), except\ndrivername. Use dialect and driver instead of drivername.
  • \n
  • Keyword arguments for sqlalchemy.create_engine(), including custom\nconnect() arguments used by your specific dialect or driver.
  • \n
  • autocommit. If this is False (default), the connection operates\nin manual commit (transactional) mode. If this is True, the\nconnection operates in autocommit (non-transactional) mode.
  • \n
\n

If url exists as a connection parameter, Streamlit will pass it to\nsqlalchemy.engine.make_url(). Otherwise, Streamlit requires (at a\nminimum) dialect, username, and host. Streamlit will use\ndialect and driver (if defined) to derive drivername, then pass\nthe relevant connection parameters to sqlalchemy.engine.URL.create().

\n

In addition to the default keyword arguments for sqlalchemy.create_engine(),\nyour dialect may accept additional keyword arguments. For example, if you\nuse dialect="snowflake" with Snowflake SQLAlchemy,\nyou can pass a value for private_key to use key-pair authentication. If\nyou use dialect="bigquery" with Google BigQuery,\nyou can pass a value for location.

\n

SQLConnection provides the .query() convenience method, which can be\nused to run simple, read-only queries with both caching and simple error\nhandling/retries. More complex database interactions can be performed by\nusing the .session property to receive a regular SQLAlchemy Session.

\n
\n

Important

\n

SQLAlchemy must be installed\nin your environment to use this connection. You must also install your\ndriver, such as pyodbc or psycopg2.

\n
\n", "args": [], "returns": [] }, @@ -149452,7 +149461,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.37.0/lib/streamlit/connections/snowflake_connection.py#L42", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -159145,8 +159155,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.38.0/lib/streamlit/connections/sql_connection.py#L54", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", - "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 3: Configuration with keyword arguments

\n

You can configure your SQL connection with keyword arguments (with or\nwithout secrets.toml). For example, if you use Microsoft Entra ID with\na Microsoft Azure SQL server, you can quickly set up a local connection for\ndevelopment using interactive authentication.

\n

This example requires the Microsoft ODBC Driver for SQL Server\nfor Windows in addition to the sqlalchemy and pyodbc packages for\nPython.

\n
\nimport streamlit as st\n\nconn = st.connection(\n    "sql",\n    dialect="mssql",\n    driver="pyodbc",\n    host="xxx.database.windows.net",\n    database="xxx",\n    username="xxx",\n    query={\n        "driver": "ODBC Driver 18 for SQL Server",\n        "authentication": "ActiveDirectoryInteractive",\n        "encrypt": "yes",\n    },\n)\n\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", + "description": "

A connection to a SQL database using a SQLAlchemy Engine.

\n

Initialize this connection object using st.connection("sql") or\nst.connection("<name>", type="sql"). Connection parameters for a\nSQLConnection can be specified using secrets.toml and/or **kwargs.\nPossible connection parameters include:

\n
    \n
  • url or keyword arguments for sqlalchemy.engine.URL.create(), except\ndrivername. Use dialect and driver instead of drivername.
  • \n
  • Keyword arguments for sqlalchemy.create_engine(), including custom\nconnect() arguments used by your specific dialect or driver.
  • \n
  • autocommit. If this is False (default), the connection operates\nin manual commit (transactional) mode. If this is True, the\nconnection operates in autocommit (non-transactional) mode.
  • \n
\n

If url exists as a connection parameter, Streamlit will pass it to\nsqlalchemy.engine.make_url(). Otherwise, Streamlit requires (at a\nminimum) dialect, username, and host. Streamlit will use\ndialect and driver (if defined) to derive drivername, then pass\nthe relevant connection parameters to sqlalchemy.engine.URL.create().

\n

In addition to the default keyword arguments for sqlalchemy.create_engine(),\nyour dialect may accept additional keyword arguments. For example, if you\nuse dialect="snowflake" with Snowflake SQLAlchemy,\nyou can pass a value for private_key to use key-pair authentication. If\nyou use dialect="bigquery" with Google BigQuery,\nyou can pass a value for location.

\n

SQLConnection provides the .query() convenience method, which can be\nused to run simple, read-only queries with both caching and simple error\nhandling/retries. More complex database interactions can be performed by\nusing the .session property to receive a regular SQLAlchemy Session.

\n
\n

Important

\n

SQLAlchemy must be installed\nin your environment to use this connection. You must also install your\ndriver, such as pyodbc or psycopg2.

\n
\n", "args": [], "returns": [] }, @@ -159256,7 +159266,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.38.0/lib/streamlit/connections/snowflake_connection.py#L42", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] }, @@ -169167,8 +169178,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.39.0/lib/streamlit/connections/sql_connection.py#L54", - "example": "
\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("select * from pet_owners")\nst.dataframe(df)\n
\n
\n", - "description": "

A connection to a SQL database using a SQLAlchemy Engine. Initialize using st.connection("<name>", type="sql").

\n

SQLConnection provides the query() convenience method, which can be used to\nrun simple read-only queries with both caching and simple error handling/retries.\nMore complex DB interactions can be performed by using the .session property\nto receive a regular SQLAlchemy Session.

\n

SQLConnections should always be created using st.connection(), not\ninitialized directly. Connection parameters for a SQLConnection can be specified\nusing either st.secrets or **kwargs. Some frequently used parameters include:

\n
    \n
  • url or arguments for sqlalchemy.engine.URL.create().\nMost commonly it includes a dialect, host, database, username and password.
  • \n
  • create_engine_kwargs can be passed via st.secrets, such as for\nsnowflake-sqlalchemy\nor Google BigQuery.\nThese can also be passed directly as **kwargs to connection().
  • \n
  • autocommit=True to run with isolation level AUTOCOMMIT. Default is False.
  • \n
\n", + "examples": "
\n

Example 1: Configuration with URL

\n

You can configure your SQL connection using Streamlit's\nSecrets management.\nThe following example specifies a SQL connection URL.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\nurl = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 2: Configuration with dialect, host, and username

\n

If you do not specify url, you must at least specify dialect,\nhost, and username instead. The following example also includes\npassword.

\n

.streamlit/secrets.toml:

\n
\n[connections.sql]\ndialect = "xxx"\nhost = "xxx"\nusername = "xxx"\npassword = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\n\nconn = st.connection("sql")\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n

Example 3: Configuration with keyword arguments

\n

You can configure your SQL connection with keyword arguments (with or\nwithout secrets.toml). For example, if you use Microsoft Entra ID with\na Microsoft Azure SQL server, you can quickly set up a local connection for\ndevelopment using interactive authentication.

\n

This example requires the Microsoft ODBC Driver for SQL Server\nfor Windows in addition to the sqlalchemy and pyodbc packages for\nPython.

\n
\nimport streamlit as st\n\nconn = st.connection(\n    "sql",\n    dialect="mssql",\n    driver="pyodbc",\n    host="xxx.database.windows.net",\n    database="xxx",\n    username="xxx",\n    query={\n        "driver": "ODBC Driver 18 for SQL Server",\n        "authentication": "ActiveDirectoryInteractive",\n        "encrypt": "yes",\n    },\n)\n\ndf = conn.query("SELECT * FROM pet_owners")\nst.dataframe(df)\n
\n
\n", + "description": "

A connection to a SQL database using a SQLAlchemy Engine.

\n

Initialize this connection object using st.connection("sql") or\nst.connection("<name>", type="sql"). Connection parameters for a\nSQLConnection can be specified using secrets.toml and/or **kwargs.\nPossible connection parameters include:

\n
    \n
  • url or keyword arguments for sqlalchemy.engine.URL.create(), except\ndrivername. Use dialect and driver instead of drivername.
  • \n
  • Keyword arguments for sqlalchemy.create_engine(), including custom\nconnect() arguments used by your specific dialect or driver.
  • \n
  • autocommit. If this is False (default), the connection operates\nin manual commit (transactional) mode. If this is True, the\nconnection operates in autocommit (non-transactional) mode.
  • \n
\n

If url exists as a connection parameter, Streamlit will pass it to\nsqlalchemy.engine.make_url(). Otherwise, Streamlit requires (at a\nminimum) dialect, username, and host. Streamlit will use\ndialect and driver (if defined) to derive drivername, then pass\nthe relevant connection parameters to sqlalchemy.engine.URL.create().

\n

In addition to the default keyword arguments for sqlalchemy.create_engine(),\nyour dialect may accept additional keyword arguments. For example, if you\nuse dialect="snowflake" with Snowflake SQLAlchemy,\nyou can pass a value for private_key to use key-pair authentication. If\nyou use dialect="bigquery" with Google BigQuery,\nyou can pass a value for location.

\n

SQLConnection provides the .query() convenience method, which can be\nused to run simple, read-only queries with both caching and simple error\nhandling/retries. More complex database interactions can be performed by\nusing the .session property to receive a regular SQLAlchemy Session.

\n
\n

Important

\n

SQLAlchemy must be installed\nin your environment to use this connection. You must also install your\ndriver, such as pyodbc or psycopg2.

\n
\n", "args": [], "returns": [] }, @@ -169278,7 +169289,8 @@ } ], "source": "https://github.com/streamlit/streamlit/blob/1.39.0/lib/streamlit/connections/snowflake_connection.py#L42", - "description": "

A connection to Snowflake using the Snowflake Python Connector. Initialize using

\n

st.connection("<name>", type="snowflake").

\n

SnowflakeConnection supports direct SQL querying using .query("..."), access to\nthe underlying Snowflake Python Connector object with .raw_connection, and other\nconvenience functions. See the methods below for more information.\nSnowflakeConnections should always be created using st.connection(), not\ninitialized directly.

\n", + "examples": "
\n

Example 1: Configuration with Streamlit secrets

\n

You can configure your Snowflake connection using Streamlit's\nSecrets management.\nFor example, if you have MFA enabled on your account, you can connect using\nkey-pair authentication.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\naccount = "xxx-xxx"\nuser = "xxx"\nprivate_key_file = "/xxx/xxx/xxx.p8"\nrole = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 2: Configuration with keyword arguments and external authentication

\n

You can configure your Snowflake connection with keyword arguments (with or\nwithout secrets.toml). For example, if your Snowflake account supports\nSSO, you can set up a quick local connection for development using browser-based SSO.

\n
\nimport streamlit as st\nconn = st.connection(\n    "snowflake", account="xxx-xxx", user="xxx", authenticator="externalbrowser"\n)\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 3: Named connection with Snowflake's connection configuration file

\n

Snowflake's Python Connector supports a connection configuration file,\nwhich is well integrated with Streamlit's SnowflakeConnection. If you\nalready have one or more connections configured, all you need to do is pass\nthe name of the connection to use.

\n

~/.snowflake/connections.toml:

\n
\n[my_connection]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("my_connection", type="snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 4: Named connection with Streamlit secrets and Snowflake's connection configuration file

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can pass the connection name through\nsecrets.toml.

\n

.streamlit/secrets.toml:

\n
\n[connections.snowflake]\nconnection_name = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 5: Default connection with an environment variable

\n

If you have a Snowflake configuration file with a connection named\nmy_connection as in Example 3, you can set an environment variable to\ndeclare it as the default Snowflake connection.

\n
\nSNOWFLAKE_DEFAULT_CONNECTION_NAME = "my_connection"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n

Example 6: Default connection in Snowflake's connection configuration file

\n

If you have a Snowflake configuration file that defines your default\nconnection, Streamlit will automatically use it if no other connection is\ndeclared.

\n

~/.snowflake/connections.toml:

\n
\n[default]\naccount = "xxx-xxx"\nuser = "xxx"\npassword = "xxx"\nwarehouse = "xxx"\ndatabase = "xxx"\nschema = "xxx"\n
\n

Your app code:

\n
\nimport streamlit as st\nconn = st.connection("snowflake")\ndf = conn.query("SELECT * FROM my_table")\n
\n
\n", + "description": "

A connection to Snowflake using the Snowflake Connector for Python.

\n

Initialize this connection object using st.connection("snowflake") or\nst.connection("<name>", type="snowflake"). Connection parameters for a\nSnowflakeConnection can be specified using secrets.toml and/or\n**kwargs. Connection parameters are passed to\nsnowflake.connector.connect().

\n

When an app is running in Streamlit in Snowflake,\nst.connection("snowflake") connects automatically using the app owner's\nrole without further configuration. **kwargs will be ignored in this\ncase. Use secrets.toml and **kwargs to configure your connection\nfor local development.

\n

SnowflakeConnection includes several convenience methods. For example, you\ncan directly execute a SQL query with .query() or access the underlying\nSnowflake Connector object with .raw_connection.

\n
\n

Tip

\n

snowflake-snowpark-python\nmust be installed in your environment to use this connection. You can\ninstall Snowflake extras along with Streamlit:

\n
\n>>> pip install streamlit[snowflake]\n
\n
\n
\n

Important

\n

Account identifiers must be of the form <orgname>-<account_name>\nwhere <orgname> is the name of your Snowflake organization and\n<account_name> is the unique name of your account within your\norganization. This is dash-separated, not dot-separated like when used\nin SQL queries. For more information, see Account identifiers.

\n
\n", "args": [], "returns": [] },