pip install streamlit★Install the framework.streamlit run first_app.py★Launch the dev server & open browser.import streamlit as st★Universal import convention.streamlit helloDemo app to explore the API.streamlit cache clearClear all on-disk/in-memory caches.streamlit config showPrint all current config values.streamlit docs/help/init/versionOpen docs, get help, scaffold, or check version.
"_This_ is **Markdown**"★A bare string on its own line renders.my_variableAny bare variable/expression auto-displays."dataframe:", my_dfMixed bare-expression tuples render too.
st.write(obj)★Auto-formats almost anything — df, error, chart...st.write_stream(generator)Stream tokens — built for LLM output.st.markdown("_md_")★Render Markdown / limited HTML.st.title("…")★Page-level title (H1).st.header("…")Section heading (H2).st.subheader("…")Sub-section heading (H3).st.code("for i…")★Syntax-highlighted code block.st.latex(r"…")Render LaTeX math.st.text("…")Fixed-width, no formatting.st.badge("New")newSmall colored status pill.st.html("<p>Hi!</p>")Drop raw HTML into the page.st.iframe(url, height=600)Embed an external page.
st.dataframe(df)★Interactive, sortable, scrollable table.st.table(df.iloc[0:10])Static table — fully rendered, no scroll.st.json({"foo":"bar"})Collapsible, syntax-highlighted JSON.st.metric("label", 42, 2)★Big number + delta indicator (▲/▼).
st.image("./header.png")★Show an image from path, URL, or array.st.logo("logo.jpg")App logo, top-left of sidebar/header.st.pdf("doc.pdf")newRender a PDF inline.st.audio(data)Embed an audio player.st.video(data)Embed a video player.st.video(data, subtitles="./s.vtt")Video with subtitle track.
st.line_chart(df)★Zero-config line chart from a dataframe.st.bar_chart(df)★Zero-config bar chart.st.area_chart(df)Zero-config area chart.st.scatter_chart(df)Zero-config scatter plot.st.map(df)Plot lat/lon points on a map.st.plotly_chart(fig)★Full interactive Plotly figure.st.pyplot(fig)Render a Matplotlib figure.st.altair_chart/graphviz_chart/pydeck_chart/vega_lite_chartOther supported chart libraries.st.plotly_chart(df, on_select="rerun")newCapture click/box-select as an event → triggers rerun.
st.sidebar.radio("…", [1,2])★Call directly offst.sidebar.with st.sidebar: …★Or group several elements with "with".st.bottom.chat_input("…")Pin an element to the bottom bar.
col1, col2 = st.columns(2)★Two equal-width columns.st.columns([3, 1, 1])Custom relative widths — first is widest.st.columns(2, vertical_alignment="bottom")Align column contents to the bottom.tab1, tab2 = st.tabs(["A","B"])★Containers switched by clickable tabs.with col1: st.radio(…)★"with" notation works for columns & tabs.
expand = st.expander("label")★Collapsible container.pop = st.popover("label")Floating panel triggered by a button.el = st.empty(); el.line_chart(…)★Reserve a slot; later calls replace its content.box = st.container(); box.write(…)Insert elements out of code order.st.container(horizontal=True)newFlex container — children laid out in a row.st.space("small")Add vertical breathing room.
st.stop()Halt script execution immediately.st.rerun()★Force an immediate rerun from the top.st.switch_page("pages/x.py")Programmatically navigate to another page.pg = st.navigation([st.Page(…)]); pg.run()★Define multi-page navigation in the entrypoint.with st.form("id"): … st.form_submit_button()★Batch widgets — no rerun until submit.@st.dialog("Welcome!")Decorate a function to open as a modal.@st.fragment★Rerun just this function, not the whole script.
st.button("Click me")★Returns True for one rerun on click.st.download_button("…", data)Click to download bytes/file.st.link_button("…", url)Button that opens a URL.st.page_link("app.py", label="Home")Link to another page in the app.st.checkbox("I agree")★Boolean toggle.st.toggle("Enable")Switch-style boolean.st.radio("Pick one", [..])★Single choice from a list.st.selectbox("Pick one", [..])★Single choice dropdown.st.multiselect("Buy", [..])★Multiple choices from a list.st.pills("Tags", [..])Tag-style single/multi select.st.segmented_control("Filter", [..])Segmented-button style choice.st.slider("Pick a #", 0, 100)★Numeric (or date) range slider.st.select_slider("Size", [..])Slider over discrete options.st.text_input("First name")★Single-line text box.st.text_area("…")Multi-line text box.st.number_input("…", 0, 10)★Numeric stepper.st.date_input/time_input/datetime_inputPickers for date, time, or both.st.file_uploader("Upload CSV")★Drag-and-drop file upload.st.camera_input/audio_inputCapture a photo or voice recording.st.color_picker("Pick")Hex color picker.st.feedback("thumbs")Thumbs/star/face rating widget.st.data_editor("Edit", data)★Spreadsheet-like editable table.st.menu_button("Export", options=[..])newDropdown of selectable actions.st.pagination(10)newPage-number navigator control.val = st.slider("…", 1, 88)★Every widget returns its current value.st.slider("…", 0, 100, disabled=True)Disable to remove interactivity.
with st.chat_message("user"): st.write(..)★Avatar + bubble container for one message.st.chat_input("Say something")★Sticky input bar, pinned to bottom.with st.container(): st.chat_input(..)Place the chat box inline instead.
el = st.dataframe(df1); el.add_rows(df2)★Append rows to an already-drawn table.el = st.line_chart(df1); el.add_rows(df2)★Append rows to an already-drawn chart.with st.echo(): st.write(..)Show the source code, then run it.
@st.cache_data★Cache data — DataFrames, API responses, etc.@st.cache_resource★Cache objects — DB connections, ML models.foo.clear(ref1)Clear the cached entry for one set of args.foo.clear()Clear every cached entry for this function.st.cache_data.clear()Wipe all cached data app-wide.
with st.spinner("In progress"): …★Spinner while a block of code runs.bar = st.progress(50); bar.progress(100)★Updatable progress bar.with st.status("Authenticating…") as s: …Expandable, updatable status log.st.toast("Warming up…")★Brief, auto-dismissing notification.st.success/info/warning/error★Color-coded inline message boxes.st.exception(e)Pretty-printed traceback.st.balloons()/snow()Celebratory full-screen animation.
if not st.user.is_logged_in: st.login("provider")Built-in OIDC authentication.st.logout()End the user's session.st.context.cookies / headers / locale / ip_addressRead request & browser context.st.connection("db", type="sql")Managed connection to SQL, Snowflake, etc.st.set_page_config(layout="wide")★Title, icon, layout — call once, first.st.query_params[key]Read/write the URL query string.st.get_option / st.set_optionRead or set a config value at runtime.app = st.App()newExpose the underlying Starlette app.