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.
Accept the Anaconda terms of service. To use Streamlit in Snowflake and the packages provided by Snowflake in Anaconda, you must acknowledge the Snowflake Third-Party Terms. See Using Third-Party Packages from Anaconda for information on using these packages.
Configure your firewall to allow traffic from
*.snowflake.app. See Firewall allowlisting 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.
The following sections describe the privileges required to create and view a Streamlit app in Snowflake.
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 the following privileges granted on the schema and database that contain 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 mydb.myschema TO ROLE myrole; GRANT USAGE ON DATABASE mydb TO ROLE myrole; GRANT CREATE STREAMLIT ON SCHEMA mydb.myschema TO ROLE myrole; GRANT CREATE STAGE ON SCHEMA mydb.myschema TO ROLE myrole;
Privileges required to view a Streamlit app¶
To view a Streamlit app, a user must have a Snowflake account and be signed in.
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 Sharing a Streamlit app for more information.
Supported versions of the Streamlit libraries¶
Streamlit in Snowflake supports v1.22.0 of the Streamlit libraries. Support for later versions of the Streamlit libraries 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.
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¶
Resources are required to run the Streamlit app and to run the app’s queries. You must choose a virtual warehouse that runs both. This warehouse remains active while the app’s web-socket connection is active. The web-socket connection expires approximately 15 minutes after its last use.
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 Changing 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.