CREATE STREAMLIT¶
Creates a new Streamlit object in Snowflake or replaces an existing Streamlit object in the same schema.
- Voir aussi :
SHOW STREAMLITS, DESCRIBE STREAMLIT, ALTER STREAMLIT, DROP STREAMLIT, UNDROP STREAMLIT
Syntaxe¶
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> [ , ... ] ) ]
La syntaxe suivante est héritée :
Important
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> [ , ... ] ) ]
Paramètres requis¶
nameSpecifies 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.Pour plus de détails, voir Exigences relatives à l’identificateur.
Paramètres facultatifs¶
FROM source_locationCopie les fichiers sources de l’application à partir de l’emplacement spécifié. L’emplacement doit se trouver dans une zone de préparation interne nommée. Le chemin peut être relatif ou entièrement qualifié. Par exemple, si la zone de préparation est nommée
@streamlit_db.streamlit_schema.streamlit_stage, les emplacements sources valides peuvent inclure :Un chemin d’accès complet à la racine de la zone de préparation :
FROM '@streamlit_db.streamlit_schema.streamlit_stage'Un chemin d’accès relatif à la racine de la zone de préparation :
FROM '@streamlit_stage'Un chemin relatif ou complet vers un sous-répertoire de la zone de préparation :
FROM '@streamlit_db.streamlit_schema.streamlit_stage/subdir'
Les fichiers sont copiés une seule fois lorsque la commande CREATE est exécutée ; les modifications ultérieures de l’emplacement source ne mettent pas automatiquement à jour l’application Streamlit.
Si ce paramètre n’est pas spécifié, Snowflake copie les fichiers sources d’une application par défaut avec un fichier de point d’entrée
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 : aucune valeur
Note
Bien que vous puissiez créer un objet Streamlit sans ce paramètre, l’application ne s’exécutera pas tant que vous n’aurez pas spécifié un entrepôt de requêtes.
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_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
The runtime defaults to the latest warehouse runtime.
DEFAULT:
SYSTEM$ST_WAREHOUSE_RUNTIME_PY3_11COMPUTE_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.
DEFAULT : aucune valeur
COMMENT = 'string_literal'Spécifie un commentaire pour l’objet Streamlit.
DEFAULT : aucune valeur
TITLE = 'app_title'Specifies a title for the Streamlit object to display in Snowsight.
DEFAULT : Nom de l’objet Streamlit transmis à 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 : aucune valeur
EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )Les noms des intégrations d’accès externe nécessaires pour que le code de l’application Streamlit puisse accéder aux réseaux externes.
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 : aucune valeur
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 Manage secrets and configure your Streamlit app.DEFAULT : aucune valeur
ROOT_LOCATION = 'stage_path_and_root_directory'Specifies the path to the named stage containing the Streamlit Python files, media files, and the
environment.ymlfile, for example:ROOT_LOCATION = '@streamlit_db.streamlit_schema.streamlit_stage'
Dans cet exemple, les fichiers Streamlit sont situés sur une zone de préparation nommée
streamlit_stageau sein d’une base de données nomméestreamlit_dbet d’un schéma nomméstreamlit_schema.Note
Ce paramètre doit pointer vers un répertoire unique à l’intérieur d’une zone de préparation interne nommée.
Les zones de préparation externes ne sont pas prises en charge pour Streamlit in Snowflake.
Si vous créez ou remplacez un objet d’application Streamlit dans Snowflake Native App Framework, utilisez
FROM 'relative_path_from_stage_root_directory'et nonROOT_LOCATION = 'stage_path_and_root_directory'.
Exigences en matière de contrôle d’accès¶
Si votre rôle ne possède pas les objets de la table suivante, votre rôle doit disposer des privilèges répertoriés sur ces objets :
Privilège |
Objet |
Notes |
|---|---|---|
CREATE STREAMLIT |
Schema where you create the Streamlit object |
|
READ |
Zone de préparation à partir de laquelle vous copiez les fichiers sources de l’application 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 |
Ce privilège n’est requis que pour créer des objets Streamlit avec le paramètre ROOT_LOCATION. |
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.
Pour obtenir des instructions sur la création d’un rôle personnalisé avec un ensemble spécifique de privilèges, voir Création de rôles personnalisés.
Pour des informations générales sur les rôles et les privilèges accordés pour effectuer des actions SQL sur des objets sécurisables, voir Aperçu du contrôle d’accès.
Notes sur l’utilisation¶
Vous devez initialiser l’application après l’avoir créée.
Important
Après avoir utilisé CREATE STREAMLIT, l’application Streamlit n’est pas active tant que vous n’avez pas effectué l’une des actions suivantes :
Exécutez ALTER STREAMLIT … ADD LIVE VERSION FROM LAST sur le nouvel objet Streamlit.
Consultez l’application dans Snowsight avec le rôle qui possède l’application.
Lorsque vous clonez un schéma ou une base de données contenant un objet Streamlit, l’objet Streamlit n’est pas cloné.
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 Manage dependencies for your Streamlit app.
Concernant les métadonnées :
Attention
Les clients doivent s’assurer qu’aucune donnée personnelle (autre que pour un objet utilisateur), donnée sensible, donnée à exportation contrôlée ou autre donnée réglementée n’est saisie comme métadonnée lors de l’utilisation du service Snowflake. Pour plus d’informations, voir Champs de métadonnées dans Snowflake.
The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement.
Les instructions CREATE OR REPLACE <objet> sont atomiques. En d’autres termes, lorsqu’un objet est remplacé, l’ancien objet est supprimé et le nouvel objet est créé dans une seule transaction.
Exemples¶
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;
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;
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;
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;
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);
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;
