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 という名前付きステージにあります。

注釈

  • このパラメーターは、名前付き内部ステージ内の1つのディレクトリをポイントする必要があります。

  • Streamlit in Snowflake 用外部ステージはサポートされていません。

  • Snowflake Native App Framework 内で Streamlit アプリケーションオブジェクトを作成または交換する場合は、 ROOT_LOCATION = 'stage_path_and_root_directory' ではなく FROM 'relative_path_from_stage_root_directory' を使用してください。

アクセス制御の要件

ロールが以下の表にあるオブジェクトを所有していない場合、ロールはそれらのオブジェクトに対して次の 権限 を持つ必要があります。

権限

オブジェクト

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 を実行する。

    • アプリを所有するロールを使用して、 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.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