streamlit

Streamlit

Specific best practices and architectural patterns when working with Streamlit.

Details

Language / Topic
pythonPython
Category
framework

Rules

balanced

Streamlit

- Build Streamlit apps with one widget per logical block — use `st.columns()` for layout, `st.session_state` for persistence across reruns. Cache expensive computations with `@st.cache_data` (serializable) or `@st.cache_resource` (connections, models).

Streamlit

- Build Streamlit apps with one widget per logical block — use `st.columns()` for layout, `st.session_state` for persistence across reruns. Cache expensive computations with `@st.cache_data` (serializable) or `@st.cache_resource` (connections, models).
- Use `st.form()` to batch inputs and prevent reruns on every widget change. Organize multi-page apps with `st.navigation()` or the `pages/` directory convention. Use `st.fragment` decorator for partial reruns of expensive sections. Never mutate session_state inside callbacks — return values and assign in the main flow.