Quick Reference · Python web app framework

streamlit cheat sheet

Every Streamlit app is just a Python script that reruns top-to-bottom whenever a user touches a widget. Learn that one loop and every function below is just a way to read input, draw output, arrange layout, or remember state across reruns.

input / widgets display output layout & containers state, cache & flow system / app config most common

Distilled from the official docs.streamlit.io/develop/quick-reference/cheat-sheet · current as of Streamlit 1.4x API surface.

The rerun loop & what breaks out of it
Script runs top → bottom, every time st.write / st.dataframe st.line_chart ... Widget renders user sees a control st.button / st.slider st.selectbox ... User interacts click, type, drag, select widget returns a value Rerun st.rerun() / auto-rerun whole script re-executes script restarts from line 1 — everything not cached or in session_state is forgotten @st.cache_data / @st.cache_resource skip re-running expensive functions across reruns PYTHON PROCESS
01Install & Runcommand line
02Magic Commandsimplicit st.write
03Display Textthe swiss-army function
04Display Datatables & numbers
05Display Mediaimages, audio, video
06Display Chartsbuilt-in & library wrappers
07Sidebar & Bottompin elements outside the flow
08Columns & Tabsside-by-side layout
09Expanders, Popovers & Placeholderscollapse, float, or replace
10Control Flowforms, pages, fragments
11Interactive Widgetsuser input — the largest family
12Chat-based AppsLLM-style UI
13Mutate Data & Echo Codeupdate without a rerun
14Cachingsurvive the rerun
15Progress & Statuskeep users informed
16Users, Data & Configauth, connections, options

Composing layout containers

Sidebar, columns, tabs, and expanders all do the same thing — they give you a sub-region to write into — just shaped differently. Based on the official Streamlit layout reference.

st.sidebar

A fixed vertical rail beside the main page — great for filters and global controls.

sidebar radio slider main page st.title · st.line_chart

st.columns([3,1,1])

The page splits horizontally; ratios set relative widths of each region.

col1 col2 col3 st.columns([3, 1, 1])

st.tabs([...])

Same screen space, multiple containers — only the active tab is visible at once.

Tab 1 Tab 2 Tab 3 tab1.write("this is tab 1")

st.expander / st.popover

Content stays collapsed (or floating) until the user clicks to reveal it.

▾ My label expand.write("Inside the expander.")

Worth memorizing

script reruns fullyon every widget interaction — top to bottom, by default
cache_data ≠ cache_resourcedata → returned by value; resource → returned by reference
st.formbatches widgets — no rerun until the submit button fires
@st.fragmentreruns only that function, not the whole script
widgets return valuesassign the call directly: x = st.slider(...)
"with" notationworks on sidebar, columns, tabs, expander, container, form
set_page_config()must be the very first Streamlit call in the script
on_select="rerun"turns chart clicks/selections into widget-like events