Skip to main content

Streamlit

Streamlit is a Python framework for building data science and machine learning web applications, making it easy to create interactive dashboards and visualizations.

tip

Get started in no time with the Streamlit template.

Deployment

Learn how to deploy an existing Streamlit app using Genezio, a serverless deployment platform that simplifies app management and reduces costs.

Prerequisites

1. Install genezio

Use your preferred package manager to install Genezio:

npm install genezio -g

2. Ensure you have a Streamlit App

If you don't have a Streamlit app, you can create one using the following steps:

Create a Hello World Streamlit App

1. Set up your project

Create a new directory and install Streamlit:

mkdir my-streamlit-app
cd my-streamlit-app
pip install streamlit

Create a new file called app.py with this basic example:

import streamlit as st

st.title('Hello World!')
st.write('Welcome to my Streamlit app!')

2. Create requirements.txt

To ensure all dependencies are properly tracked and installed during deployment, create a requirements.txt file by running:

pip freeze > requirements.txt

Alternatively, you can manually create a requirements.txt file with just the necessary dependencies:

streamlit

3. Test the Streamlit App

Run the following command to start the Streamlit app:

streamlit run app.py

Open a web browser and navigate to http://localhost:8501 to see the app running.

Deployment Guide

1. Create configuration file

First, you need to create the configuration file in the root directory of your Streamlit app, run the following command:

genezio analyze

This command will analyze your project and create the genezio.yaml file in the root directory of your Streamlit app, with the following content:

# The name of your project, which also influences the subdomain of the project.
name: genezio-project
# Select a region closest to your user base for optimal performance.
region: us-east-1
# Specifies the version of the YAML configuration syntax being used.
yamlVersion: 2
# Configuration specific to the Streamlit project setup.
streamlit:
# The path to the directory containing your Streamlit app.
path: .
# The package manager used to install dependencies.
packageManager: pip
# The entry file of your Streamlit app.
entryFile: app.py
# The runtime to use for your Streamlit app.
runtime: python3.13.x
Supported Python Runtimes

Genezio supports the following Python runtime values:

  • python3.9.x
  • python3.10.x
  • python3.11.x
  • python3.12.x
  • python3.13.x

Use these exact values in your genezio.yaml configuration file, at the runtime field.

2. Deploy your project

Finally, deploy your project. A browser window will open, and you will be prompted to log in to your Genezio account and authorize the CLI to make the deployment. Run the following command in your terminal:

genezio deploy
warning

The requirements.txt file is required for the deployment to work.

Local Development

To develop and test your app locally, run:

genezio local

This command starts a local development server on port 8501 by default. You can specify a custom port by setting the GENEZIO_PORT_STREAMLIT environment variable using one of these methods:

  • Add GENEZIO_PORT_STREAMLIT=<port> to your .env file
  • Windows: Run set GENEZIO_PORT_STREAMLIT=<port> && genezio local
  • macOS/Linux: Run GENEZIO_PORT_STREAMLIT=<port> genezio local

See your app in Genezio Dashboard

After deploying your application, you can test it to ensure it's running correctly. To verify that your Streamlit app is working, open a web browser and navigate to the URL provided for your deployed app.

Additionally, you can monitor and manage your app through the Genezio App Dashboard. The dashboard URL, also provided after deployment, allows you to access comprehensive views of your project's status and logs.

You can find this URL in the deployment output under the App Dashboard URL section.

Support

We invite you to join our community on Discord for further information and help.

Happy Learning!