Streamlit Tutorial
Learn Streamlit step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Install Streamlit and Run Your First App Install Streamlit in a virtual environment, run the hello demo, write app.py, start it with streamlit run, change the port and stop the server on any system.
- The Rerun Model How Streamlit runs your script: it reruns top to bottom on every interaction, plain variables reset, widgets keep values, and st.stop and st.rerun control the flow.
- Magic, st.write and Page Configuration Learn how st.write displays almost anything, how Streamlit magic shows bare variables, how to set the page title, icon and layout, and how to structure an app file.
Text, Data and Charts
- Text Elements Display text in Streamlit with title, header, subheader, markdown, caption, code, latex and divider. Learn colored text, badges, emoji and how to format numbers for display.
- DataFrames and Tables Show pandas data in Streamlit with st.dataframe, st.table and st.data_editor. Learn column_config, hiding the index, styling, row selection and editing data safely.
- Metrics and Status Elements Show KPIs with st.metric and deltas, give feedback with success, info, warning and error boxes, and show long-running work with progress, spinner, status and toast.
- Built-in Charts Draw charts in one line with st.line_chart, st.area_chart, st.bar_chart, st.scatter_chart and st.map. Learn wide versus long data, x and y arguments, colors and labels.
- Matplotlib, Altair and Plotly in Streamlit Use st.pyplot, st.altair_chart and st.plotly_chart for full control over charts. Learn figure functions, the object-oriented Matplotlib API, caching figures and choosing a library.
Input Widgets
- Buttons, Checkboxes and Toggles Learn Streamlit button behavior: buttons are True for one rerun, nested buttons vanish, and checkboxes and toggles keep state. Add download and link buttons.
- Text and Number Input Collect typed input in Streamlit with text_input, text_area and number_input. Learn defaults, validation, password fields, int versus float values and when the app reruns.
- Choice Widgets Let users choose with Streamlit selectbox, radio, multiselect, slider, select_slider, pills and segmented_control. Learn return values, defaults, format_func and filtering data.
- Date, File and Media Input Collect dates, times, files, photos and colors in Streamlit. Read an uploaded CSV with pandas, filter by a date range, limit file types and sizes, and handle bad files safely.
- Forms and Callbacks Batch inputs with st.form so the app reruns once on submit, and use on_click and on_change callbacks that run before the script. Includes ordering rules and common mistakes.
Layout and Navigation
- Columns and Containers Lay out a Streamlit page with st.columns, st.container and st.empty. Learn column ratios, gaps, alignment, bordered cards, scrolling containers and drawing out of order.
- Tabs, Expanders, Popovers and Dialogs Organize a Streamlit page with tabs, expanders and popovers, and ask for confirmation with st.dialog. Learn why every tab's code runs on each rerun and how to avoid slow tabs.
- The Sidebar Put filters and settings in the Streamlit sidebar with st.sidebar. Learn the with syntax, st.logo, starting collapsed, forms for filters and how to drive a dashboard from sidebar widgets.
- Multipage Apps Build multipage Streamlit apps with the pages folder or st.navigation and st.Page. Learn page links, switch_page, sections, shared state, URL paths and a clean project layout.
State and Caching
- How Streamlit Reruns Your Script Understand the Streamlit execution model: every widget interaction reruns the whole script. Learn what resets, what survives and why this shapes every app.
- Session State Learn st.session_state in Streamlit: initialize once, read and write with keys, link widgets to state, build counters, to-do lists and multi-step flows.
- Callbacks, Forms and Fragments Control when Streamlit reruns. Use on_change callbacks, st.form to batch inputs, st.fragment to rerun only part of the page, and st.rerun the right way.
- Caching with cache_data and cache_resource Speed up Streamlit apps with st.cache_data and st.cache_resource. Learn cache keys, ttl, max_entries, hashing rules, clearing caches and common pitfalls.
Data Connections
- Files, CSV and Excel in Streamlit Let users upload CSV, Excel and JSON files in Streamlit, read them with pandas, validate columns, handle large files and offer results through download buttons.
- SQL Databases and st.connection Connect Streamlit to SQL databases with st.connection and SQLAlchemy. Run safe parameterized queries, cache results with ttl and test the logic with SQLite.
- Web APIs and Secrets in Streamlit Call web APIs from Streamlit with requests, cache responses, handle errors and timeouts, and keep API keys safe with st.secrets and secrets.toml.
- Editing and Saving Data with st.data_editor Let users edit tables in Streamlit with st.data_editor. Read edited_rows, added_rows and deleted_rows, validate input and save the changes to SQLite safely.
Machine Learning Apps
- Building a Machine Learning App Build a machine learning app in Streamlit: load data, train a scikit-learn model, collect inputs with sliders, show predictions and probabilities, with clean code structure.
- Saving, Loading and Sharing Models Persist scikit-learn models for Streamlit with joblib, load them once with cache_resource, version them, retrain on demand with a button and avoid unsafe pickles.
- Model Evaluation Dashboards Build a model evaluation page in Streamlit: accuracy, precision, recall, confusion matrix, feature importance and an interactive decision-threshold slider.
- Chat Apps with st.chat_message Build chat interfaces in Streamlit with st.chat_message and st.chat_input. Keep history in session state, stream replies and call a language model API safely.
Deployment and Customization
- Configuration and Themes Configure Streamlit with config.toml, command-line flags and environment variables. Set themes, ports, upload limits, page title, icon and layout for your app.
- Deploying to Streamlit Community Cloud Publish a Streamlit app for free: structure the repository, write requirements.txt, add secrets, deploy from GitHub, manage updates and fix common build errors.
- Running Streamlit with Docker and a Reverse Proxy Package a Streamlit app in a Docker image, set options with environment variables, add a health check, and put it behind Nginx with WebSocket support and HTTPS.
- Performance and Security Checklist Find slow spots in a Streamlit app with timing, then fix them with caching, smaller data and fragments. Add passwords, validate input and avoid common security holes.
Projects and Practice
- Project: Expense Tracker with SQLite Build a complete expense tracker in Streamlit: a SQLite database layer, an add-expense form, filters, monthly summaries, charts and CSV export, with tested logic.
- Project: Machine Learning Prediction App Build a complete regression app in Streamlit: train and evaluate a model offline, show predictions with an uncertainty range, explain inputs and package it for deployment.
- Project: A Data Explorer for Any CSV Build a reusable data explorer in Streamlit: upload any CSV, profile columns, filter rows dynamically, group and pivot, choose charts and download the filtered result.
- Practice, Testing and Review Test Streamlit apps with pytest and the AppTest framework, separate logic from the UI, and practice with ten graded exercises that review state, caching, data and deployment.