Photo by Andrea De Santis on Unsplash
By Deiby Gómez
As Data Engineers, there’s a growing need to present data pipelines, monitoring tools, and insights through lightweight, user-friendly web applications. Streamlit has become a go-to framework for building these tools due to its speed, simplicity, and native integration with the Python data ecosystem. Streamlit allows developers to create interactive front-ends with just a few lines of Python code. With built-in support for charts, widgets, and media, it’s ideal for prototyping dashboards, exposing ML models, or building internal tools that communicate complex data processes.
While Streamlit makes it easy to create interactive single-page applications, many developers encounter challenges structuring multi-page applications with clean navigation.
We’ll walk through the creation of a multi-page Streamlit application that consists of a main page that acts as a central hub, and three secondary pages (“page1”, “page2”, and “page3”), each representing a separate section of your app—such as data sources, processing pipelines, or output summaries. The navigation allows users to move from the main page to any of the secondary pages and return back with ease.

This example includes 4 python scripts:
- main_page.py: has the code for the main page.
- page1.py: has the code for the page1, it will show a text and a button to return the main page.
- page2.py: has the code for the page2, it will show a text and a button to return the main page.
- page3.py: has the code for the page2, it will show a text and a button to return the main page.
main_page.py:
This script serves as the entry point of the Streamlit application and handles multi-page navigation logic using st.session_state. You can use this for your login or any other homepage. It checks whether a navigation target is stored in session state and dynamically routes the user to the corresponding page module (page1, page2, or page3). If no page is selected, it displays buttons to let the user choose a page. Upon clicking, it stores the target page in the session and triggers a rerun to load the corresponding page.
import streamlit as st
import page1
import page2
import page3
if 'navigation_page' in st.session_state:
if st.session_state["navigation_page"]=='page1':
page1.main()
elif st.session_state["navigation_page"]=='page2':
page2.main()
elif st.session_state["navigation_page"]=='page3':
page3.main()
else:
if st.button("Go to Page 1"):
st.session_state["navigation_page"]='page1'
st.rerun()
if st.button("Go to Page 2"):
st.session_state["navigation_page"]='page2'
st.rerun()
if st.button("Go to Page 3"):
st.session_state["navigation_page"]='page3'
st.rerun()
page1.py:
This module defines the content for Page 1. It displays a simple message and a button that, when clicked, clears the navigation state and reruns the app—sending the user back to the main page. This is a minimalist approach that allows returning to the homepage without explicitly tracking the previous page.
import streamlit as st
def main():
st.write ("This is page 1")
if st.button("Go main page"):
del st.session_state["navigation_page"]
st.rerun()
page2.py:
Functionally identical to Page 1, but serves as a distinct section of the application. This pattern allows each page to encapsulate its own content and logic while maintaining a consistent method for returning to the main page.
import streamlit as st
def main():
st.write ("This is page 2")
if st.button("Go main page"):
del st.session_state["navigation_page"]
st.rerun()
page3.py:
Same structure as the other page modules. This modular setup encourages clean separation of concerns, making it easier to scale the application by adding more pages or functionality over time.
import streamlit as st
def main():
st.write ("This is page 3")
if st.button("Go main page"):
del st.session_state["navigation_page"]
st.rerun()
Conclusion
Building multi-page applications in Streamlit might seem non-intuitive at first, especially for developers coming from traditional web frameworks. However, with a straightforward use of st.session_state and st.rerun(), it’s entirely possible to implement clean and effective page transitions in Streamlit.
By organizing your pages into separate modules and controlling navigation from a central logic in the main script, you’ll create a better user experience and ensure your codebase remains modular and scalable. This structure makes it easier to expand your application in the future.
Resources:
- Asking Business information using Natural Language in Snowflake with Cortex Analyst
- How to Forecast your sales in Snowflake
- How to update your lambdas to authenticate with SSH Keys in Snowflake
Deiby Gómez was the first Oracle ACE Director of Guatemala (2015-2023) and has 35 Technology certifications including the highest certifications for Oracle Database (Oracle Certified Master, OCM) and three Advanced Snowflake Certifications (Architect, Administrator and Data Engineer). An engineer with two master’s degrees and a future lawyer, Deiby has spoken in Technology Events in more than 12 countries including Oracle Open World in San Francisco. Most recently, Deiby was selected as 2025 Snowflake Squad Member.
Is your organization adapting to remain competitive? In The Architect Room, we design a roadmap for the future of your digital organization, while capitalizing on current technology investments. Our knowledge spans a variety of offerings across all of the major public cloud providers. Visit Red Pill Analytics or feel free to reach out on Twitter, Facebook, and LinkedIn. For more data tips and tricks, check out our blogs or browse the RPA blogs at Medium.