Create your Streamlit app¶
This topic describes how to deploy a Streamlit in Snowflake app from existing Streamlit app code. If you’re new to Streamlit in Snowflake and want to try a starter app first, see Getting started with Streamlit in Snowflake.
Before you begin:
Ensure that you meet the required prerequisites.
Choose a runtime environment for your app (container or warehouse).
Prepare your dependencies in a
requirements.txt,pyproject.toml, orenvironment.ymlfile.Review the expected file organization for your app’s source files.
Deploy your app code¶
If you already have a Streamlit app on your local machine or on a Snowflake stage, use one of the following methods to create a STREAMLIT object from your source files.
Sign in to Snowsight.
In the navigation menu, select Projects » Streamlit.
Select + Streamlit App.
Enter a name for your app.
In the App location dropdown, select the database and schema for your app.
Configure the runtime for your app:
To create a container-runtime app, make the following selections:
Select Run on container.
Select a compute pool to run your app on.
Select a query warehouse to run your app’s queries on.
To create a warehouse-runtime app, make the following selections:
Select Run on warehouse.
Select a warehouse to run your app on.
Select Create.
In the editor, replace the starter code with your own app code. You can paste code directly or upload files:
To upload files, select + (Add) » Upload file, choose the files, and select Upload.
To create additional files (such as
pyproject.toml), select + (Add) » Create new file.
Select Run.
Upload your app files to a named stage:
You can also upload files through Snowsight as described in Staging files using Snowsight.
Create the STREAMLIT object from your staged files:
To create a container-runtime app, run the following command:
To create a warehouse-runtime app, omit the RUNTIME_NAME and COMPUTE_POOL parameters:
Push your code to the live version:
You must run this command before users with only USAGE privilege on the Streamlit object can view it.
For the full parameter reference, see CREATE STREAMLIT.
Note
Snowflake CLI version 3.14.0 or later is required. Version 3.14+ uses the modern CREATE STREAMLIT syntax by default.
In your project directory, create a
snowflake.ymlfile alongside your app code.To create a container-runtime app, use the following configuration:
To create a warehouse-runtime app, omit
compute_poolandruntime_name:List all files your app needs in the
artifactssection.Deploy the app:
For more information, see the Creating a Streamlit app and Deploying a Streamlit app guides.
View a Streamlit app¶
For information about the privileges required to view a Streamlit app, see Privileges required to view a Streamlit app.
Sign in to Snowsight.
In the navigation menu, select Projects » Streamlit.
Select the Streamlit app you want to view.
If you are viewing a multipage Streamlit app, select a tab to view additional pages.
To view information about a STREAMLIT object:
To view the app in a browser, sign in to Snowsight, then In the navigation menu, select Projects » Streamlit, and select the app.
To get the URL for your deployed app:
Set up CI/CD with GitHub Actions¶
You can deploy Streamlit in Snowflake apps automatically from a Git repository using Snowflake CLI and GitHub Actions. You can use a similar approach with other CI/CD providers.
Prerequisites¶
A GitHub repository containing your Streamlit app files and
snowflake.yml.A
SNOWCLI_PWsecret configured in your GitHub repository settings.
Example workflow¶
Create a .github/workflows/deploy.yml file in your repository:
Commit and push the file to trigger the workflow.
For more information, see GitHub Actions documentation.