How shivtejpatil2807/streamlit-cookbook works
Purpose and Entrypoints
This repository contains two independent Streamlit applications: a multipage Streamlit cookbook and a standalone number-guessing game. Run the cookbook with streamlit run Home.py; run the game with streamlit run game.py. Both execute in Streamlit’s Python runtime and render directly in the browser.
Paths: Home.py, game.py, requirements.txt
Cookbook Shell and Navigation
Home.py is the cookbook landing page and topic index. Streamlit automatically discovers Python files in pages/ and exposes them as ordered sidebar navigation entries; numeric filename prefixes define their order. There is no separate router or frontend layer.
Paths: Home.py, pages/01_Text_and_Markdown.py, pages/13_Navigation.py
Topic-Page Demonstration Model
Each topic page is a self-contained executable lesson: it presents Streamlit API usage, displays the associated code, and renders its live output. Pages are intentionally isolated so learners can run and inspect one capability at a time rather than sharing a domain model.
Paths: pages/02_Input_Widgets.py, pages/04_Data_Display.py, pages/05_Charts.py
Interaction and Rerun Boundary
Streamlit widgets drive control flow by returning current values during a full top-to-bottom rerun of the active script. Input, layouts, file/media handling, status feedback, and forms are demonstrated as direct Streamlit calls rather than through a client-side application layer.
Paths: pages/03_Layouts.py, pages/06_File_Handling.py, pages/08_Status_and_Messages.py
Stateful and Deferred-Execution Patterns
The cookbook explicitly covers Streamlit mechanisms that cross rerun boundaries: st.session_state retains per-session values, forms batch input until submit, and cache decorators avoid repeated data/resource initialization. Authentication is presented through Streamlit/session-state patterns.
Paths: pages/09_Session_State.py, pages/10_Forms.py, pages/11_Caching.py
Chat and Authentication Examples
Later tutorial stages cover conversational UI primitives and login behavior. These are examples within the cookbook, not evidence of a shared authentication service or backend identity provider.
Paths: pages/12_Chat_Elements.py, pages/14_Authentication.py
Guess Game Flow
game.py is a separate interactive, multi-stage game. A player supplies a username, then progresses through random-number guessing and randomized pattern challenges. Session state maintains game progress across Streamlit reruns; completion reaches success, while failed stages reach game-over/restart paths. Game logic has dedicated test coverage.
Paths: game.py, tests/test_game_logic.py
Infrastructure and External Services
The material runtime is Python plus Streamlit, with dependencies declared in requirements.txt. Local hosting is Streamlit’s development server (normally port 8501). The README links deployed instances on Streamlit Community Cloud; no database, persistence layer, API service, or external authentication provider is represented in the file tree.
Paths: requirements.txt, .devcontainer/devcontainer.json
Components 17
Cookbook tutorial
Multipage Streamlit lessons.
- Cookbook home · Landing page and topic index.
Home.py - Page discovery · Discovers ordered scripts in pages/.
pages/13_Navigation.py - Text and Markdown
pages/01_Text_and_Markdown.py - Input widgets · Widgets return current values during each rerun.
pages/02_Input_Widgets.py - Layouts
pages/03_Layouts.py - Data display
pages/04_Data_Display.py - Charts
pages/05_Charts.py - File and media handling
pages/06_File_Handling.py - Status and messages
pages/08_Status_and_Messages.py - Stateful patterns · Session state, forms, and caching cross rerun boundaries.
pages/09_Session_State.py - Chat elements
pages/12_Chat_Elements.py - Authentication example · Demonstrates login behavior with Streamlit session-state patterns.
pages/14_Authentication.py
Guessing game
Standalone stateful Streamlit app.
- Guess game · Standalone multi-stage interactive game.
game.py - Game session state · Retains username, progress, and restart state across reruns.
game.py - Random challenge stages · Number guessing and pattern challenges lead to success or restart.
game.py
Other components
- Dependencies · Declares the Python and Streamlit runtime dependencies.
requirements.txt - Streamlit runtime · Serves apps and reruns the active script on interaction.
Connections 19
- Dependencies → Streamlit runtime: installs
- Streamlit runtime → Cookbook home: runs
- Streamlit runtime → Guess game: runs
- Cookbook home → Page discovery: uses
- Page discovery → Text and Markdown: discovers
- Page discovery → Input widgets: discovers
- Page discovery → Layouts: discovers
- Page discovery → Data display: discovers
- Page discovery → Charts: discovers
- Page discovery → File and media handling: discovers
- Page discovery → Status and messages: discovers
- Page discovery → Stateful patterns: discovers
- Page discovery → Chat elements: discovers
- Page discovery → Authentication example: discovers
- Input widgets → Streamlit runtime: widget reruns
- Stateful patterns → Streamlit runtime: uses session and cache
- Guess game → Game session state: maintains
- Game session state → Random challenge stages: drives progress
- Random challenge stages → Guess game: reruns for next state