In March 2022, Snowflake acquired Streamlit, creators of a Python library for crafting sleek web apps. At Summit 2022, Snowflake introduced Native Apps, enabling users to monetize their creations directly within the Snowflake Marketplace. By June 2023, the Native App Framework launched its public preview on AWS, opening the door for thousands to harness these potent features.
These considerable investments of time and resources are a testament to Snowflake’s strategic goal of enabling users to build, deploy, and use apps without leaving its platform. These Native Apps can be defined as bundling code, data, and Snowflake objects, using a wide array of core Snowflake functionality – including Streamlit, Snowpark, and many others – along the way.
The Aimpoint Digital team has been closely tracking these releases & experimenting with these new features. We are excited to share a series of technical blogs detailing how to utilize these features effectively and the best practices for seamless app deployment.
In this blog post, we will dive into the basics of deploying Streamlit apps within the Snowflake Native Apps Framework.
Understanding Snowflake and Streamlit: Key Concepts
Before we get into the nitty-gritty details, let’s recap the key concepts and how they fit together.
A Streamlit application refers to an interface built using the Python Streamlit library. This library makes it supremely easy to connect to data and create interactive dashboards, machine learning and predictive analytics models, or data-processing functionality with a slick UI.
A Streamlit app can also be built and run locally on your machine – it is not a purely Snowflake native feature. Snowflake is introducing a separate Streamlit in Snowflake (or SiS) feature that will allow users to quickly build web apps directly into the UI – these are separate from Native Apps and are designed to be used by users within their own Snowflake account.
The standalone Streamlit apps are currently in private preview.
The Snowflake Native App Framework refers to the set of capabilities one can use & rules one must follow when creating a Native App that can be shared with consumer accounts.
Native Apps can include various Snowflake features, including stored procedures, Snowpark, or Streamlit. Once the code & files that comprise an app are ready, they are packaged up into an Application Package from which the Native App is installed.
The Native Apps Framework is built around the concept of Providers and Consumers, similar to data shares:
- Providers create the application and make its Application Package available on the marketplace or through private listing,
- Consumers install the application from a listing and run it inside their own Snowflake instance.
With this high-level architecture in mind, let us now delve into the detail of creating & deploying a simple Streamlit interface into a Native App using the Native Apps Framework.
Comprehensive Guide to Deploying Streamlit on Snowflake
To deploy a Streamlit interface in a Snowflake Native App, one must follow the following steps:
- Create & prepare the Application files locally on your machine.
- Create & prepare an Application Package in Snowflake in the following order:
- Create an Application Package object
- Add files to a stage in the Application Package
- Release a new version of the Application Package
Create an Application From the Application Package
In this guide, we will leverage the Snowsight UI functionality as much as possible – but keep in mind that all these deployment & configuration steps can be done directly using a combination of SQL commands and basic scripting.
Create and Prepare the Application Files
The Native Apps Framework requires an application to contain a specific set of files. We will be using our Manual Data Entry app as an example and highlighting which bits of code you will have to update to set things up correctly with your application:
- This is the file that is run when the app is created.
- A key part of the setup scripts involves creating the Application role, which is the role that the application uses to execute commands and granting access to the objects needed to run this application to the Application role.
When building your own setup script, you should pick an APPLICATION ROLE, SCHEMA, and specific Streamlit app name that is relevant to your application.
Make sure also to update the MAIN_FILE path to match the name of your Streamlit Python file.
- This is a YML file with the basic configuration of the application.
- This file must include the manifest_verison, artifacts, and setup_script properties.
- Please note that it is currently not possible to add custom fields to the manifest file in case you were hoping to leverage the file to perform additional configuration.
- A file containing a description of the application.
- This file will act as the front-page users first see when they access the app, so make sure to take the time to prepare a nice introduction for them!
- Make sure you reference the correct readme file name & path in the manifest file in the artifacts section.
We also recommend being aware of the following file:
- This file should be used if you use libraries within your application files, specifically if you are working with Python.
- For example, if you use the Snowflake.permission library within your Streamlit application, you must include this file and specify this in your dependencies.
- These files contain your application’s logic (Streamlit app, Snowpark code, etc.)
- If you are creating a Streamlit application, make sure to specify the name & path of the main file to be used in your CREATE STREAMLIT statement in the setup script.
- If your Streamlit application references other files – such as utility files containing Python functions – make sure to organize your files in the following way:
- A main Python file that you reference in the setup script
- A zipped folder that contains all the additional files that are referenced in your main file.
As a last point, the Native Apps Framework will expect a specific file structure when these files are added to the application package:
- A root folder containing the manifest and readme files
- A script folder containing the setup file
- A Streamlit folder (if relevant) with the main streamlit app file & the .zip containing the other dependencies, as well as the environment.yml file.
Create and Prepare an Application Package
With these files prepared, we are ready to build our Application Package in Snowflake. We will do this in 3 steps:
First, we will create our Application Package:
- The application package will appear as a separate Snowflake object. It is at the same level as a database object in the object hierarchy and will appear alongside them.
- Once the package is created, we will create a stage to host our application files.
- Make sure you have granted permission to create application packages for the role you will be using. By default, only the ACCOUNTADMIN role has this privilege.
After completing these steps, you should see the following objects inside of your Snowflake instance:
With the stage ready, we can now add our files to the stage. Start by navigating to the stage you have just created.
Hit the big blue “+ Files” button in the top right corner to add files. We recommend enabling directory tables to view your files – the option will be in the middle of your screen.
In the pop-up window that appears, start adding your files. You can drag and drop the files directly into the box or hit browse to use your file explorer.
Bring in all the files that are meant to live in the same directory together:
- Manifest.yml & readme.md in the root directory,
- Environment.yml, main Streamlit python files, and any supporting zipped files in the Streamlit folder
- Setup.sql in the scripts folder
You can type the names of the folders in the “Specify path…” text box.
Once all the files have been added, your application package should look like this:
Finally, now that the application package is ready, we can now deploy a new version of our application.
- This step is not required if you run your application in debug mode; however, for a true production release and one that one can share through a listing, you must do a proper version release.
To do this through the UI, navigate to the Apps objects and click on Packages in the top section.
- Click on your application package, and you should be greeted with an “Add first version” button.
- Once you click on it, a pop-up window should appear, asking you to specify details about your release.
Fill out the required details, and make sure to indicate the path to your application files:
- In our example, the files are in the root folder. However, you could also use a version-specific file path where you reference the folder containing the version of the files you would like to use. This allows you to keep multiple versions of the same app within one stage and makes continuous deployment of updates smooth.
Once you hit publish, you should be greeted with the following screen.
You have now successfully completed creating an application package built using the Snowflake Native Application framework.
Create an Application from the Application Package
Now that your application package has been successfully created, you can:
- Create a listing that will enable users in other Snowflake accounts to install and utilize the app as consumers,
- Install the app in your own Snowflake instance to enable your users to benefit from it!
This guide will show how to create an app in your account. We will dedicate a future blog to best practices around creating listings for the marketplace.
First, to create an Application from an Application Package, make sure you have granted the following privileges to the role you will be using:
- Installing the application is extremely easy once you have been granted the correct privileges.
- We recommend specifying the specific version or patch number when doing the installation.
- The version and/or patch number depend on the one you defined when you released the Application Package version at the end of the last section.
Alternatively, you can specify the location of the stage where the application package is located:
- This is particularly relevant when working in debug mode, where you do not release a version of the application package.
Once you have done this, your newly installed application will appear under the Apps objects in your Snowflake instance. Congratulations, you have successfully installed your first Native App!
To use your application, click on it and navigate to the tab linked to your Streamlit application.
If you would like to update or modify your application, upload new or updated existing application package files, release an updated version or patch, and re-create the application.
Reflecting on Snowflake’s Native Application Innovations
Snowflake’s Native Application features are incredibly powerful tools for allowing customers to get more value out of their data without having to leave the comfort of the platform. Furthermore, it massively simplifies the task of creating & managing SaaS tools for skilled developers hoping to monetize their products without worrying about the infrastructure overhead.
If you want to discuss or deploy native apps, do not hesitate to reach out using the form below.