CREATE STREAMLIT

Creates a new Streamlit object in Snowflake or replaces an existing Streamlit object in the same schema.

참고 항목:

SHOW STREAMLITS, DESCRIBE STREAMLIT, ALTER STREAMLIT, DROP STREAMLIT, UNDROP STREAMLIT

구문

CREATE [ OR REPLACE ] STREAMLIT [ IF NOT EXISTS ] <name>
  [ FROM <source_location> ]
  [ 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> [ , ... ] ) ]
Copy

다음 구문은 레거시입니다.

중요

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.

CREATE [ OR REPLACE ] STREAMLIT [ IF NOT EXISTS ] <name>
  ROOT_LOCATION = '<stage_path_and_root_directory>'
  MAIN_FILE = '<path_to_main_file_in_root_directory>'
  [ QUERY_WAREHOUSE = <warehouse_name> ]
  [ COMMENT = '<string_literal>' ]
  [ TITLE = '<app_title>' ]
  [ IMPORTS = ( '<stage_path_and_file_name_to_read>' [ , ... ] ) ]
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <integration_name> [ , ... ] ) ]
Copy

필수 매개 변수

name

Specifies the identifier (i.e. name) for the Streamlit object. This identifier must be unique for the schema where the object is created.

In addition, the identifier must start with an alphabetic character and can’t contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive.

자세한 내용은 식별자 요구 사항 섹션을 참조하십시오.

선택적 매개 변수

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_name

Specifies 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. 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_9

    • SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_10

    • SYSTEM$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

The runtime defaults to the latest warehouse runtime.

DEFAULT: SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_11

COMPUTE_POOL = compute_pool_name

Specifies the compute pool where the Streamlit app runs. This parameter is required when using a container runtime and is ignored for warehouse runtimes.

DEFAULT: 값 없음

COMMENT = 'string_literal'

Streamlit 오브젝트에 대한 설명을 명시합니다.

DEFAULT: 값 없음

TITLE = 'app_title'

Specifies a title for the Streamlit object to display in 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)

Secrets are only available in warehouse runtimes through the _snowflake module 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 Manage secrets and configure your Streamlit app.

DEFAULT: 값 없음

ROOT_LOCATION = 'stage_path_and_root_directory'

Specifies the path to the named stage containing the Streamlit Python files, media files, and the environment.yml file, for example:

ROOT_LOCATION = '@streamlit_db.streamlit_schema.streamlit_stage'
Copy

이 예에서 Streamlit 파일은 streamlit_db 라는 데이터베이스와 streamlit_schema 라는 스키마 내의 streamlit_stage 로 명명된 스테이지에 있습니다.

참고

  • 이 매개 변수는 명명된 내부 스테이지 내의 단일 디렉터리를 가리켜야 합니다.

  • Streamlit in Snowflake 에 대한 외부 스테이지는 지원되지 않습니다.

  • Snowflake Native App Framework 내에서 Streamlit 애플리케이션 오브젝트를 만들거나 바꾸는 경우 ROOT_LOCATION = 'stage_path_and_root_directory' 가 아닌 FROM 'relative_path_from_stage_root_directory' 를 사용하십시오.

액세스 제어 요구 사항

역할이 다음 테이블의 오브젝트를 소유하지 않는 경우 역할에 해당 오브젝트에 대한 나열된 :ref:`권한<label-access_control_overview_privileges>`이 있어야 합니다.

권한

오브젝트

Notes

CREATE STREAMLIT

Schema where you create the Streamlit object

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

Schema where you create the Streamlit object

이 권한은 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.

지정된 권한 세트로 사용자 지정 역할을 만드는 방법에 대한 지침은 사용자 지정 역할 만들기 섹션을 참조하십시오.

보안 오브젝트 에 대해 SQL 작업을 수행하기 위한 역할과 권한 부여에 대한 일반적인 정보는 액세스 제어의 개요 섹션을 참조하십시오.

사용법 노트

  • 앱을 만든 후에는 초기화해야 합니다.

    중요

    CREATE STREAMLIT를 사용한 후 Streamlit 앱은 다음 작업 중 하나를 수행할 때까지 활성화되지 않습니다.

    • 새 Streamlit 오브젝트에 대해 ALTER STREAMLIT … ADD LIVE VERSION FROM LAST를 실행합니다.

    • 앱을 소유한 역할을 사용하여 |sf-web-interface|에서 앱을 방문합니다.

  • 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.yml file.

    • Container runtime: Use a pyproject.toml or requirements.txt file.

    For more information, see Manage dependencies for your Streamlit app.

  • 메타데이터 관련:

    주의

    고객은 Snowflake 서비스를 사용할 때 개인 데이터(사용자 오브젝트 제외), 민감한 데이터, 수출 통제 대상 데이터 또는 기타 규제 데이터가 메타데이터로 입력되지 않도록 해야 합니다. 자세한 내용은 Snowflake의 메타데이터 필드 섹션을 참조하십시오.

  • The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.

  • CREATE OR REPLACE <오브젝트> 문은 원자성입니다. 즉, 오브젝트가 바뀔 때 단일 트랜잭션으로 이전 오브젝트가 삭제되고 새 오브젝트가 생성됩니다.

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:

CREATE STREAMLIT hello_streamlit
  RUNTIME_NAME = 'SYSTEM$ST_CONTAINER_RUNTIME_PY3_11'
  COMPUTE_POOL = my_compute_pool
  QUERY_WAREHOUSE = my_warehouse;
Copy

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 STREAMLIT hello_streamlit
  QUERY_WAREHOUSE = my_warehouse;
Copy

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:

CREATE STREAMLIT hello_streamlit
  FROM @streamlit_db.streamlit_schema.streamlit_stage
  MAIN_FILE = 'streamlit_main.py'
  QUERY_WAREHOUSE = my_warehouse
  RUNTIME_NAME = 'SYSTEM$ST_CONTAINER_RUNTIME_PY3_11'
  COMPUTE_POOL = my_compute_pool;
Copy

To create a warehouse-runtime Streamlit app from custom source files, run the CREATE STREAMLIT command as shown in the following example:

CREATE STREAMLIT hello_streamlit
  FROM @streamlit_db.streamlit_schema.streamlit_stage
  MAIN_FILE = 'streamlit_main.py'
  QUERY_WAREHOUSE = my_warehouse;
Copy

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:

CREATE STREAMLIT hello_streamlit
  FROM @streamlit_db.streamlit_schema.streamlit_stage
  MAIN_FILE = 'streamlit_main.py'
  QUERY_WAREHOUSE = my_warehouse
  SECRETS = ('api_key' = streamlit_db.streamlit_schema.my_api_secret);
Copy

Container-runtime Streamlit apps must use SQL functions to access secrets. For more information, see Manage secrets and configure your Streamlit app.

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:

CREATE STREAMLIT hello_streamlit
  FROM @streamlit_db.streamlit_schema.streamlit_repo/branches/streamlit_branch/
  MAIN_FILE = 'streamlit_main.py'
  QUERY_WAREHOUSE = my_warehouse;
Copy