Mesop
Use this skill to build, debug, and deploy Mesop applications. Mesop is a Python-native UI framework that enables developers to build web apps without writing frontend code (HTML/CSS/JS).
Quick Triage
- Use this skill for pure Python web UIs, especially for AI/ML demos and internal tools.
- Do NOT use this skill if the user specifically requests a different Python framework (Streamlit, Gradio, Solara) unless they are asking for a comparison or migration.
- Do NOT use this skill for general Flask/FastAPI backend development unless it's specifically about mounting a Mesop app.
Workflow
- Setup: Install
mesop and create main.py.
- Define Page: Use
@me.page(path="/") to define the entry point.
- Define State: Create a
@me.stateclass to hold session state (must be serializable).
- Create Components: Build the UI tree using
me.box, me.text, me.input, etc.
- Handle Events: Write event handler functions (regular or generator) to update state.
- Style: Apply styles using
me.Style (flexbox/grid) for layout and appearance.
- Deploy: Deploy to Cloud Run, Docker, or Hugging Face Spaces.
Essential Patterns
Standard Import
Always use the standard alias:
import mesop as me
import mesop.labs as mel # For labs components like chat
State Management
State is session-scoped and must be serializable.
@me.stateclass
class State:
count: int = 0
input_value: str = "" # Immutable default
# items: list[str] = field(default_factory=list) # Mutable default pattern
Accessing State: state = me.state(State) inside components or event handlers.
Event Handlers
- Regular: Run to completion, then update UI.
- Generator:
yield to stream UI updates (e.g., loading states, LLM streaming). MUST yield at the end.
- Async: Use
async def and await for concurrent operations.
Component Composition
Use with blocks for content components (parents):
with me.box(style=me.Style(display="flex")):
me.text("Child 1")
me.button("Child 2")
Key Usage
Use key to identify components for:
- Resetting state (change key to re-render)
- Focus management (
me.focus_component)
- Scroll targeting (
me.scroll_into_view)
- Reusing event handlers (access
e.key)
Common Pitfalls
- Closure Variables: Do NOT rely on closure variables in event handlers; they may be stale. Use
key or state instead.
- Input Race Conditions: Avoid setting
value on inputs unless necessary. Use on_blur instead of on_input for performance, or track "initial" vs "current" value if bidirectional binding is needed.
- Mutable Defaults: Never use mutable types (list, dict) as default values in
@me.stateclass. Use dataclasses.field(default_factory=...).
- Global State: Global variables are shared across ALL users. Use
@me.stateclass for per-session state.
Reference Map
- Core Patterns:
references/core-patterns.md (State, Events, Streaming, Navigation)
- Components:
references/components-reference.md (API reference for all components)
- Styling & Layouts:
references/styling-and-layouts.md (CSS-in-Python, Flexbox, Grid, Theming)
- Deployment:
references/deployment-and-config.md (Cloud Run, Docker, Config, Security)
- Web Components:
references/web-components.md (Custom JS integration, Lit)
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: mesop3description: Build Python-native web apps with Mesop. Triggers when users want to build, debug, or deploy Mesop applications, including AI chat interfaces, internal tools, and ML demos. Use when this capability is needed.4---56# Mesop78Use this skill to build, debug, and deploy **Mesop** applications. Mesop is a Python-native UI framework that enables developers to build web apps without writing frontend code (HTML/CSS/JS).910## Quick Triage1112- Use this skill for **pure Python** web UIs, especially for AI/ML demos and internal tools.13- **Do NOT** use this skill if the user specifically requests a different Python framework (Streamlit, Gradio, Solara) unless they are asking for a comparison or migration.14- **Do NOT** use this skill for general Flask/FastAPI backend development unless it's specifically about mounting a Mesop app.1516## Workflow17181. **Setup**: Install `mesop` and create `main.py`.192. **Define Page**: Use `@me.page(path="/")` to define the entry point.203. **Define State**: Create a `@me.stateclass` to hold session state (must be serializable).214. **Create Components**: Build the UI tree using `me.box`, `me.text`, `me.input`, etc.225. **Handle Events**: Write event handler functions (regular or generator) to update state.236. **Style**: Apply styles using `me.Style` (flexbox/grid) for layout and appearance.247. **Deploy**: Deploy to Cloud Run, Docker, or Hugging Face Spaces.2526## Essential Patterns2728### Standard Import29Always use the standard alias:30```python31import mesop as me32import mesop.labs as mel # For labs components like chat33```3435### State Management36State is session-scoped and must be serializable.37```python38@me.stateclass39class State:40 count: int = 041 input_value: str = "" # Immutable default42 # items: list[str] = field(default_factory=list) # Mutable default pattern43```44**Accessing State:** `state = me.state(State)` inside components or event handlers.4546### Event Handlers47- **Regular**: Run to completion, then update UI.48- **Generator**: `yield` to stream UI updates (e.g., loading states, LLM streaming). **MUST** yield at the end.49- **Async**: Use `async def` and `await` for concurrent operations.5051### Component Composition52Use `with` blocks for content components (parents):53```python54with me.box(style=me.Style(display="flex")):55 me.text("Child 1")56 me.button("Child 2")57```5859### Key Usage60Use `key` to identify components for:61- Resetting state (change key to re-render)62- Focus management (`me.focus_component`)63- Scroll targeting (`me.scroll_into_view`)64- Reusing event handlers (access `e.key`)6566## Common Pitfalls6768- **Closure Variables**: Do NOT rely on closure variables in event handlers; they may be stale. Use `key` or state instead.69- **Input Race Conditions**: Avoid setting `value` on inputs unless necessary. Use `on_blur` instead of `on_input` for performance, or track "initial" vs "current" value if bidirectional binding is needed.70- **Mutable Defaults**: Never use mutable types (list, dict) as default values in `@me.stateclass`. Use `dataclasses.field(default_factory=...)`.71- **Global State**: Global variables are shared across ALL users. Use `@me.stateclass` for per-session state.7273## Reference Map7475- **Core Patterns**: `references/core-patterns.md` (State, Events, Streaming, Navigation)76- **Components**: `references/components-reference.md` (API reference for all components)77- **Styling & Layouts**: `references/styling-and-layouts.md` (CSS-in-Python, Flexbox, Grid, Theming)78- **Deployment**: `references/deployment-and-config.md` (Cloud Run, Docker, Config, Security)79- **Web Components**: `references/web-components.md` (Custom JS integration, Lit)8081---82> Converted and distributed by [TomeVault](https://tomevault.io/claim/outlinedriven) — claim your Tome and manage your conversions.83<!-- tomevault:4.0:skill_md:2026-04-13 -->