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:

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.

  1. Sign in to Snowsight.

  2. In the navigation menu, select Projects » Streamlit.

  3. Select + Streamlit App.

  4. Enter a name for your app.

  5. In the App location dropdown, select the database and schema for your app.

  6. 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.

  7. Select Create.

  8. 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.

  9. Select Run.

View a Streamlit app

For information about the privileges required to view a Streamlit app, see Privileges required to view a Streamlit app.

  1. Sign in to Snowsight.

  2. In the navigation menu, select Projects » Streamlit.

  3. Select the Streamlit app you want to view.

If you are viewing a multipage Streamlit app, select a tab to view additional pages.

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_PW secret configured in your GitHub repository settings.

Example workflow

Create a .github/workflows/deploy.yml file in your repository:

name: Deploy via Snowflake CLI

on:
  push:
    branches:
      - main

env:
  PYTHON_VERSION: '3.12'

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    environment: dev
    steps:
      - name: 'Checkout GitHub Action'
        uses: actions/checkout@v3

      - name: Install Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: 'Install Snowflake CLI'
        shell: bash
        run: |
          python -m pip install --upgrade pip
          pip install snowflake-cli

      - name: 'Create config'
        shell: bash
        env:
          SNOWFLAKE_PASSWORD: ${{ secrets.SNOWCLI_PW }}
        run: |
          mkdir -p ~/.snowflake
          cp config.toml ~/.snowflake/config.toml
          echo "password = \"$SNOWFLAKE_PASSWORD\"" >> ~/.snowflake/config.toml
          chmod 0600 ~/.snowflake/config.toml

      - name: 'Deploy the Streamlit app'
        shell: bash
        run: |
          snow streamlit deploy --replace

Commit and push the file to trigger the workflow.

For more information, see GitHub Actions documentation.