CREATE STREAMLIT¶
在 Snowflake 中创建新的 Streamlit 对象或替换同一架构中的现有 Streamlit 对象。
语法¶
以下语法是传统语法:
重要
ROOT_LOCATION is a legacy parameter and may be deprecated in a future release.
For container runtimes, ROOT_LOCATION is not supported.
For Streamlit apps created using ROOT_LOCATION, multi-file editing and Git integration are not supported.
必填参数¶
name指定 Streamlit 对象的标识符(即名称)。此标识符对于在其中创建对象的架构必须是唯一的。
此外,标识符必须以字母字符开头,且不能包含空格或特殊字符,除非整个标识符字符串放在双引号内(例如,
"My object")。放在双引号内的标识符也区分大小写。有关更多详细信息,请参阅 标识符要求。
可选参数¶
FROM source_location从指定位置复制应用程序源文件。该位置必须位于内部命名暂存区内。路径可以是相对的,也可以是完全限定的。例如,如果将暂存区命名为
@streamlit_db.streamlit_schema.streamlit_stage,则有效的源位置可以包括:根暂存区的完全限定路径:
FROM '@streamlit_db.streamlit_schema.streamlit_stage'根暂存区的相对路径:
FROM '@streamlit_stage'暂存区内子目录的完全限定路径或相对路径:
FROM '@streamlit_db.streamlit_schema.streamlit_stage/subdir'
执行 CREATE 命令时文件仅复制一次;将来对源位置的更改不会自动更新 Streamlit 应用程序。
如果未指定此参数,Snowflake 会使用
streamlit_app.py入口点文件复制默认应用程序的源文件。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 you are using ROOT_LOCATION instead of FROM, then MAIN_FILE can be a path relative to ROOT_LOCATION even though ROOT_LOCATION only supports warehouse runtimes.
DEFAULT:
'streamlit_app.py'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.
DEFAULT:无值
备注
尽管您可以创建不带此参数的 Streamlit 对象,但在您指定查询仓库之前,该应用程序不会运行。
RUNTIME_NAME = 'runtime_name'Specifies the runtime environment for the Streamlit app. The runtime determines where and how the app executes.
Warehouse runtime: Run the app in a virtual warehouse. Each viewer gets a personal instance of the app. Use
SYSTEM$WAREHOUSE_RUNTIME. The Python version is selected separately using theenvironment.ymlfile.Container runtimes: Run the app in a Snowpark Container Services compute pool. All viewers share a single, long-running instance of the app. Container runtime names include the Python version. The following container runtimes are valid:
SYSTEM$ST_CONTAINER_RUNTIME_PY3_11
The runtime defaults to the warehouse runtime.
DEFAULT:
SYSTEM$WAREHOUSE_RUNTIMECOMPUTE_POOL = compute_pool_nameSpecifies the compute pool where the Streamlit app runs. This parameter is used only with container runtimes and is ignored for warehouse runtimes.
If you omit this parameter when using a container runtime, Snowflake uses the compute pool specified by the DEFAULT_STREAMLIT_COMPUTE_POOL parameter. If the DEFAULT_STREAMLIT_COMPUTE_POOL parameter is updated after the Streamlit app is created, it won't affect the compute pool used by the app.
DEFAULT: The compute pool specified by the DEFAULT_STREAMLIT_COMPUTE_POOL account parameter.
COMMENT = 'string_literal'指定 Streamlit 对象的注释。
DEFAULT:无值
TITLE = 'app_title'为 Streamlit 对象指定要在 Snowsight 中显示的标题。
DEFAULT:选择使用 时默认使用的角色和仓库。传递给 CREATE STREAMLIT 的 Streamlit 对象的名称。
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.
DEFAULT:无值
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.
DEFAULT:无值
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)In warehouse runtimes, secrets are accessed through the
_snowflakemodule. In container runtimes, secrets are accessible throughst.secretsand are also mapped to environment variables. Secrets must be associated with an external access integration in EXTERNAL_ACCESS_INTEGRATIONS. For more information, see 管理密钥并配置 Streamlit 应用程序.DEFAULT:无值
ROOT_LOCATION = 'stage_path_and_root_directory'指定包含 Streamlit Python 文件、媒体文件和
environment.yml文件的命名暂存区的路径,例如:在此示例中,Streamlit 文件位于名为
streamlit_stage的命名暂存区上,而该暂存区在名为streamlit_db的数据库和名为streamlit_schema的架构中。备注
此参数必须指向已命名内部暂存区内的单个目录。
Streamlit in Snowflake 不支持外部暂存区。
如果要在 Snowflake Native App Framework 中创建或替换 Streamlit 应用程序对象,请使用
FROM 'relative_path_from_stage_root_directory'而非ROOT_LOCATION = 'stage_path_and_root_directory'。
访问控制要求¶
如果您的角色没有下表中的对象,则您的角色必须对这些对象具备列出的 权限:
权限 |
对象 |
备注 |
|---|---|---|
CREATE STREAMLIT |
创建 Streamlit 对象的架构 |
|
READ |
要从中复制 Streamlit 应用程序源文件的暂存区 |
|
USAGE |
Warehouse used by the Streamlit app |
|
USAGE |
Compute pool used by the Streamlit app |
This privilege is only required if your app uses a container runtime. |
USAGE |
External access integrations used by the Streamlit app |
This privilege is only required if your app uses external access integrations. For container runtimes, this privilege is required to install packages from external package indexes like PyPI. |
USAGE |
Secrets used by the Streamlit app |
This privilege is only required if your app uses secrets and only applies to warehouse runtimes. |
CREATE STAGE |
创建 Streamlit 对象的架构 |
只有使用 ROOT_LOCATION 参数创建 Streamlit 对象时才需要此权限。 |
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.
有关创建具有指定权限集的自定义角色的说明,请参阅 创建自定义角色。
使用说明¶
创建应用程序后,必须对其进行初始化。
重要
使用 CREATE STREAMLIT 后,Streamlit 应用程序只有在您执行以下任一操作后才能上线:
对新的 Streamlit 对象执行 ALTER STREAMLIT ... ADD LIVE VERSION FROM LAST。
使用拥有应用程序的角色访问 Snowsight 中的应用程序。
在克隆包含 Streamlit 对象的架构或数据库时,不会克隆 Streamlit 对象。
To specify the packages used by the Streamlit application, include a dependency file in the source files. The format of the dependency file depends on the runtime type:
Warehouse runtime: Use an
environment.ymlfile.Container runtime: Use a
pyproject.tomlorrequirements.txtfile.
For more information, see 管理 Streamlit 应用程序的依赖项.
关于元数据:
注意
客户应确保在使用 Snowflake 服务时,不会将个人数据(用户对象除外)、敏感数据、出口管制数据或其他受监管数据作为元数据输入。有关更多信息,请参阅 Snowflake 中的元数据字段。
OR REPLACE 和 IF NOT EXISTS 子句互斥。它们不能同时用于同一条语句中。
CREATE OR REPLACE <object> 语句是原子的。也就是说,当对象被替换时,旧对象将被删除,新对象将在单个事务中创建。
示例¶
Create a Streamlit app with default source files¶
To create a container-runtime Streamlit app from built-in default files, run the CREATE STREAMLIT command as shown in the following example:
By default, apps use the latest warehouse runtime if RUNTIME_NAME isn't specified. To create a warehouse-runtime Streamlit app from built-in default files, run the CREATE STREAMLIT command as shown in the following example:
Create a Streamlit app from a custom source files¶
To create a container-runtime Streamlit app from custom source files, run the CREATE STREAMLIT command as shown in the following example:
To create a warehouse-runtime Streamlit app from custom source files, run the CREATE STREAMLIT command as shown in the following example:
Create a warehouse-runtime Streamlit app with secrets¶
To create a warehouse-runtime Streamlit app with secrets, run the CREATE STREAMLIT command as shown in the following example:
For container-runtime apps, secrets are accessible through st.secrets and as environment variables.
For more information, see 管理密钥并配置 Streamlit 应用程序.
Create a Streamlit app from a Git repository¶
To create a Streamlit app from a Git repository, run the CREATE STREAMLIT command as shown in the following example:
