ALTER STREAMLIT¶
修改现有 Streamlit 对象的属性。
语法¶
ALTER STREAMLIT [ IF EXISTS ] <name> SET
[ MAIN_FILE = '<filename>']
[ QUERY_WAREHOUSE = <warehouse_name> ]
[ RUNTIME_NAME = '<runtime_name>' ]
[ COMPUTE_POOL = <compute_pool_name> ]
[ COMMENT = '<string_literal>']
[ TITLE = '<app_title>' ]
[ IMPORTS = ( '<stage_path_and_file_name_to_read>' [ , ... ] ) ]
[ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
[ SECRETS = ( '<snowflake_secret_name>' = <snowflake_secret> [ , ... ] ) ]
ALTER STREAMLIT [ IF EXISTS ] <name> RENAME TO <new_name>
ALTER STREAMLIT <name> COMMIT
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
ALTER STREAMLIT <name> PULL
ALTER STREAMLIT <name> ADD LIVE VERSION FROM LAST
For Streamlit objects created with ROOT_LOCATION, only the following syntax is supported:
重要
ROOT_LOCATION is a legacy parameter and may be deprecated in a future release. For Streamlit apps created using ROOT_LOCATION, multi-file editing and Git integration are not supported.
ALTER STREAMLIT [ IF EXISTS ] <name> SET
[ ROOT_LOCATION = '<stage_path_and_root_directory>' ]
[ MAIN_FILE = '<path_to_main_file>']
[ QUERY_WAREHOUSE = <warehouse_name> ]
[ COMMENT = '<string_literal>']
[ TITLE = '<app_title>' ]
[ IMPORTS = ( '<stage_path_and_file_name_to_read>' [ , ... ] ) ]
[ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
ALTER STREAMLIT [ IF EXISTS ] <name> RENAME TO <new_name>
参数¶
nameStreamlit 对象的标识符。如果标识符包含空格或特殊字符,则整个字符串必须放在双引号内。放在双引号内的标识符也区分大小写。
SET ...指定要为 Streamlit 对象设置的属性:
MAIN_FILE = 'filename'Specifies the Streamlit entrypoint file. The requirements depend on the runtime type:
Warehouse runtimes: The file must be in the root of the source directory specified in FROM. Only a filename is allowed, not a path.
Container runtimes: The file can be in the root or a subdirectory. You can specify a relative path from the root of the source directory, like
'subdir/my_app.py'.If your app was created with ROOT_LOCATION instead of FROM, then MAIN_FILE can be a path relative to ROOT_LOCATION even though ROOT_LOCATION only supports warehouse runtimes.
QUERY_WAREHOUSE = warehouse_nameSpecifies the warehouse used by the Streamlit app. The behavior depends on the runtime type:
Warehouse runtimes: Specifies the warehouse to run the app code and execute SQL queries. This is the code warehouse. It's recommended to manually switch to a different warehouse within your app code for queries.
Container runtimes: Specifies the warehouse to execute SQL queries issued by the app. The app code runs on the compute pool specified by COMPUTE_POOL.
RUNTIME_NAME = 'runtime_name'Specifies the runtime environment for the Streamlit app. Use this to change the runtime from warehouse to container, from container to warehouse, or from one version to another. Runtime names follow the pattern
SYSTEM$ST_<type>_RUNTIME_PY<version>.Warehouse runtimes: Run the app in a virtual warehouse. Each viewer gets a personal instance of the app. The following warehouse runtimes are valid:
SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_9SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_10SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_11
Container runtimes: Run the app in a Snowpark Container Services compute pool. All viewers share a single, long-running instance of the app. The following container runtimes are valid:
SYSTEM$ST_CONTAINER_RUNTIME_PY3_11
重要
When changing from a warehouse runtime to a container runtime, you must also set the COMPUTE_POOL parameter as appropriate. Container runtimes require a compute pool.
COMPUTE_POOL = compute_pool_nameSpecifies the compute pool where the Streamlit app runs. This parameter is required when using a container runtime and is ignored for warehouse runtimes.
COMMENT = 'string_literal'为 Streamlit 对象添加注释或覆盖现有注释。
TITLE = 'app_title'为 Streamlit 应用程序添加要在 Snowsight 中显示的标题。
IMPORTS = ( 'stage_path_and_file_name_to_read' [ , ... ] )The location (stage), path, and name of the file(s) to import. This only applies to warehouse runtimes and is ignored for container runtimes.
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )Streamlit 应用代码为访问外部网络所需的 外部访问集成名称 名称。
For container runtimes, external access integrations are required to install packages from external package indexes like PyPI. For all runtime types, external access integrations enable the app to make outbound network requests.
SECRETS = ( 'snowflake_secret_name' = snowflake_secret [ , ... ] )Maps Snowflake secrets to secret names that can be referenced in the Streamlit app code. The secret name (left side) is how you reference the secret in your code, and the secret object (right side) is the identifier of the Snowflake secret.
For example:
SECRETS = ('api_key' = my_database.my_schema.my_secret)Secrets are only available in warehouse runtimes through the
_snowflakemodule and must be associated with an external access integration in EXTERNAL_ACCESS_INTEGRATIONS. In container runtimes, this parameter isn't supported and you must create SQL functions to access secrets instead. For more information, see 管理密钥并配置 Streamlit 应用程序.ROOT_LOCATION = 'stage_path_and_root_directory'Specifies the root stage name and prefix containing the Streamlit Python files, media files, and
environment.ymlfile. This parameter must point to a single directory inside a named internal stage.
RENAME TO new_nameSpecifies the new identifier for the Streamlit object. The identifier must be unique for the schema where the object was created.
有关标识符的更多详细信息,请参阅 标识符要求。
COMMIT将 LIVE 版本中待处理的编辑提交到新的 LAST 版本。提交后,LIVE 版本会立即与 LAST 版本完全一致。
PUSH如果未指定:samp:
TO {git_branch_uri},则使用基础版本中存储的分支将最新提交的变更推送到 Git 存储库。If the base version is not based on a Git branch, this throws an error.
TO git_branch_uri将提交的更改推送到指定的分支。
GIT_CREDENTIALS = snowflake_secret指定 Snowflake 密钥,其中包含用于对存储库进行身份验证的凭据。
USERNAME = git_username指定 Git 用户名。
PASSWORD = git_password指定 Git 密码。
NAME = git_author_name指定要使用的 Git 作者名称。
EMAIL = git_author_email指定用作 Git 作者名的有效电子邮件地址。
COMMENT = git_push_comment指定要包含在 Git 推送中的注释。
ABORT移除应用程序的当前实时版本,包括 Snowsight 中所有尚未提交的编辑。
PULL拉取最新更改。必须先中止当前实时版本,然后才能拉取。
ADD LIVE VERSION FROM LAST根据上次提交的版本,创建应用程序的新实时版本。
当 Streamlit 应用程序的所有者在 Snowsight 中打开该应用程序且实时版本不存在时,会自动执行此命令。如果其他用户访问该应用程序且实时版本不存在,则会返回错误。
访问控制要求¶
If your role does not own the objects in the following table, then your role must have the listed privileges on those objects:
权限 |
对象 |
Notes |
|---|---|---|
OWNERSHIP |
您修改的 Streamlit 对象 |
|
USAGE |
Warehouse used by the Streamlit app |
This privilege is only required if you set a new value for QUERY_WAREHOUSE. |
USAGE |
Compute pool used by the Streamlit app |
This privilege is only required if you set a new value for COMPUTE_POOL. |
USAGE |
External access integrations used by the Streamlit app |
This privilege is only required if you set a new value for EXTERNAL_ACCESS_INTEGRATIONS. |
USAGE |
Secrets used by the Streamlit app |
This privilege is only required if you set a new value for SECRETS. |
Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.
有关创建具有指定权限集的自定义角色的说明,请参阅 创建自定义角色。
使用说明¶
如果您移除应用程序的实时版本,则在您执行以下任一操作之前,用户无法访问该应用程序:
对 Streamlit 对象执行 ALTER STREAMLIT ... ADD LIVE VERSION FROM LAST。
使用拥有应用程序的角色访问 Snowsight 中的应用程序。
If you run the ALTER STREAMLIT command while viewing a Streamlit app in Snowsight, the app reflects the changes differently depending on the runtime type:
Warehouse runtime: The app doesn't reflect the changes until you select Run.
Container runtime: The app reflects the changes immediately when you next interact with the app.
如果希望更改反映在应用程序中,则必须重新加载或重新启动应用程序。
When migrating from warehouse runtime to container runtime:
You must set both RUNTIME_NAME and COMPUTE_POOL.
Your app must use Python 3.11 and Streamlit 1.50 or later.
Ensure your app code is thread-safe and optimized for concurrent viewers.
Replace
get_active_session()withst.connection("snowflake").Replace
_snowflakemodule with native Python equivalents.
For a complete migration checklist, see 在运行时环境之间迁移.
关于元数据:
注意
客户应确保在使用 Snowflake 服务时,不会将个人数据(用户对象除外)、敏感数据、出口管制数据或其他受监管数据作为元数据输入。有关更多信息,请参阅 Snowflake 中的元数据字段。
Examples¶
Change the query warehouse¶
To change the warehouse used by a Streamlit app, run the ALTER STREAMLIT command as shown in the following example:
ALTER STREAMLIT my_app
SET QUERY_WAREHOUSE = new_warehouse;
Migrate from a warehouse runtime to a container runtime¶
To migrate a Streamlit app from warehouse runtime to container runtime, run the ALTER STREAMLIT command as shown in the following example:
ALTER STREAMLIT my_app SET
RUNTIME_NAME = 'SYSTEM$ST_CONTAINER_RUNTIME_PY3_11'
COMPUTE_POOL = my_compute_pool
EXTERNAL_ACCESS_INTEGRATIONS = (pypi_access_integration);
Container runtimes require an external access integration to install packages from external package indexes like PyPI. Otherwise, they can only use the default, pre-installed packages. For more information, see 管理 Streamlit 应用程序的依赖项.
Add secrets to an existing warehouse-runtime app¶
To add secrets to an existing warehouse-runtime Streamlit app, run the ALTER STREAMLIT command as shown in the following example:
ALTER STREAMLIT my_app SET
EXTERNAL_ACCESS_INTEGRATIONS = (my_access_integration)
SECRETS = ('api_key' = my_database.my_schema.my_api_secret);
Secrets are only available in warehouse runtimes and must be associated with an external access integration. Container-runtime Streamlit apps must use SQL functions to access secrets. For more information, see 管理密钥并配置 Streamlit 应用程序.
Rename a Streamlit app¶
To rename a Streamlit app, run the ALTER STREAMLIT command as shown in the following example:
ALTER STREAMLIT old_app_name
RENAME TO new_app_name;
