> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to Streamlit: Python Web Apps Without HTML

> Learn what Streamlit is, how its rerun execution model works, and how to create and run your first interactive Python web application.

One of the biggest challenges in data science and machine learning is sharing your work with people who don't use Python. Jupyter notebooks require a running kernel; command-line scripts produce no visual output; and building a proper web frontend requires HTML, CSS, and JavaScript skills most data scientists don't have. **Streamlit** solves this problem by letting you turn a plain Python script into a fully interactive web application — with no frontend code whatsoever. You write Python, run one command, and anyone with a browser can use your app.

## What Is Streamlit?

Streamlit is an open-source Python library designed for building data dashboards, AI demos, and interactive internal tools. It is especially popular for:

* **AI chat interfaces** — connect to a language model and wrap it in a UI
* **Data dashboards** — upload a CSV, visualize it, and filter results interactively
* **ML model demos** — let non-technical users adjust inputs and see predictions
* **Internal business tools** — replace clunky spreadsheet workflows with polished apps

## How Streamlit Works

Streamlit follows a simple **client-server architecture**:

1. Your Python script runs as a server process.
2. The browser displays the rendered interface as a client.
3. When the user interacts with any widget (button, slider, text field), the browser sends the event to the server.
4. Streamlit **reruns your entire script from top to bottom** to refresh the UI with the updated values.

This **rerun model** is the key mental model to internalize. Every interaction triggers a full script re-execution. This keeps the UI in sync with your Python logic automatically — but it also means you need to understand caching (covered in the Data Handling chapter) to avoid re-running expensive operations on every rerun.

### A Simple Example

```python theme={null}
import streamlit as st

st.title("Hello Streamlit")
name = st.text_input("Your name")

if name:
    st.write(f"Hello, {name}!")
```

Every time you type a character in the text field, Streamlit reruns the script, evaluates the `if` block, and updates the greeting instantly.

## Creating and Running an App

<Steps>
  ### Install Streamlit

  ```bash theme={null}
  pip install streamlit
  ```

  ### Create Your App File

  Create a file called `app.py` with your Streamlit code.

  ```python theme={null}
  import streamlit as st

  st.title("My First App")
  st.write("Welcome to Streamlit!")
  ```

  ### Run the App

  ```bash theme={null}
  streamlit run app.py
  ```

  Streamlit starts a local development server, typically at `http://localhost:8501`, and opens your app in the default browser automatically.

  ### Edit and Reload

  Edit `app.py` and save. Streamlit detects the change and shows a **Rerun** button in the top-right corner of the browser. Click it (or enable auto-rerun) to see your changes immediately.
</Steps>

## Recommended Project Structure

A simple Streamlit project typically looks like this:

```text theme={null}
my_project/
├── app.py          ← main app logic
├── data/           ← CSV or JSON data files
├── images/         ← local images used in the app
├── pages/          ← additional pages for multipage apps
└── requirements.txt
```

<Tip>
  For multipage apps, place additional Python files inside a `pages/` directory. Streamlit automatically detects them and adds navigation links in the sidebar — no routing code required.
</Tip>

## What's in This Module

The Streamlit module is organized into five sections that build on each other:

| Section                | What You'll Learn                                           |
| ---------------------- | ----------------------------------------------------------- |
| **Displaying Content** | Text, tables, images, code blocks, status messages          |
| **Widgets**            | Buttons, text inputs, sliders, file uploaders, date pickers |
| **Data Handling**      | Loading CSVs, filtering DataFrames, Matplotlib charts       |
| **Building Apps**      | Full capstone project — a Student Performance Dashboard     |
