Creating a Streamlit app¶
Prerequisites¶
Before creating a Streamlit app with Snowflake CLI, you should meet the following prerequisites:
Ensure that your account has the correct privileges as described in Privileges required to create and use a Streamlit app.
Ensure that you can create or have access to a named stage where you can upload your Streamlit app files.
Bootstrap a Streamlit app¶
The snow init
command creates a local directory with a sample set of files that help you get started creating a Streamlit app. When you execute this command, Snowflake CLI creates the following directory structure:
example_streamlit/ - project name (default: example_streamlit)
snowflake.yml - configuration for snow streamlit commands
environment.yml - additional config for Streamlit, for example installing packages
streamlit_app.py - entrypoint file of the app
pages/ - directory name for Streamlit pages (default pages)
common/ - example “shared library”
To initialize a Streamlit app named my-streamlit-app
, enter the following command:
snow init new_streamlit_project --template-source ../local_templates/example_streamlit -D query_warehouse=dev_warehouse -D stage=testing
Caution
Files inside a project directory are processed by Snowflake CLI and could be uploaded to Snowflake when executing other snow streamlit
commands. You should use caution when putting any sensitive information inside files in a project directory.
For more information about the file structure, see Create the Streamlit files on your local file system.
Create the project definition for a Streamlit app¶
Each Streamlit app in Snowflake must include a snowflake.yml
project definition file. Streamlit is limited to one application per project definition file.
The following shows a sample snowflake.yml
project definition file:
definition_version: 2
entities:
my_streamlit:
type: streamlit
identifier: streamlit_app
stage: my_streamlit_stage
query_warehouse: my_streamlit_warehouse
main_file: streamlit_app.py
pages_dir: pages/
external_access_integrations:
- test_egress
secrets:
dummy_secret: "db.schema.dummy_secret"
imports:
- "@my_stage/foo.py"
artifacts:
- common/hello.py
- environment.yml
The following table describes the properties of a Streamlit project definition.
Property |
Definition |
---|---|
identifier optional, string |
Optional Snowflake identifier for the entity. The value can have the following forms:
|
type optional, string |
Must be |
comment optional, string |
Comment for the Streamlit dashboard. |
title required, string |
Human-readable title for the Streamlit dashboard. |
stage optional, string |
Stage in which the app’s artifacts will be stored. Default: None. |
query_warehouse required, string |
Snowflake warehouse to host the app. |
main_file optional, string |
Entrypoint file of the streamlit app. Default: “streamlit_app.py”. |
pages_dir optional, string |
Streamlit pages. Default: “pages”. |
artifacts required, string sequence |
List of files which should be included into deployment artifacts. |