4 Streamlit’s execution model
This chapter covers
- Building apps that maintain state between page updates
- Troubleshooting apps
- The all-important
st.session_stateandst.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.
Note The GitHub repo for the book is at https://github.com/aneevdavis/streamlit-in-action. The chapter_04 folder contains all the code for this chapter, including “in progress” versions you can use to follow along.