Build data apps, dashboards, and AI tools using pure Python with minimal effort.
-
What is Streamlit?
-
When & Why Use Streamlit
-
Installation & Setup
-
Streamlit App Structure
-
Running a Streamlit App
-
Core Concepts
- Script Rerun Model
- State & Reactivity
-
Layout & Page Structure
-
Display Elements
-
Input Widgets
-
Data Display Components
-
Charts & Visualization
-
Forms
-
Session State
-
Caching & Performance
-
File Uploads & Downloads
-
Sidebar & Multipage Apps
-
Configuration & Theming
-
Deployment Options
-
Streamlit for AI / LLM Apps
-
Best Practices
-
Common Pitfalls
-
Mini Project Ideas
Streamlit is an open-source Python framework used to build interactive web applications for:
- Data analysis
- Dashboards
- Machine learning demos
- AI / LLM-powered tools
- Internal tools & prototypes
Write Python → Get a Web App
No frontend frameworks. No HTML/CSS/JS required.
- You want to quickly build a UI for Python logic
- You are building AI tools (chatbots, summarizers, RAG apps)
- You need internal dashboards
- You want fast iteration
- You need heavy custom UI
- You are building large consumer apps
- SEO or fine-grained frontend control is critical
pip install streamlitCheck installation:
streamlit versionMinimal app:
import streamlit as st
st.title("Hello Streamlit")
st.write("My first Streamlit app")📁 Typical structure:
app.py
requirements.txt
pages/
1_Dashboard.py
2_Settings.py
streamlit run app.py- App runs on:
http://localhost:8501 - Auto reloads on file save
👉 Streamlit re-runs the entire script from top to bottom on every user interaction
Example:
count = 0
if st.button("Click"):
count += 1
st.write(count)❌ This will always show 1
Why? Because the script restarts.
Widgets automatically trigger reruns.
name = st.text_input("Enter name")
st.write("Hello", name)No event handlers required.
st.title("Main Title")
st.header("Header")
st.subheader("Subheader")
st.text("Plain text")
st.markdown("**Markdown supported**")col1, col2 = st.columns(2)
with col1:
st.write("Left")
with col2:
st.write("Right")with st.container():
st.write("Grouped content")st.metric("Revenue", "₹1,20,000", "+8%")st.success("Success")
st.error("Error")
st.warning("Warning")
st.info("Info")import time
progress = st.progress(0)
for i in range(100):
time.sleep(0.05)
progress.progress(i + 1)st.text_input("Name")
st.text_area("Description")st.number_input("Age", min_value=0)
st.slider("Rating", 0, 10)st.selectbox("Country", ["India", "USA"])
st.multiselect("Skills", ["Python", "JS", "AI"])
st.radio("Gender", ["Male", "Female"])if st.button("Submit"):
st.write("Clicked!")import pandas as pd
df = pd.DataFrame({
"Name": ["A", "B"],
"Score": [80, 90]
})
st.dataframe(df)
st.table(df)st.json({"name": "Vinod", "role": "Engineer"})st.line_chart(df)st.bar_chart(df)import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
st.pyplot(fig)import plotly.express as px
fig = px.line(df, x="Name", y="Score")
st.plotly_chart(fig)with st.form("login"):
user = st.text_input("Username")
pwd = st.text_input("Password", type="password")
submitted = st.form_submit_button("Login")
if submitted:
st.write("Logged in:", user)Used to persist data across reruns.
if "count" not in st.session_state:
st.session_state.count = 0if st.button("Increment"):
st.session_state.count += 1
st.write(st.session_state.count)Used for data loading
@st.cache_data
def load_data():
return pd.read_csv("data.csv")Used for models, DB connections
@st.cache_resource
def load_model():
return modelfile = st.file_uploader("Upload CSV")
if file:
df = pd.read_csv(file)
st.dataframe(df)st.download_button(
"Download",
data="Hello",
file_name="hello.txt"
)st.sidebar.title("Menu")
option = st.sidebar.selectbox("Choose", ["Home", "Settings"])📁 Structure:
app.py
pages/
1_Home.py
2_Settings.py
Streamlit auto-detects pages.
[theme]
primaryColor="#4CAF50"
backgroundColor="#FFFFFF"
textColor="#000000"- Streamlit Community Cloud
- AWS EC2
- Docker
- HuggingFace Spaces
- Render / Railway
Typical flow:
- User input
- Call LLM API
- Show response
prompt = st.text_area("Ask")
if st.button("Generate"):
response = call_llm(prompt)
st.write(response)Perfect for:
- Chatbots
- Summarizers
- RAG systems
- AI tutors
✅ Use st.session_state
✅ Use forms for inputs
✅ Cache heavy operations
✅ Modularize logic
✅ Keep UI simple
❌ Forgetting rerun behavior ❌ Heavy computation without caching ❌ Global variables ❌ Blocking API calls
- AI Chatbot UI
- Resume Analyzer
- Text Summarizer
- CSV Dashboard
- LLM Playground
- Admin Panel for ML Models
Streamlit turns Python into a UI superpower.
If you know Python, you already know Streamlit.