Streamlit in Snowflake: Enable Git integration and multi-file editing for Streamlit in Snowflake apps

Attention

This behavior change is in the 2025_01 bundle.

For the current status of the bundle, refer to Bundle History.

Streamlit in Snowflake apps behave as follows:

Before this change:

Git integration and multi-file editing for Streamlit in Snowflake apps are not supported in Snowsight.

After this change:

Git integration and multi-file editing are supported for new Streamlit in Snowflake apps and include changes in the following areas:

Note

The existing Streamlit in Snowflake apps using ROOT_LOCATION work as before, but Git integration and multi-file editing are not supported.

Snowsight

Create a Streamlit in Snowflake app from a file in a Git repository

要从 Git 存储卡中的文件创建 Streamlit 应用程序,请执行以下操作:

  1. Sign in to Snowsight.
  2. In the navigation menu, select Projects » Streamlit.
  3. Next to + Streamlit, open the drop-down menu and select Create from repository.
  4. For File location in repository, select the repository and branch in the repository that contain the Streamlit app file, then select the specific .py file. For details on connecting Snowflake to your Git repository, see Setting up Snowflake to use Git.
  5. For App location, select a database and schema to contain the Streamlit app. These cannot be changed after you create the app.
  6. For Query warehouse and App warehouse, select a warehouse.
  7. Select Create to create a Streamlit app from the .py file in your Git repository.

Connect a Streamlit in Snowflake app with a Git repository

要将现有的 Streamlit 应用程序连接到 Git 存储库,请执行以下操作:

  1. Sign in to Snowsight.
  2. In the navigation menu, select Projects » Streamlit, and then open or create a Streamlit app.
  3. In the Files tab, next to the database object explorer, select Connect Git Repository.
  4. For File location in repository, select the repository and branch in the repository with which you want to sync the Streamlit app.
  5. Select Select Folder.
  6. When you are prompted to commit and push your app to the Git repository, select Push to Git.

Edit multiple files within Snowsight

To edit multiple files of your Streamlit in Snowflake app within Snowsight:

  1. Sign in to Snowsight.
  2. In the navigation menu, select Projects » Streamlit, and then open or create a Streamlit app.
  3. In the Files tab, select a file to edit.

CREATE STREAMLIT 和 ALTER STREAMLIT 命令的变更

When this behavior change bundle is enabled, the following changes to CREATE STREAMLIT and ALTER STREAMLIT commands are introduced.

CREATE STREAMLIT

Streamlit 应用程序的代码不再需要单独的暂存区对象;Streamlit 对象存储应用程序代码。使用 FROM 子句,您可以指明将代码从哪个现有位置复制到 Streamlit 应用程序。

语法

CREATE [ OR REPLACE ] STREAMLIT [ IF NOT EXISTS ] <name>
  [ { VERSION <version_alias_name> |
      VERSION (COMMENT = <version_comment>) |
      VERSION <version_alias_name> (COMMENT = <version_comment>) } ]
  [ FROM <source_location>]
  MAIN_FILE = '<path_to_main_file_in_root_directory>'
  QUERY_WAREHOUSE = <warehouse_name>
  [ COMMENT = <create_comment> ]
  [ DEFAULT_VERSION = <default_version_name_or_alias> ]
  [ TITLE = '<app_title>' ]
  [ IMPORTS = ( '<stage_path_and_file_name_to_read>' [ , ... ] ) ]
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
必填参数
name

Streamlit 应用程序的名称。

path_to_main_file_in_root_directory

Specifies the filename of the Streamlit app. This filename is relative to the value of ROOT_LOCATION.

warehouse_name

指定运行由 Streamlit 应用程序发出的 SQL 查询的仓库。

可选参数

version_alias_name

用户指定的版本别名。

version_comment

用户为该版本提供的注释。

source_location

复制源文件的源位置。

create_comment

指定 Streamlit 对象的注释。默认情况下没有值。

default_version_name_or_alias

使用的默认版本名称。

app_title

为 Streamlit 应用程序指定要在 Snowsight 中显示的标题。

stage_path_and_file_name_to_read

要导入的文件的位置(暂存区)、路径和名称。

integration_name

Streamlit 应用程序代码访问外部网络所需的外部访问集成名称名称。

示例

要从暂存区创建 Streamlit 应用程序,请运行 CREATE STREAMLIT 命令,如下例所示:

CREATE STREAMLIT app
  FROM @streamlit_db.streamlit_schema.streamlit_stage;
  MAIN_FILE = 'streamlit_app.py'
  QUERY_WAREHOUSE = my_warehouse;

要从 Git 存储库创建 Streamlit 应用程序,请运行 CREATE STREAMLIT 命令,如下例所示:

CREATE STREAMLIT app
  FROM @streamlit_db.streamlit_schema.streamlit_repo/branches/streamlit_branch/;
  MAIN_FILE = 'streamlit_app.py'
  QUERY_WAREHOUSE = my_warehouse;

ALTER STREAMLIT

启用此行为变更捆绑包后,ALTER STREAMLIT 命令将更新为包括以下内容:

语法

ALTER STREAMLIT <name> ADD VERSION [ [ IF NOT EXISTS] <version_alias_name> ]
FROM <source_location>
[ COMMENT = <add_version_comment> ]

ALTER STREAMLIT <name> ADD VERSION <version_name>
FROM { <snowgit_tag_uri> | <snowgit_commit_uri> }
[ COMMENT = <git_pull_comment> ]

ALTER STREAMLIT <name> ADD LIVE VERSION [ [IF NOT EXISTS] <version_alias_name> ]
[ FROM LAST ]
[ COMMENT = <add_version_comment> ]

ALTER STREAMLIT <name> VERSION <existing_version_name_or_alias>
SET ALIAS = <new_version_name_alias>

ALTER STREAMLIT <name> COMMIT [ VERSION <live_version_alias> ] [COMMENT = <version_comment>]

ALTER STREAMLIT <name> SET DEFAULT_VERSION = <version_name> | <version_name_alias>

ALTER STREAMLIT <name> PUSH [TO <git_branch_uri>] [ { GIT_CREDENTIALS = <snowflake_secret> | USERNAME = <git_username> password = <git_password> } NAME = <git_author_name> EMAIL = <git_author_email> ] [ COMMENT = <git_push_comment>]

ALTER STREAMLIT <name> ABORT [ VERSION  <live_version_alias> ]

ALTER STREAMLIT <name> PULL

参数

name

Streamlit 应用程序的名称。

version_alias_name

用户指定的版本别名。

source_location

复制源文件的源位置。需要 OWNERSHIP 权限。

ALTER STREAMLIT name PUSH

Pushes the latest committed changes to the Git repo, using the branch stored in the base version if git_branch_uri is not specified.

如果基础版本不是基于 Git 分支,则会导致出错。需要 OWNERSHIP 权限。

git-branch-uri

推送已提交变更的目标分支。

git_author_name

要使用的 git 作者名称。

git_author_email

用作 git 作者名称的有效电子邮件地址。

git_push_comment

用户指定的注释,包含在 git 推送中。

ALTER STREAMLIT name ABORT

移除现有版本并删除其文件。如果没有指定版本,则默认删除 live_version。需要 OWNERSHIP 权限。

ALTER STREAMLIT name PULL

将源中的最新变更提取到 Streamlit 的实时版本中。需要 OWNERSHIP 权限。

DESCRIBE STREAMLIT 输出中的新列

When this behavior change bundle is enabled, the output of the DESCRIBE STREAMLIT command includes the following new columns:

列名称描述
default_version以备将来使用。
default_version_name以备将来使用。
default_version_alias以备将来使用。
default_version_location_uri以备将来使用。
default_version_source_location_uri以备将来使用。
default_version_git_commit_hash以备将来使用。
live_version字符串。指定此应用程序的实时版本。
live_version_name字符串。此应用程序实时版本的名称。
live_version_alias字符串。此应用程序实时版本的别名。
live_version_location_uri字符串。实时版本文件的存储位置的 URI。
live_version_source_location_uri字符串。指定复制 live_version 的源位置 URI。如果未克隆该 Streamlit,则为空。
live_version_git_commit_hash字符串。live_version 指向的 git 提交的十六进制哈希。如果未连接 Git 存储库,则为空。

参考:1888