Creating a Streamlit app

Prerequisites

Before creating a Streamlit app with Snowflake CLI, you should meet the following prerequisites:

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
Copy

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
Copy

The following table describes the properties of a Streamlit project definition.

Streamlit project definition properties

Property

Definition

identifier

optional, string

Optional Snowflake identifier for the entity. The value can have the following forms:

  • String identifier text

    identifer: my-streamlit-id
    
    Copy

    Both unquoted and quoted identifiers are supported. To use quoted identifiers, include the surrounding quotes in the YAML value (e.g. ’”My Streamlit Application”’).

  • Object

    identifer:
      name: my-streamlit-id
      schema: my-schema # optional
      database: my-db # optional
    
    Copy

    Note

    An error occurs if you specify a schema or database and use a fully-qualified name in the name property (such as mydb.schema1.my-app).

type

optional, string

Must be streamlit.

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.