Mesop Features
Declarative UI
import mesop as me
@me.page(path="/")
def home():
me.text("Hello World", type="headline-4")
me.button("Click me", on_click=handle_click)
me.input(label="Enter text", on_blur=handle_input)
def handle_click(e: me.ClickEvent):
state = me.state(AppState)
state.count += 1
@me.stateclass
class AppState:
count: int = 0
text: str = ""Built-in AI Chat Component
import mesop.labs as mel
def transform(prompt: str, history: list) -> str:
# Your LLM call here
return call_llm(prompt)
@me.page(path="/chat")
def chat_page():
mel.chat(
transform,
title="AI Assistant",
bot_user="Assistant",
)This gives you a complete chat UI with:
- Message history
- Streaming responses
- User/bot avatars
- Input field with send button
State Management
@me.stateclass
class State:
query: str = ""
results: list[str] = []
loading: bool = False
def search(e: me.ClickEvent):
state = me.state(State)
state.loading = True
yield # Update UI to show loading
state.results = perform_search(state.query)
state.loading = False
yield # Update UI with resultsComponents
| Component | Usage |
|---|---|
me.text() |
Text display |
me.button() |
Clickable button |
me.input() |
Text input |
me.textarea() |
Multi-line input |
me.select() |
Dropdown |
me.slider() |
Range slider |
me.checkbox() |
Toggle |
me.table() |
Data table |
me.markdown() |
Render Markdown |
me.plot() |
Matplotlib charts |
mel.chat() |
Full chat interface |
Hot Reload
Edit your Python file and the UI updates instantly — no restart needed.
Multi-Page Apps
@me.page(path="/")
def home(): ...
@me.page(path="/chat")
def chat(): ...
@me.page(path="/dashboard")
def dashboard(): ...FAQ
Q: What is Mesop? A: Mesop is Google's open-source Python UI framework with 6,500+ GitHub stars for rapidly building AI demos and internal tools with declarative components, built-in chat UI, and hot reload.
Q: How is Mesop different from Streamlit or Gradio? A: Mesop uses a declarative component model (like React) instead of Streamlit's top-to-bottom rerun model. It has better state management and a built-in AI chat component. Gradio is focused on ML model demos; Mesop is for general-purpose AI apps.
Q: Is Mesop free? A: Yes, open-source under Apache-2.0.