agilab-streamlit-pages

Streamlit page authoring patterns for AGILAB (session_state safety, keys, rerun, UX).

⭐3stars🔀1forks📁View on GitHub🕐Updated Jan 9, 2026⬇️2downloads

When & Why to Use This Skill

This Claude skill provides standardized authoring patterns and best practices for developing Streamlit pages within the AGILAB framework. It optimizes the development process by enforcing session state safety, proper widget key management, and modern UX patterns, ensuring the creation of robust, crash-resistant Python web applications.

Use Cases

  • Safe Session State Management: Preventing runtime crashes by using 'setdefault' patterns to initialize state before widget creation.
  • Widget Key Hygiene: Implementing namespaced and stable keys (e.g., page_id:widget_name) to avoid duplicate key errors and ensure state persistence.
  • State Reset Implementation: Using versioned key patterns or gated reruns to safely reset widget values without interrupting the user flow.
  • API Compliance: Ensuring the use of modern Streamlit functions like 'st.rerun()' instead of deprecated experimental versions for better stability.
  • UI/UX Optimization: Following recommended rendering sequences (Initialize -> Render -> Compute) to maintain a clean separation of concerns in page logic.
nameagilab-streamlit-pages
descriptionStreamlit page authoring patterns for AGILAB (session_state safety, keys, rerun, UX).
licenseBSD-3-Clause (see repo LICENSE)
updated2026-01-09

Streamlit Pages Skill (AGILAB)

Use this skill when editing:

  • src/agilab/AGILAB.py
  • src/agilab/pages/*.py
  • src/agilab/apps-pages/*/src/*/*.py

Session State Rules (Avoid Common Crashes)

  • Never assign st.session_state["k"] = … after a widget with key="k" was created.

    • Prefer st.session_state.setdefault("k", default) before the widget.
    • Or use widget return values and compute derived state separately.
  • If you need to “reset” a widget value:

    • Use a different key (versioned key pattern), or
    • Gate the reset behind a rerun and only mutate state before widget creation.
  1. Initialize defaults with setdefault at the top of the page.
  2. Render widgets.
  3. Read values from widgets, compute derived state, store under different keys.

Rerun API

  • Do not use st.experimental_rerun(); use st.rerun().

Key Hygiene

  • Every widget must have a stable, unique key.
  • Prefer namespaced keys: f\"{page_id}:df_files\", not "df_files".