Run and share Streamlit apps

This example shows you how to run a Streamlit app with modal serve, and then deploy it as a serverless web app.

example streamlit app

This example is structured as two files:

  1. This module, which defines the Modal objects (name the script serve_streamlit.py locally).

  2. app.py, which is any Streamlit script to be mounted into the Modal function (download script).

Define container dependencies 

The app.py script imports three third-party packages, so we include these in the example’s image definition and then add the app.py file itself to the image.

Spawning the Streamlit server 

Inside the container, we will run the Streamlit server in a background subprocess using subprocess.Popen. We also expose port 8000 using the @web_server decorator.

Iterate and Deploy 

While you’re iterating on your screamlit app, you can run it “ephemerally” with modal serve. This will run a local process that watches your files and updates the app if anything changes.

Once you’re happy with your changes, you can deploy your application with

If successful, this will print a URL for your app that you can navigate to from your browser 🎉 .