liveBook · Manning

What you will learn in Build Python Web Apps with Streamlit

AI and data applications in minutes

by Aneev Kochakadan
Foreword by Adrien Treuille

Chapter by chapter

Chapter 1: Introduction to Streamlit

This introduction positions Streamlit as a fast, Python-only way to build interactive web apps and previews the book’s project-based learning path.

1.1 Building web apps · 1.1.1 What do you need to build a web app? · 1.2 What is Streamlit? · 1.3 Ten reasons Streamlit is so popular · 1.3.1 Streamlit is pure Python · 1.3.2 Streamlit lets you go from idea to app in minutes · 1.3.3 Streamlit makes beautiful apps · 1.3.4 Streamlit lets you focus on your app, not UI details · 1.3.5 Streamlit’s syntax is simple, concise, and intuitive · 1.3.6 Streamlit works well with LLMs · 1.3.7 Streamlit has excellent support for data science and visualizations · 1.3.8 You can share your Streamlit apps for free, in record time · 1.3.9 Streamlit has a huge, friendly community · 1.3.10 You can extend Streamlit with third-party components or build your own · 1.4 What can you build with Streamlit? · 1.4.1 Data applications · 1.4.2 Apps that use Generative AI like LLMs · 1.4.3 Internal tools for your workplace · 1.4.4 Prototypes for large apps · 1.4.5 Anything else you can imagine · 1.5 When not to use Streamlit · 1.5.1 Complex, large-scale applications · 1.5.2 Apps that require a high degree of UI customization · 1.5.3 Native desktop or mobile apps · 1.6 How is Streamlit different from other technologies? · 1.6.1 Jupyter notebooks · 1.6.2 HTML, CSS, and JavaScript · 1.6.3 React · 1.6.4 Flask, Django, and FastAPI · 1.6.5 Tkinter and PyQt · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: Getting started with Streamlit

This chapter introduces the path from preparing a Streamlit development environment through learning the development workflow to building a first password-checker app.

2.1 Getting Streamlit up and running · 2.2 Setting up your development environment · 2.2.1 Version control with Git · 2.2.2 Code editors · 2.2.3 Virtual environments · 2.3 Running Streamlit for the first time · 2.4 The Streamlit development workflow · 2.5 Building your first app · 2.5.1 A password checker · 2.5.2 Logic flow · 2.5.3 Going through the code · 2.5.4 Running the app · 2.5.5 Making changes to the app · 2.5.6 Killing and restarting the server · 2.6 Summary

What you learn in chapter 2 →

Chapter 3: Taking an app from concept to code

This chapter introduces planning and design as essential work and previews an end-to-end process for turning an app concept into Streamlit code.

3.1 Concept to code: A six-step process · 3.2 Stating our concept: A unit converter · 3.3 Defining the requirements · 3.3.1 Defining what the app won’t do · 3.4 Visualizing the user experience · 3.4.1 Creating a mock · 3.5 Brainstorming the implementation · 3.5.1 Converting units · 3.5.2 Tracking units and conversion factors · 3.5.3 Mapping the flow of logic · 3.6 Writing code · 3.6.1 Implementing the frontend · 3.6.2 Implementing the backend · 3.6.3 Wiring up the frontend and backend · 3.7 Iterating on the app · 3.7.1 Rounding conversion results · 3.7.2 Getting rid of the button · 3.8 Summary

What you learn in chapter 3 →

Chapter 4: Streamlit’s execution model

This chapter introduces Streamlit’s execution model, state management, and troubleshooting through a daily to-do list app with intentionally created bugs.

4.1 A more complex app: Daily to-dos · 4.1.1 Stating the concept · 4.1.2 Defining the requirements and what is out of scope · 4.1.3 Visualizing the user experience · 4.1.4 Brainstorming the implementation · 4.2 Implementing and troubleshooting the app · 4.2.1 Displaying the task list · 4.2.2 Enabling actions · 4.3 How Streamlit executes an app · 4.3.1 Frontend and server · 4.3.2 App reruns · 4.3.3 Applying reruns to the app · 4.4 Persisting variables across reruns · 4.4.1 st.session_state · 4.5 Completing the app · 4.5.1 Adding session state · 4.5.2 Wiring up the Delete buttons · 4.5.3 What’s happening behind the scenes · 4.5.4 Triggering reruns automatically · 4.5.5 Wiring up the checkboxes · 4.5.6 An infinite rerun loop · 4.5.7 Preventing the infinite rerun · 4.5.8 Adding the completion progress indicator · 4.6 Summary

What you learn in chapter 4 →

Chapter 5: Sharing your apps with the world

This chapter introduces moving a Streamlit app from local development to public deployment, including hosting choices, external services, secrets, and dependencies.

5.1 Deploying apps · 5.1.1 What is deployment? · 5.1.2 Options for deployment · 5.2 Deploying the to-do list app to Streamlit Community Cloud · 5.2.1 Prerequisites · 5.2.2 Deployment steps · 5.3 Deploying an app that uses an external service · 5.3.1 A joke of the day to entertain users · 5.3.2 Using the requests library to connect to an API · 5.3.3 Incorporating jokes in the app · 5.3.4 Accessing an API key safely with st.secrets · 5.4 Deploying changes to Streamlit Community Cloud · 5.4.1 Using a requirements.txt file to manage Python dependencies · 5.4.2 Using .gitignore to protect secrets.toml · 5.4.3 Configuring secrets in Community Cloud · 5.5 Summary

What you learn in chapter 5 →

Chapter 6: A dashboard fit for a CEO

This chapter introduces why executive metrics dashboards matter and previews building an interactive CEO KPI dashboard with Streamlit, pandas, caching, widgets, and Plotly.

6.1 A metrics dashboard · 6.1.1 Stating the concept · 6.1.2 Defining the requirements · 6.1.3 Visualizing the user experience · 6.1.4 Brainstorming the implementation · 6.2 Loading the data · 6.2.1 The pandas library · 6.2.2 Reading and displaying a dataframe · 6.2.3 Caching data · 6.3 Prepping and filtering the data · 6.3.1 Creating a filter panel · 6.3.2 Creating a date range selector · 6.4 Calculating and displaying metrics · 6.4.1 Calculating the metrics · 6.4.2 Setting up the metrics configuration · 6.4.3 Formatting the metrics · 6.4.4 Displaying the metrics · 6.5 Constructing visualizations · 6.5.1 Creating a time series chart · 6.5.2 Creating a pie chart · 6.6 Summary

What you learn in chapter 6 →

Chapter 7: The CEO strikes back: Supercharging the dashboard

This chapter introduces an iterative upgrade of the Note n’ Nib metrics dashboard in response to user feedback, using advanced Streamlit features to improve flexibility and usability.

7.1 Feedback on the dashboard · 7.2 Granularity in the time series chart · 7.2.1 Enabling different time granularities · 7.2.2 Creating a time grain selector · 7.3 Interdependent filters · 7.4 Date range comparisons · 7.4.1 Adding another date range selector · 7.4.2 Showing the comparison in the metric bar · 7.5 A drilldown view · 7.5.1 Inserting a modal dialog · 7.5.2 Designing the content of the drilldown · 7.5.3 Implementing the drilldown view · 7.6 Enabling deeplinks · 7.6.1 Using st.query_params · 7.6.2 Setting widget defaults through st.session_state · 7.6.3 Implementing deeplinks · 7.7 Sourcing data from a data warehouse · 7.7.1 Getting data into BigQuery · 7.7.2 Setting up the Python-BigQuery connection · 7.7.3 Updating the dashboard to load data from BigQuery · 7.7.4 Notes on deployment to Streamlit Community Cloud · 7.8 Summary

What you learn in chapter 7 →

Chapter 8: Building a CRUD app with Streamlit

This chapter introduces CRUD as the common create, read, update, and delete pattern and previews building a Streamlit CRUD app with persistent storage and user authentication.

8.1 Haiku Haven: A CRUD app in Streamlit · 8.1.1 Stating the concept and requirements · 8.1.2 Visualizing the user experience · 8.1.3 Brainstorming the implementation · 8.2 Setting up persistent storage · 8.2.1 Relational database concepts · 8.2.2 Haiku Haven’s data model · 8.2.3 PostgreSQL: A real relational database · 8.2.4 A crash course in SQL · 8.2.5 Connecting PostgreSQL to the app · 8.3 Creating user accounts · 8.3.1 Splitting the app into services · 8.3.2 Creating the user service · 8.4 Setting up a multi-page login flow · 8.4.1 Multi-page apps in Streamlit · 8.4.2 Implementing login · 8.4.3 Navigating between pages · 8.5 Creating, reading, updating, and deleting haikus · 8.5.1 Defining a HaikuService class · 8.5.2 Enabling users to create haikus · 8.5.3 The other CRUD operations: Read, Update, Delete · 8.6 Deploying Haiku Haven · 8.6.1 Setting up a managed PostgreSQL server in production · 8.6.2 Deploying to Community Cloud · 8.7 Summary

What you learn in chapter 8 →

Chapter 9: Creating an AI-powered application

This chapter introduces building Streamlit features with LLM prompts and responses, controllable structured interactions, sequential state, and editable tables.

9.1 Fact Frenzy: An AI trivia game · 9.1.1 Stating the concept and requirements · 9.1.2 Visualizing the user experience · 9.1.3 Brainstorming the implementation · 9.2 Using AI to generate trivia questions · 9.2.1 Why use an LLM in Fact Frenzy? · 9.2.2 Setting up an OpenAI API key · 9.2.3 Calling the OpenAI API in Python · 9.2.4 Writing an LLM class · 9.2.5 The Game class · 9.2.6 Calling the Game class in the app · 9.3 Using AI to evaluate answers · 9.3.1 Structured Outputs · 9.4 Moving through game states · 9.5 Game mechanics: Keeping score, a New Game button, and Game Over · 9.5.1 Keeping score · 9.6 Including multiple questions · 9.6.1 Response variability, or lack thereof · 9.6.2 Implementing multiple questions · 9.7 Adding AI personalities · 9.7.1 Adding game settings · 9.8 Summary

What you learn in chapter 9 →

Chapter 10: RAG and agentic apps with LangGraph and Streamlit

This chapter introduces building a Streamlit customer-service chatbot that uses LangGraph, private data retrieval, and real-world actions to provide business value.

10.1 Nibby: A customer service bot · 10.1.1 Stating the concept and requirements · 10.1.2 Visualizing the user experience · 10.1.3 Brainstorming the implementation · 10.1.4 Installing dependencies · 10.2 Creating a basic chatbot · 10.2.1 Introduction to LangGraph and LangChain · 10.2.2 Graphs, nodes, edges, and state · 10.2.3 A one-node LLM graph · 10.3 Multi-turn conversations · 10.3.1 Adding memory to the graph · 10.3.2 Displaying the conversation history · 10.4 Restricting the bot to customer support · 10.4.1 Creating a base prompt · 10.4.2 Inserting a base context node in the graph · 10.5 Retrieval Augmented Generation · 10.5.1 What is Retrieval Augmented Generation? · 10.5.2 Implementing RAG in our app · 10.6 Turning the bot into an agent · 10.6.1 What are agents? · 10.6.2 The ReAct framework · 10.6.3 Creating tools an agent can use · 10.6.4 Making our graph agentic · 10.7 Summary

What you learn in chapter 10 →

Chapter 11: Testing Streamlit apps

This chapter introduces a testing strategy for Streamlit apps, covering automated tests at multiple levels to catch defects and prevent regressions as an app evolves.

11.1 MovieScout: An app to test · 11.1.1 Using the TMDB API to pull movie info · 11.1.2 The backend · 11.1.3 The frontend · 11.2 Testing the application · 11.2.1 Different kinds of tests · 11.2.2 Our testing approach · 11.2.3 A quick introduction to pytest · 11.3 Unit testing the backend · 11.3.1 How unit testing works · 11.3.2 Writing unit tests for the backend · 11.3.3 Running the tests · 11.4 Unit testing the Streamlit frontend · 11.4.1 Writing unit tests for the frontend · 11.4.2 Running frontend tests · 11.5 Testing the integration between components · 11.5.1 Writing integration tests · 11.6 Testing the end-to-end flow · 11.7 Evolving code and tests · 11.8 Summary

What you learn in chapter 11 →

Chapter 12: Packaging and deploying Streamlit apps

This chapter introduces moving beyond Streamlit Community Cloud by packaging a Streamlit app with Docker, deploying it to AWS Elastic Beanstalk, and giving it a custom HTTPS domain.

12.1 Deployment considerations · 12.1.1 Why Streamlit Community Cloud may not work for some users · 12.1.2 Deployment alternatives · 12.1.3 Our approach · 12.2 Packaging the app using Docker · 12.2.1 Intro to Docker · 12.2.2 The app in a container · 12.2.3 Creating a Dockerfile · 12.2.4 Excluding files from an image · 12.2.5 Building an image and running a container · 12.2.6 Adding a Docker Compose configuration · 12.3 Deploying to AWS Elastic Beanstalk · 12.3.1 An overview of AWS · 12.3.2 Introducing Elastic Beanstalk · 12.3.3 A mental model of the deployed app · 12.3.4 Creating and preparing an AWS account · 12.3.5 Modifying your app setup for Elastic Beanstalk · 12.3.6 Creating an Elastic Beanstalk app · 12.4 Adding a custom domain and HTTPS · 12.4.1 Adding a domain · 12.4.2 Creating a certificate · 12.4.3 Adding the certificate to your load balancer · 12.5 Go forth and develop! · 12.6 Summary

What you learn in chapter 12 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.