CREATE STREAMLIT

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

Consulte também:

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

Sintaxe

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

A sintaxe a seguir é herdada:

Importante

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

Parâmetros obrigatórios

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.

Para obter mais detalhes, consulte Requisitos para identificadores.

Parâmetros opcionais

FROM source_location

Copia os arquivos de origem do aplicativo do local especificado. O local deve estar dentro de um estágio nomeado interno. O caminho pode ser relativo ou totalmente qualificado. Por exemplo, se o estágio for nomeado @streamlit_db.streamlit_schema.streamlit_stage, os locais de origem válidos podem incluir:

  • Um caminho totalmente qualificado para a raiz do estágio: FROM '@streamlit_db.streamlit_schema.streamlit_stage'

  • Um caminho relativo para a raiz do estágio: FROM '@streamlit_stage'

  • Um caminho totalmente qualificado ou relativo para um subdiretório dentro do estágio: FROM '@streamlit_db.streamlit_schema.streamlit_stage/subdir'

Os arquivos são copiados apenas uma vez quando o CREATE o comando é executado; Alterações futuras no local de origem não atualizam automaticamente o aplicativo Streamlit.

Se esse parâmetro não for especificado, o Snowflake copiará os arquivos de origem para um aplicativo padrão com um streamlit_app.py Arquivo de ponto de entrada.

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: sem valor

Nota

Embora você possa criar um objeto Streamlit sem esse parâmetro, o aplicativo não será executado até que você especifique um warehouse de consultas.

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: sem valor

COMMENT = 'string_literal'

Especifica um comentário para o objeto Streamlit.

DEFAULT: sem valor

TITLE = 'app_title'

Specifies a title for the Streamlit object to display in Snowsight.

DEFAULT: O nome do objeto Streamlit passado para CREATE 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: sem valor

EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )

Os nomes das integrações de acesso externo necessárias para que o código do aplicativo Streamlit acesse redes externas.

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: sem valor

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: sem valor

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

Neste exemplo, os arquivos Streamlit estão localizados em um estágio nomeado denominado streamlit_stage em um banco de dados denominado streamlit_db e esquema denominado streamlit_schema.

Nota

  • Este parâmetro deve apontar para um único diretório dentro de um estágio interno nomeado.

  • Estágios externos não são suportados pelo Streamlit in Snowflake.

  • Se você estiver criando ou substituindo um objeto de aplicativo Streamlit dentro do Snowflake Native App Framework, use FROM 'relative_path_from_stage_root_directory' em vez de ROOT_LOCATION = 'stage_path_and_root_directory'.

Requisitos de controle de acesso

Se sua função não possuir os objetos na tabela a seguir, sua função deverá ter os privilégios listados sobre esses objetos:

Privilégio

Objeto

Notes

CREATE STREAMLIT

Schema where you create the Streamlit object

READ

Estágio de onde você copia os arquivos de origem do aplicativo 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

Este privilégio só é necessário para criar objetos Streamlit com o ROOT_LOCATION Parâmetro.

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.

Para instruções sobre como criar uma função personalizada com um conjunto específico de privilégios, consulte Criação de funções personalizadas.

Para informações gerais sobre concessões de funções e privilégios para executar ações de SQL em objetos protegíveis, consulte Visão geral do controle de acesso.

Notas de uso

  • Você deve inicializar o aplicativo após criá-lo.

    Importante

    Depois de usar a CREATE STREAMLIT, o aplicativo Streamlit não estará ativo até que você execute uma das seguintes ações:

    • Executar ALTER STREAMLIT … ADD LIVE VERSION FROM LAST no novo objeto Streamlit.

    • Acesse o aplicativo em Snowsight com a função proprietária do aplicativo.

  • Quando você clona um esquema ou banco de dados contendo um objeto Streamlit, o objeto Streamlit não é clonado.

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

  • Em relação aos metadados:

    Atenção

    Os clientes devem garantir que nenhum dado pessoal (exceto para um objeto do usuário), dados sensíveis, dados controlados por exportação ou outros dados regulamentados sejam inseridos como metadados ao usar o serviço Snowflake. Para obter mais informações, consulte Campos de metadados no Snowflake.

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

  • Instruções CREATE OR REPLACE <object> são atômicas. Ou seja, quando um objeto é substituído, o objeto antigo é excluído e o novo objeto é criado em uma única transação.

Exemplos

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