CREATE STREAMLIT

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

See also:

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

Syntax

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

The following syntax is legacy:

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> [ , ... ] ) ]
Copy

Required parameters

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.

For more details, see Identifier requirements.

Optional parameters

FROM source_location

Copies the app source files from the specified location. The location must be within an internal named stage. The path can be relative or fully qualified. For example, if the stage is named @streamlit_db.streamlit_schema.streamlit_stage, valid source locations can include:

  • A fully qualified path to the root of the stage: FROM '@streamlit_db.streamlit_schema.streamlit_stage'

  • A relative path to the root of the stage: FROM '@streamlit_stage'

  • A fully qualified or relative path to a subdirectory within the stage: FROM '@streamlit_db.streamlit_schema.streamlit_stage/subdir'

Files are copied only one time when the CREATE command is executed; future changes to the source location don’t automatically update the Streamlit app.

If this parameter isn’t specified, Snowflake copies the source files for a default app with a streamlit_app.py entrypoint file.

MAIN_FILE = 'filename'

The filename of the Streamlit entrypoint file. This file must be in the root of the source directory specified in FROM.

If you are using ROOT_LOCATION instead of FROM, then MAIN_FILE can be a path relative to ROOT_LOCATION.

DEFAULT: 'streamlit_app.py'

QUERY_WAREHOUSE = warehouse_name

Specifies the warehouse to run the app and execute SQL queries issued by the Streamlit app.

DEFAULT: No value

Note

Although you can create a Streamlit object without this parameter, the app won’t run until you specify a query warehouse.

COMMENT = 'string_literal'

Specifies a comment for the Streamlit object.

DEFAULT: No value

TITLE = 'app_title'

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

DEFAULT: The name of the Streamlit object passed to CREATE STREAMLIT.

IMPORTS = ( 'stage_path_and_file_name_to_read' [ , ... ] )

The location (stage), path, and name of the file(s) to import.

EXTERNAL_ACCESS_INTEGRATIONS = ( integration_name [ , ... ] )

The names of external access integrations needed in order for the Streamlit app code to access external networks.

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

In this example, the Streamlit files are located on a named stage named streamlit_stage within a database named streamlit_db and schema named streamlit_schema.

Note

  • This parameter must point to a single directory inside a named internal stage.

  • External stages are not supported for Streamlit in Snowflake.

  • If you’re creating or replacing a Streamlit application object within the Snowflake Native App Framework, use FROM 'relative_path_from_stage_root_directory' and not ROOT_LOCATION = 'stage_path_and_root_directory'.

Access control requirements

If your role does not own the objects in the following table, then your role must have the listed privileges on those objects:

Privilege

Object

Notes

CREATE STREAMLIT

Schema where you create the Streamlit object

READ

Stage from which you copy the Streamlit app source files

CREATE STAGE

Schema where you create the Streamlit object

This privilege is only required to create Streamlit objects with the ROOT_LOCATION parameter.

The USAGE privilege on the parent database and schema are required to perform operations on any object in a schema. Note that a role granted any privilege on a schema allows that role to resolve the schema. For example, a role granted CREATE privilege on a schema can create objects on that schema without also having USAGE granted on that schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Usage notes

  • You must initialize the app after creating it.

    Important

    After you use CREATE STREAMLIT, the Streamlit app isn’t live until you do one of the following actions:

    • Execute ALTER STREAMLIT … ADD LIVE VERSION FROM LAST on the new Streamlit object.

    • Visit the app in Snowsight with the role that owns the app.

  • When you clone a schema or database containing a Streamlit object, the Streamlit object is not cloned.

  • To specify the packages used by the Streamlit application, use an environment.yml file.

  • Regarding metadata:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in 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 <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

Examples

To create a Streamlit app from a stage, 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

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
Language: English