Streamlit Explained: Turning Python Scripts Into Web Apps
What Streamlit actually does, a basic example, and when to reach for it instead of Flask or FastAPI
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.
The 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.
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 offers free hosting for public apps directly from a GitHub repo, which is the fastest path from script to shareable link if the app doesn’t need to be private.