Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท Getting Started

What Is Streamlit?

Learn what Streamlit is, how a Python script becomes a web app, when to choose it over Flask or Dash, and which examples in this course are real or stand-ins.

Streamlit is a Python library that turns an ordinary script into an interactive web app. You write top-to-bottom Python, call functions like st.title() and st.slider(), and Streamlit shows a page with headings, charts and controls in your browser. You never write HTML, CSS, JavaScript or a route table.

It was made for people who already live in Python: data analysts, machine learning engineers and researchers who want to share a model or a dashboard without learning a web framework. A page that would take a day with Flask and a front end can be a thirty-line file.

What is real and what is a stand-in in this course

Be clear about this up front, because it shapes how you will practice. Streamlit needs a Python server process that keeps a websocket open to the browser, and the in-browser Python on this site (Pyodide) cannot start one. So:

  • Real Streamlit code appears in read-only ```python blocks. We describe in words what the page would show. These are real Streamlit programs; you run them on your own machine with streamlit run.
  • Runnable examples use Pyodide with pandas, NumPy and matplotlib. They run the data logic around an app (filtering, aggregating, drawing a chart), which is exactly the code you would put inside a Streamlit script.
  • Tiny stand-ins that we wrote by hand, clearly labelled, imitate one idea: how a script is re-run whenever a widget changes. They are not Streamlit, and they say so in their code.

Whenever a block is real or a stand-in, the text above it tells you.

Your first look

This is a complete, real Streamlit app. Saved as app.py and started with streamlit run app.py, it works as written.

Python
import streamlit as st

st.title("Tip calculator")

bill = st.number_input("Bill amount", min_value=0.0, value=50.0, step=1.0)
percent = st.slider("Tip percent", 0, 30, 15)

tip = bill * percent / 100
st.write(f"Tip: {tip:.2f}")
st.write(f"Total: {bill + tip:.2f}")

The page shows a large title, a number box starting at 50, a slider from 0 to 30 starting at 15, and two lines of text with the tip (7.50) and the total (57.50). Drag the slider to 20 and both numbers update at once. There is no callback function and no event handler: Streamlit simply runs the script again from the top with the new slider value.

The core idea: a script that reruns

flowchart LR
    A["You change a widget"] --> B["Browser tells the server"]
    B --> C["Server reruns app.py<br/>from top to bottom"]
    C --> D["New elements sent to browser"]
    D --> A

Every interaction triggers a full rerun of your script. The Rerun Model studies this in detail.

This model is the reason Streamlit is so easy, and also the source of nearly every beginner surprise. Because the script is just a script, you think in plain Python. Because it reruns constantly, you must learn to cache slow work and to keep memory between runs. Later chapters cover both.

What Streamlit gives you

One script, one app

Pure Python No HTML or JavaScript
Rerun model Widgets rerun the script
Hot reload Save the file, see the change
1 / 3

When to choose Streamlit

Streamlit shines for dashboards, internal tools, model demos and exploratory apps where the author is a Python programmer and the audience is people (colleagues, customers, students) who just want to click. Compare the alternatives:

Tool Best for Trade-off
Streamlit Fast data apps, prototypes, internal tools Whole script reruns; less control over exact layout
Flask / Django Full websites, APIs, accounts, databases You write routes, templates and front-end code
Dash Dashboards with fine-grained callbacks More boilerplate; callbacks wired by hand
Jupyter notebook Exploration for yourself Not a polished app for other people

It is not the right tool for a public site with millions of users, deep customization of every pixel, or heavy real-time collaboration. It is great for "I have an analysis; let others use it today."

The data logic is plain Python

Most of the work in a Streamlit app is ordinary pandas. This runnable example is the part you would put inside a sales dashboard: take some data, filter it by a value a widget would give you, and summarise. We use a fixed number in place of a slider.

Python The logic behind a dashboard (pandas, runnable)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Change min_units and run again. In Streamlit, a slider would do that change for you and the script would rerun automatically.

A taste of the rerun model (stand-in)

Here is the first of our hand-written stand-ins. This is not Streamlit. It is about 15 lines that imitate one thing: a widget value is remembered by the framework, and the whole script function runs again every time that value changes.

Python Stand-in: widget changes rerun the script

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that script never mentions events or updates. It is just a function that reads the current widget value and prints. That is the Streamlit programming model in miniature.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens when a user moves a slider in a Streamlit app?

    Streamlit reruns the whole script on the server each time a widget changes; there are no per-widget callbacks required.
  2. 2. Which skill does Streamlit let you avoid?

    You build the interface with Python function calls such as st.title and st.slider.
  3. 3. Why are the Streamlit apps on this site shown as read-only code?

    Streamlit runs a Python server with a websocket to the browser. The runnable examples here cover the data logic and a labelled stand-in for the rerun idea.
  4. 4. Which task suits Streamlit least?

    Full websites with accounts and custom design are better served by a web framework like Flask or Django.

Summary

  • Streamlit turns a Python script into a web app using function calls like st.title and st.slider.
  • Every interaction reruns the script from top to bottom.
  • It is ideal for dashboards, prototypes and internal data tools.
  • Real Streamlit code is read-only on this site; data logic and the rerun idea run in the browser with pandas and a labelled stand-in.

Next: Install Streamlit and Run Your First App