Streamlit Explained: Turning Python Scripts Into Web Apps
What Streamlit actually does, a basic example, how its rerun model works, and when to reach for it instead of Flask or FastAPI
Checked against Streamlit 1.67.0 (it requires Python 3.11 or later). Streamlit exists to answer one specific problem: a data scientist has a working script and needs to show it to someone else, without writing a frontend. No HTML, no CSS, no JavaScript — just Python function calls that become UI elements.
A basic example
import streamlit as st
import pandas as pd
st.title("Sales Dashboard")
uploaded = st.file_uploader("Upload CSV", type="csv")
if uploaded:
df = pd.read_csv(uploaded)
region = st.selectbox("Region", df["region"].unique())
st.line_chart(df[df["region"] == region]["sales"])streamlit run app.py turns that into a running web app with a file upload, a dropdown, and a chart — no route definitions, no templates, no separate frontend build step.
You can check the behaviour without a browser using Streamlit’s AppTest helper. This ran a variant of the app with built-in data (the file uploader is awkward to automate) on Streamlit 1.67.0: the title and dropdown options appeared as written, selecting a different region reran the script and updated the chart, and the @st.cache_data function still ran only once:
from streamlit.testing.v1 import AppTest
at = AppTest.from_file("app.py", default_timeout=60).run()
at.selectbox[0].select("S").run() # simulates choosing another dropdown option
print(at.selectbox[0].value) # S: the script reran with the new valueThe rerun model
Every interaction — clicking a button, moving a slider, selecting a dropdown option — reruns the entire script from top to bottom, with Streamlit caching expensive steps (like loading a large dataset) via @st.cache_data so they don’t rerun unnecessarily. That’s a genuinely different mental model from a traditional web framework’s request/response cycle, but it’s what keeps Streamlit apps simple to reason about even as they grow — there’s no client-side state to synchronize with the server, because the whole UI is just the output of running the script again. Newer releases add tools for the cases where a full rerun is too coarse: st.fragment reruns only part of a page, st.navigation and st.Page build multipage apps, and st.dialog opens modal dialogs (all present in 1.67.0). st.session_state keeps values across reruns.
Streamlit vs Flask or FastAPI
They’re not really competing for the same job. Flask and FastAPI give you full control over routes, APIs, and HTML — the right choice when you’re building a real product with custom UI, authentication, or an API other services will call. Streamlit gives up that control in exchange for speed: a working interactive app in an afternoon, with a UI toolkit of pre-built widgets instead of custom frontend code. Reach for Streamlit when the audience is internal, a demo, or a quick dashboard; reach for a real web framework once you need custom design, multiple user roles, or an API surface beyond the app itself.
Sharing what you build
The open-source library is free to run anywhere. Streamlit Community Cloud is described on Streamlit’s site as free for public apps: you sign in with GitHub, pick a repository, branch and file, and deploy, and pushes to the repository update the app. For private apps the same page points to deploying with Snowflake instead, so if the app must be private, plan for that route or self-host.
Frequently Asked Questions
What does Streamlit actually do?
Streamlit turns a plain Python script into an interactive web app by adding function calls for UI elements — sliders, buttons, charts, file uploads — with no HTML, CSS, or JavaScript required.
How does Streamlit’s rerun model work?
Every interaction reruns the entire script from top to bottom, with expensive steps like loading data cached via @st.cache_data so they don’t rerun unnecessarily. There’s no client-side state to synchronize — the UI is just the output of running the script again.
Should you use Streamlit or Flask/FastAPI?
Streamlit when the audience is internal, a demo, or a quick dashboard and you want a working app in an afternoon. Flask or FastAPI when you’re building a real product needing custom UI, authentication, or an API other services will call.
How do you share a Streamlit app?
The open-source library is free to run anywhere. Streamlit Community Cloud offers free hosting for public apps directly from a GitHub repo, the fastest path from script to shareable link if it doesn’t need to be private.