About Streamlit in Snowflake¶
This topic describes how to use Streamlit in Snowflake to develop and run Streamlit applications.
About Streamlit in Snowflake¶
Streamlit is an open-source Python library that makes it easy to create and share custom web apps for machine learning and data science. By using Streamlit you can quickly build and deploy powerful data applications. For more information about the open-source library, see the Streamlit Library documentation.
Streamlit in Snowflake helps developers securely build, deploy, and share Streamlit apps on Snowflake’s data cloud. Using Streamlit in Snowflake, you can build applications that process and use data in Snowflake without moving data or application code to an external system.
Prerequisites for using Streamlit in Snowflake¶
To use Streamlit in Snowflake ensure that you have met the following prerequisites:
Review the limitations and unsupported features.
Acknowledge the External Offerings Terms. To use Mapbox in Streamlit in Snowflake, and the packages provided by Anaconda, you must acknowledge the External Offerings Terms. See Using Third-Party Packages from Anaconda for information on using these packages.
*.snowflake.appis allowlisted in your network and that the app is able to connect to Snowflake. See You cannot load the Streamlit app for more information.
Privileges required to create and use a Streamlit app¶
Within Streamlit in Snowflake, a Streamlit app is a securable object that adheres to the Snowflake access control framework. Streamlit apps use a permission model that is based on owner’s rights. See Understanding owner’s rights and Streamlit in Snowflake apps for details.
An app editor and the owner of the schema containing the Streamlit app can determine which roles have permission to use the app. Users can interact with the app and can see anything displayed by the Streamlit app. Users have the same view of the app as the owner does.
Refer to Share a Streamlit app for more information.
Privileges required to create a Streamlit app¶
Streamlit apps are schema-level objects.
To create and edit a Streamlit app by using Streamlit in Snowflake, you must use a role that has either the OWNERSHIP privilege on the schema, or both of the following privileges:
Granted on the database that contains the Streamlit app:
Granted on the schema that contains the Streamlit app:
Use the GRANT <privileges> command to grant these privileges to a role, as shown in the following examples:
GRANT USAGE ON SCHEMA streamlit_db.streamlit_schema TO ROLE streamlit_creator; GRANT USAGE ON DATABASE streamlit_db TO ROLE streamlit_creator; GRANT CREATE STREAMLIT ON SCHEMA streamlit_db.streamlit_schema TO ROLE streamlit_creator; GRANT CREATE STAGE ON SCHEMA streamlit_db.streamlit_schema TO ROLE streamlit_creator;
If a future grant is defined on database or schema, ensure that the user creates the Streamlit app using the role defined in the future grant.
Privileges required to view a Streamlit app¶
To view a Streamlit app, you must have a Snowflake account and be signed in. Additionally, you must use a role that is granted the USAGE privilege on the following:
The database that contains the Streamlit app.
The schema that contains the Streamlit app.
The Streamlit app.
In most cases, when the app owner shares a Streamlit app with another role, the USAGE privilege is automatically granted to the new role. However, if a Streamlit app is created in a schema with MANAGED ACCESS, the USAGE privilege must be manually granted to the new role.
The schema owner or a user with the role with the MANAGE GRANTS privilege must grant the USAGE privilege using the GRANT <privileges> command as shown in the following examples:
GRANT USAGE ON DATABASE streamlit_db TO ROLE streamlit_user;
GRANT USAGE ON SCHEMA streamlit_db.streamlit_schema TO ROLE streamlit_user;
GRANT USAGE on STREAMLIT streamlit_db.streamlit_schema.streamlit_app to ROLE streamlit_user;
Future grants are not supported for STREAMLIT objects.
Supported versions of the Streamlit library¶
Streamlit in Snowflake supports v1.22.0 of the Streamlit library. Support for later versions of the Streamlit library will be included as they are released.
Supported external packages¶
By default, Streamlit in Snowflake includes the
pre-installed in your environment. The environment also has access to the dependencies required by these packages.
Streamlit in Snowflake apps run in Python 3.8.
You can install additional packages in your Streamlit app. See the Snowflake Anaconda Channel for a list of supported packages.
See the following topics for information about including a supported package in your Streamlilt app:
Concurrency considerations for Streamlit in Snowflake¶
Streamlit in Snowflake provides session throttling and autoscaling within Snowflake to handle periods of increased demand for a Streamlit app. Streamlit in Snowflake uses a combination of cloud services instances and virtual warehouse instances. See Key Concepts & Architecture for more information.
To maintain the integrity of Snowflake, Streamlit in Snowflake imposes per-instance, per-account, and per-user limits on the number of concurrent Streamlit sessions that a Cloud Services instance can handle. Streamlit sessions are load-balanced between these instances until all instances reach their concurrent session limit. When a limit is reached, the instance is auto-scaled to support additional sessions.
Requests from Streamlit app users might be throttled temporarily. Users might see a “Please Wait” message when autoscaling is initiated.
Billing considerations for Streamlit in Snowflake¶
Streamlit in Snowflake requires a virtual warehouse to run a Streamlit app and to perform SQL queries. To run a Streamlit app, you must select a single virtual warehouse to run both the app itself and its queries. This warehouse remains active while the app’s WebSocket connection is active. The WebSocket connection, which keeps the Streamlit app’s virtual warehouse active, expires approximately 15 minutes after the app’s last use.
To conserve credits, you can suspend the virtual warehouse. Alternatively, you can close the webpage running the app, which allows the virtual warehouse that is running to auto-suspend.
Guidelines for selecting a warehouse in Streamlit in Snowflake¶
When you run a Streamlit app in Streamlit in Snowflake, multiple factors may affect performance, including the complexity of the Streamlit app, availability of warehouses, latency, and cost. The following sections provide general guidelines for using virtual warehouses in Streamlit in Snowflake.
Use smaller warehouses¶
When you run a Streamlit app in Streamlit in Snowflake you should select the smallest warehouse possible.
When running, a warehouse maintains a cache of the Python packages used by a Streamlit app. Caching Python packages improves the performance for later app loads by using the cached version of a package instead of downloading the packages again. The cache is removed when the warehouse is suspended, which may result in a slower loading of the app initially after the warehouse is resumed. As the resumed warehouse runs and runs more apps, the package cache is rebuilt, and apps that are able to take advantage of the cache will experience improved app loading performance.
Note that per-second credit billing and auto-suspend provide flexibility to start with smaller warehouses, then adjust the size of the warehouse to match the workload of the Streamlit app. You can increase the size of a warehouse at any time. See Change the warehouse of a Streamlit app for more information.
Use dedicated warehouses¶
When you use Streamlit in Snowflake, Snowflake recommends using a dedicated warehouses for running Streamlit apps. This enables you to isolate the costs of running a Streamlit apps. A dedicated warehouse may also improve the load time of the app since the warehouse does not have to manage other workloads.
See Warehouse Considerations for more information.
To avoid warehouse suspension during initialization, consider setting auto-suspend to a minimum of 30 seconds.