Getting started with Streamlit in Snowflake¶
This topic walks you through deploying your first Streamlit in Snowflake app in under five minutes using a container runtime. After that, two hands-on examples show you how to build real apps that query data, personalize the experience for each viewer, and write back to Snowflake.
Prerequisites¶
Before you can create a Streamlit app, ensure that your administrator has completed the essential security setup for Streamlit apps.
Your role must have the following privileges:
| Privilege | Object | Notes |
|---|---|---|
| USAGE | Database where you create the Streamlit app | |
| CREATE STREAMLIT, USAGE | Schema where you create the Streamlit app | |
| USAGE | Compute pool that runs the Streamlit app | For all accounts, Snowflake configures a general-purpose compute pool that typical users will have access to. For more information, see Configuring your own preferred compute pools for Streamlit apps. |
| USAGE | Warehouse that runs queries in the Streamlit app |
For more information, see Privileges required to create and use a Streamlit app.
Deploy your first Streamlit in Snowflake app¶
The fastest way to get started is to create a Streamlit app using the default starter code. When you create an app without specifying source files, Snowflake provides example code automatically.
- Sign in to Snowsight.
- In the navigation menu, select Projects » Streamlit.
- Select + Streamlit App.
- Enter a name for your app.
- Select a database and schema to create your app in.
- Select Run on container.
- Select a compute pool and a query warehouse.
- Select Create.
Snowsight redirects you to the app editor. Your app will be ready within a few minutes. Then, you can view and edit it immediately.
Run the following SQL commands in a SQL session:
To view your app, sign in to Snowsight, then In the navigation menu, select Projects » Streamlit, and select your app.
Note
Snowflake CLI version 3.14.0 or later is required. Version 3.14+ uses the modern CREATE STREAMLIT syntax by default.
-
Initialize a new Streamlit project:
-
Navigate to the project directory:
-
Edit the
snowflake.ymlfile to use a container runtime: -
Deploy the app and open it in your browser:
Edit your app¶
After deploying, you can edit the app code to customize it. For a quick test:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Streamlit, and then select your app.
- Select Edit.
- Modify the code in
streamlit_app.py. - Select Run to see your changes.
-
Get your app’s source location:
-
Copy an updated file to that location:
- Edit
streamlit_app.pyin your local project directory. - Redeploy:
For more information, see Edit your Streamlit app.
What’s next?¶
Now that you have a running app, try one of these hands-on examples:
- Example: Build a personalized data dashboard: Build a dashboard that queries Snowflake data and personalizes
the display for each viewer using
st.connectionandst.user. - Example: Build a form that writes to Snowflake: Build a form that writes user input back to a Snowflake table,
demonstrating
st.form, dependency management, andst.user.
To learn more about specific topics:
- Create your Streamlit app: Detailed instructions for creating apps from Snowsight, SQL, or the CLI.
- Manage dependencies for your Streamlit app: Add Python packages to your app.
- Runtime environments for Streamlit apps: Understand container and warehouse runtimes.
- External network access in Streamlit in Snowflake: Connect your app to external services.