Courses/Streamlit: 20 Real Apps/Module 2: Streamlit Fundamentals
Module 2 · Lesson 120 minBeginner

Your First Streamlit App in 10 Lines

Lesson goal
Build and run your first web app, and understand Streamlit's rerun model — the key idea behind everything else.

Your first web app — in 10 lines

You are about to do something most people think requires months of web development: put a real, interactive web app on your screen. Ten lines of Python. No HTML, no CSS, no JavaScript.

Step 1: Install Streamlit

In your terminal (with your project's virtual environment active):

code
pip install streamlit

Step 2: Create the app

Create a file called first_app.py:

code
import streamlit as st

st.title("🚀 My First App")
st.write("Hello! This is a real web app, built with Python.")

name = st.text_input("What is your name?")

if st.button("Greet me"):
    st.success(f"Welcome, {name}! You are officially an app developer.")

Step 3: Run it

code
streamlit run first_app.py

Your browser opens at localhost:8501 — type your name, press the button, and watch it respond. You just built a web app. Screenshot it. You'll want to remember this one.

How it actually works

The single most important idea in Streamlit — understand this and everything else becomes easy:

> Streamlit re-runs your entire script from top to bottom every time you interact with a widget.

Click the button? The script runs again, top to bottom. Type in the text box? Rerun. This is called the rerun model, and it's why Streamlit apps are just... Python scripts.

Walk through what happens on each rerun:

  • st.title draws the heading
  • st.write draws the text
  • st.text_input draws the box and holds whatever you typed
  • If the button is pressed, the success message appears
  • The script isn't "reacting to events" like JavaScript — it's simply re-executing and drawing a fresh page. That's the whole magic.

    The vocabulary you now know

  • Widget — anything the user interacts with (text_input, button, slider...)
  • Rerun — the full script re-execution that happens on every interaction
  • st.write — the "display anything" function: text, numbers, lists, DataFrames
  • Common Errors & Fixes

  • streamlit: command not found — your virtual environment isn't active, or the pip install didn't finish. Re-run pip install streamlit inside the venv.
  • Port 8501 is already in use — an older app is still running. Close that terminal tab, or run with --server.port 8502.
  • Nothing happens when I press the button — check the indentation: the st.success line must be *inside* the if (indented 4 spaces).
  • What to try next

    Before moving on, experiment:

  • Add a second text input for favorite food and include it in the greeting
  • Add a slider ("Pick a number", 1 to 100) and display the value
  • Try st.balloons() inside the button — you've earned it
  • Checkpoint
    Your app runs at localhost:8501 and updates the moment you save the file.
    What you learned
    • How st.title, st.write, and st.button work
    • The rerun model — why scripts re-run top to bottom
    • Running apps with streamlit run