chapter four

4 Streamlit’s execution model

 

This chapter covers

  • Building apps that maintain state between page updates
  • Troubleshooting apps
  • The all-important st.session_state and st.rerun
  • Streamlit’s execution model

In the last two chapters, you got your feet wet with Streamlit by building two fully functional apps: a password checker and a unit converter. You learned the basics of Streamlit syntax and how to create interactive elements. But what happens behind the scenes when a Streamlit app runs? Understanding this is key to building more complex applications. In this chapter, we explore Streamlit’s execution model and how to manage an app’s state.

This chapter also takes a slightly different approach than the previous ones. While we’ll still build a practical application—a daily to-do list app—the primary focus is on building troubleshooting skills. We’ll intentionally introduce bugs into the app to simulate real-world situations where things don’t go according to plan. By following along and fixing these problems, you’ll gain a deeper understanding of Streamlit’s inner workings and how to debug your apps effectively.

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

Summary