streamlit-to-marimo
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConverting Streamlit Apps to Marimo
将Streamlit应用转换为Marimo
For general marimo notebook conventions (cell structure, PEP 723 metadata, output rendering, , variable naming, etc.), refer to the skill. This skill focuses specifically on mapping Streamlit concepts to marimo equivalents.
marimo checkmarimo-notebook有关marimo笔记本的通用规范(单元格结构、PEP 723元数据、输出渲染、、变量命名等),请参考技能。本技能专门聚焦于将Streamlit概念映射为marimo等效实现。
marimo checkmarimo-notebookSteps
步骤
-
Read the Streamlit app to understand its widgets, layout, and state management.
-
Create a new marimo notebook following theskill conventions. Add all dependencies the Streamlit app uses (pandas, plotly, altair, etc.) — but replace
marimo-notebookwithstreamlit. You should not overwrite the original file.marimo -
Map Streamlit components to marimo equivalents using the reference tables below. Key principles:
- UI elements are assigned to variables and their current value is accessed via .
.value - Cells that reference a UI element automatically re-run when the user interacts with it — no callbacks needed.
- UI elements are assigned to variables and their current value is accessed via
-
Handle conceptual differences in execution model, state, and caching (see below).
-
Runon the result and fix any issues.
uvx marimo check
-
阅读Streamlit应用代码,了解其组件、布局和状态管理逻辑。
-
按照技能规范创建新的marimo笔记本。添加Streamlit应用使用的所有依赖(pandas、plotly、altair等)——但要将
marimo-notebook替换为streamlit。请勿覆盖原文件。marimo -
参考下方对照表将Streamlit组件映射为marimo等效组件,核心原则:
- UI元素赋值给变量,通过访问其当前值。
.value - 引用了UI元素的单元格会在用户交互时自动重新运行——无需回调函数。
- UI元素赋值给变量,通过
-
处理执行模型、状态、缓存方面的概念差异(见下文说明)。
-
对转换后的文件执行,修复所有问题。
uvx marimo check
Widget Mapping Reference
组件映射对照表
Input Widgets
输入组件
| Streamlit | marimo | Notes |
|---|---|---|
| | |
| | Pass discrete values via |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | No dedicated time widget |
| | Use |
| | No dedicated color picker |
| | Use |
| | Returns a download link element |
| | Wraps any element so its value only updates on submit |
| Streamlit | marimo | 说明 |
|---|---|---|
| | |
| | 通过 |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | 无专门的时间组件 |
| | 使用 |
| | 无专门的颜色选择器 |
| | 触发高开销计算时使用 |
| | 返回下载链接元素 |
| | 包裹任意元素,仅在提交时更新其值 |
Display Elements
展示元素
| Streamlit | marimo | Notes |
|---|---|---|
| | |
| | Supports f-strings: |
| | marimo uses KaTeX; see |
| | |
| | DataFrames render as interactive marimo widgets natively; use |
| | Use |
| | |
| | |
| | |
| | |
| |
| Streamlit | marimo | 说明 |
|---|---|---|
| | |
| | 支持f-string: |
| | marimo使用KaTeX;参考 |
| | |
| | DataFrame默认渲染为交互式marimo组件;仅当需要无代码转换时使用 |
| | 如果需要行选择功能可使用 |
| | |
| | |
| | |
| | |
| |
Charts
图表
| Streamlit | marimo | Notes |
|---|---|---|
| | Use |
| | Use |
| | Use |
| Streamlit | marimo | 说明 |
|---|---|---|
| | 需要选择功能时使用 |
| | 需要选择功能时使用 |
| | 需要交互式matplotlib时使用 |
Layout
布局
| Streamlit | marimo | Notes |
|---|---|---|
| | Pass a list of elements |
| | Use |
| | Dict of |
| | Dict of |
| | |
| | |
| | |
| | Context manager |
| Streamlit | marimo | 说明 |
|---|---|---|
| | 传入元素列表 |
| | 使用 |
| | 传入字典 |
| | 传入字典 |
| | |
| | |
| | |
| | 上下文管理器 |
Key Conceptual Differences
核心概念差异
Execution Model
执行模型
Streamlit reruns the entire script top-to-bottom on every interaction. Marimo uses a reactive cell DAG — only cells that depend on changed variables re-execute.
- No need for — reactivity is automatic.
st.rerun() - No need for — structure cells so downstream cells naturally depend on upstream values.
st.stop()
Streamlit在每次交互时会从上到下重新运行整个脚本。Marimo使用响应式单元格DAG——仅依赖变更变量的单元格才会重新执行。
- 无需使用——响应式是自动生效的。
st.rerun() - 无需使用——合理组织单元格结构,让下游单元格自然依赖上游值即可。
st.stop()
State Management
状态管理
| Streamlit | marimo |
|---|---|
| Regular Python variables between cells |
Callback functions ( | Cells referencing |
| |
| Streamlit | marimo |
|---|---|
| 单元格之间的普通Python变量 |
回调函数 ( | 引用了 |
| |
Caching
缓存
| Streamlit | marimo |
|---|---|
| |
| |
@mo.cachefunctools.cache@mo.persistent_cache| Streamlit | marimo |
|---|---|
| |
| |
@mo.cachefunctools.cache@mo.persistent_cacheMulti-Page Apps
多页应用
Marimo offers two approaches for multi-page Streamlit apps:
- Single notebook with routing: Use with
mo.routesormo.nav_menuto build multiple "pages" (tabs/routes) inside one notebook.mo.sidebar - Multiple notebooks as a gallery: Run a folder of notebooks with to serve them as a gallery with navigation.
marimo run folder/
Marimo为多页Streamlit应用提供两种迁移方案:
- 单笔记本加路由:配合或
mo.nav_menu使用mo.sidebar,在单个笔记本内构建多个「页面」(标签页/路由)。mo.routes - 多笔记本作为画廊:使用运行一个文件夹内的笔记本,将它们作为带导航的应用画廊提供服务。
marimo run folder/
Deploying
部署
marimo features molab to host marimo apps instead of the streamlit community cloud. You can generate an "open in molab" button via the skill.
add-molab-badgemarimo提供molab服务来托管marimo应用,替代Streamlit社区云。你可以通过技能生成「在molab中打开」按钮。
add-molab-badgeCustom components
自定义组件
streamlit has a feature for custom components. These are not compatible with marimo. You might be able to generate an equivalent anywidget via the skill but discuss this with the user before working on that.
marimo-anywidgetStreamlit支持自定义组件,这些组件与marimo不兼容。你可以通过技能生成等效的anywidget,但在实施前请先与用户沟通确认。
marimo-anywidget