A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: editing pass (#2501)
Akshay Agrawale2dedaff1abe
diff --git a/README.md b/README.mdindex 98ab33238b..c9d780ce59 100644--- a/README.md+++ b/README.md@@ -62,10 +62,12 @@ memory, eliminating hidden state.<a name="expensive-notebooks"></a>-**Compatible with expensive notebooks.** marimo lets you configure the runtime-to be lazy, marking affected cells as stale instead of automatically running-them. This gives you guarantees on program state while preventing accidental-execution of expensive cells.+**Compatible with expensive notebooks.** marimo lets you [configure the runtime+to be+lazy](https://docs.marimo.io/guides/configuration/runtime_configuration.html),+marking affected cells as stale instead of automatically running them. This+gives you guarantees on program state while preventing accidental execution of+expensive cells.**Synchronized UI elements.** Interact with [UIelements](https://docs.marimo.io/guides/interactivity.html) like [sliders](https://docs.marimo.io/api/inputs/slider.html#slider),diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.cssindex c5f108349a..fffc42862a 100644--- a/docs/_static/css/custom.css+++ b/docs/_static/css/custom.css@@ -7,6 +7,11 @@ body .page {--api-font-size: var(--font-size--normal) !important;}+/* Slightly wider than default for our WASM examples. */+.content {+ width: 48em;+}+.sidebar-brand-text {font-family: "CalSans";color: #1c7362;@@ -51,6 +56,10 @@ iframe.demo.large {}iframe.demo.xlarge {+ height: 900px;+}++iframe.demo.xxlarge {height: 1200px;}diff --git a/docs/_static/docs-app-config.png b/docs/_static/docs-app-config.pngnew file mode 100644index 0000000000..c19a597337Binary files /dev/null and b/docs/_static/docs-app-config.png differdiff --git a/docs/_static/docs-module-reloading-lazy.mp4 b/docs/_static/docs-module-reloading-lazy.mp4new file mode 100644index 0000000000..a0d046959cBinary files /dev/null and b/docs/_static/docs-module-reloading-lazy.mp4 differdiff --git a/docs/_static/docs-module-reloading.mp4 b/docs/_static/docs-module-reloading.mp4new file mode 100644index 0000000000..9f27a0242dBinary files /dev/null and b/docs/_static/docs-module-reloading.mp4 differdiff --git a/docs/_static/docs-runtime-config.mp4 b/docs/_static/docs-runtime-config.mp4new file mode 100644index 0000000000..031e700013Binary files /dev/null and b/docs/_static/docs-runtime-config.mp4 differdiff --git a/docs/_static/docs-user-config.mp4 b/docs/_static/docs-user-config.mp4new file mode 100644index 0000000000..0df2eddf21Binary files /dev/null and b/docs/_static/docs-user-config.mp4 differdiff --git a/docs/examples.md b/docs/examples.mdindex 24af3ca676..c623945843 100644--- a/docs/examples.md+++ b/docs/examples.md@@ -1,11 +1,12 @@# Examples-We have a large library of examples in-[our repo](https://github.com/marimo-team/marimo/tree/main/examples). Each-example encapsulates its own Python dependencies, making it easy to run.+We have a large [library of+examples](https://github.com/marimo-team/marimo/tree/main/examples) in our+repo. Each example [encapsulates its own Python dependencies in a package+sandbox](/guides/editor_features/package_management.md), making it easy to run.We've deployed some of these examples at our [publicgallery](https://marimo.io/@public).-We spotlight projects from the community each week; check out our+We spotlight projects from the community each week on [our Twitter](https://x.com/marimo_io); check out our[spotlights repo](https://github.com/marimo-team/spotlights) for a runningarchive, with links to notebooks.diff --git a/docs/getting_started/index.md b/docs/getting_started/index.mdindex 995f804e59..c5f4fd49ec 100644--- a/docs/getting_started/index.md+++ b/docs/getting_started/index.md@@ -86,7 +86,7 @@ Having installation issues? Reach out to us [at GitHub](https://github.com/marimmarimo tutorial --help```-## Notebooks+## Edit notebooksCreate and edit notebooks with `marimo edit`.@@ -106,7 +106,7 @@ marimo edit your_notebook.py(If `your_notebook.py` doesn't exist, marimo will create a blank notebooknamed `your_notebook.py`.)-## Apps+## Deploy as appsUse `marimo run` to serve your notebook as an app, with Python code hidden anduneditable.@@ -115,19 +115,35 @@ uneditable.marimo run your_notebook.py```-## Convert Jupyter notebooks+## Convert from Jupyter to marimo-Automatically translate Jupyter notebooks to marimo notebooks with `marimo convert`:+Automatically convert Jupyter notebooks to marimo notebooks with `marimo convert`:```bash-marimo convert your_notebook.ipynb > your_notebook.py+marimo convert your_notebook.ipynb -o your_notebook.py```-Because marimo is different from traditional notebooks, your converted notebook-will likely have errors that you'll need to fix. marimo will guide you through-fixing them when you open it with `marimo edit`.+Then open the notebook with `marimo edit your_notebook.py`-## GitHub Copilot+:::{admonition} Disable autorun on startup+:class: tip+++marimo automatically runs notebooks when they are opened. If this+is a problem for you (not all Jupyter notebooks are designed to be run on+startup), you can disable autorun on startup via [user configuration](https://docs.marimo.io/guides/configuration.html#user-configuration).++1. Type `marimo config show` to get the location of your config file.+2. If no config file exists, create it at `~/.marimo.toml` or `$XDG_CONFIG_HOME/marimo/marimo.toml`.+3. Update your config to include the following:++```toml+[runtime]+auto_instantiate = false+```+:::++## GitHub Copilot and AI AssistantThe marimo editor natively supports [GitHub Copilot](https://copilot.github.com/),an AI pair programmer, similar to VS Code.@@ -138,7 +154,10 @@ _Get started with Copilot_:2. Enable Copilot via the settings menu in the marimo editor._Note_: Copilot is not yet available in our conda distribution; please install-marimo using `pip` if you need Copilot.+marimo from `PyPI` if you need Copilot.++marimo also comes with support for [other copilots](https://docs.marimo.io/guides/editor_features/ai_completion.html#codeium-copilot),+and a built-in [AI assistant](https://docs.marimo.io/guides/editor_features/ai_completion.html#generate-code-with-our-ai-assistant) that helps you write code.## VS Code extensiondiff --git a/docs/guides/coming_from/jupyter.md b/docs/guides/coming_from/jupyter.mdindex fbec63d72f..4060d8a852 100644--- a/docs/guides/coming_from/jupyter.md+++ b/docs/guides/coming_from/jupyter.md@@ -1,7 +1,34 @@-## Coming from Jupyter+# Coming from Jupyter-If you're coming from Jupyter, this guide will help you get started-with marimo. Fun fact: the guide is itself a marimo notebook!+If you're coming from Jupyter, here are a few tips to help you adapt to marimo+notebooks.-<iframe src="https://marimo.app/l/z0aerp?embed=true" class="demo xlarge" frameBorder="0">+## Runtime configuration++You can [configure marimo's runtime](/guides/configuration/runtime_configuration.md) to not+autorun on startup or on cell execution.++Even when autorun is disabled, your notebook remains a directed graph, with+marimo eliminating hidden state for you and marking cells as stale.++## HTML snapshots++marimo stores notebooks as Python, not JSON. This lets you version notebooks+with git, [execute them as scripts](/guides/scripts.md), and import named+cells into other Python files. However, it does mean that your notebook outputs+(e.g., plots) are not stored in the file.++If you'd like to keep a visual record of your notebook work, [enable+the "Auto-download as HTML" setting](/guides/configuration), which will+periodically snapshot your notebook as HTML to a `__marimo__` folder in the+notebook directory.+++## Interactive guide++This guide contains additional tips to help you adapt to marimo. Fun fact: the+guide is itself a marimo notebook!+++<iframe src="https://marimo.app/l/z0aerp?embed=true" class="demo xxlarge" frameBorder="0"></iframe>diff --git a/docs/guides/configuration.md b/docs/guides/configuration/index.mdsimilarity index 66%rename from docs/guides/configuration.mdrename to docs/guides/configuration/index.mdindex 7ffaed964d..049d151ec0 100644--- a/docs/guides/configuration.md+++ b/docs/guides/configuration/index.md@@ -1,7 +1,17 @@# Configuration+```{eval-rst}+.. toctree::+ :maxdepth: 2+ :hidden:++ runtime_configuration+```+marimo offers two types of configuration: User Configuration and App Configuration. Both can be easily managed through the Settings menu in the marimo editor.+<img align="right" src="/_static/docs-app-config.png" width="300px"/>+## App ConfigurationApp Configuration is specific to each notebook and is stored in the `notebook.py` file. This allows you to customize various aspects of your notebook, including:@@ -9,40 +19,53 @@ App Configuration is specific to each notebook and is stored in the `notebook.py- Notebook width- Notebook title- Custom CSS-- Additional app-specific settings-- _and more_+- Automatically download HTML snapshots++Configure these settings through the notebook menu.++<br clear="left"/>## User Configuration-User Configuration applies globally across all marimo notebooks and is stored in a `.marimo.toml` file. marimo searches for this file in the following order:+User Configuration applies globally across all marimo notebooks and is stored+in a `.marimo.toml` file.++While you can edit the `.marimo.toml` file directly, we recommend using the+marimo UI for a more user-friendly experience.++<video controls width="100%" height="100%" align="center" src="/_static/docs-user-config.mp4"> </video>++You can customize the following:++- [Runtime](/guides/configuration/runtime_configuration.md), including whether notebooks autorun+- [Hotkeys](/guides/editor_features/hotkeys.md)+- Completion (auto-completion, AI copilot, etc.)+- Display (theme, font size, output placement, etc.)+- Autosave+- Package management+- Server settings+- VIM keybindings+- Formatting settings+- [AI assistance](/guides/editor_features/ai_completion.md)++### User configuration file++marimo searches for the `.marimo.toml` file in the following order:1. Current directory2. Parent directories (moving up the tree)3. Home directory (`~/.marimo.toml`)4. [XDG](https://xdgbasedirectoryspecification.com/) directory (`~/.config/marimo/marimo.toml` or `$XDG_CONFIG_HOME/marimo/marimo.toml`)-If no `.marimo.toml` file is found, marimo creates a default one in your home directory.+If no `.marimo.toml` file is found, marimo creates one for you in an XDG config+compliant way.-While you can edit the `.marimo.toml` file directly, we recommend using the marimo UI for a more user-friendly experience. To view your current configuration and locate the config file, run:+View your current configuration and locate the config file with:```bashmarimo config show```-You can customize:--- [Runtime configuration](/guides/runtime_configuration.md)-- [Hotkeys](/guides/editor_features/hotkeys.md)-- Completion settings (auto-completion, AI copilot, etc.)-- Display settings (theme, font size, output placement, etc.)-- Autosave settings-- Package management preferences-- Server settings-- VIM keybindings-- Formatting settings-- [AI settings](/guides/editor_features/ai_completion.md)-- _and more_-## Environment VariablesThere are some configuration options that can be set via environment variables. These are:diff --git a/docs/guides/configuration/runtime_configuration.md b/docs/guides/configuration/runtime_configuration.mdnew file mode 100644index 0000000000..d959f388b3--- /dev/null+++ b/docs/guides/configuration/runtime_configuration.md@@ -0,0 +1,94 @@+# Runtime configuration++Through the notebook settings menu, you can configure how and when marimo+runs cells.++<video controls width="100%" height="100%" align="center" src="/_static/docs-runtime-config.mp4"> </video>++++## On startup++By default, marimo notebooks run automatically on startup; just how the command++```+python main.py+```++executes a script,++```+marimo edit notebook.py+```++executes the notebook.++Disable this behavior by unchecking "Autorun on startup".++_When sharing a notebook as an app with `marimo run`, this setting has+no effect._++## On cell change++By default, when a cell is run or a UI element is interacted with, marimo+automatically runs cells that reference any of its variables. **You can disable+automatic execution of cell's descendants in the notebook settings menu by+setting `"On cell change"` to `"lazy"`.**++When the runtime is lazy, running a cell marks affected cells as stale but+doesn't automatically run them. Lazy evaluation means cells are only run when+their outputs are needed. If you run a cell that has stale ancestors, those+ancestors will also run to make sure your cell doesn't use stale inputs. You+can always click the notebook run button or use the keyboard shortcut to run+all stale cells.++**When should I use lazy evaluation?** Choosing the lazy runtime can be helpful+when working on notebooks with expensive cells.++:::{admonition} Tip: speed up expensive notebooks with marimo's smart caching+:class: tip++In addition to runtime configuration, marimo also provides [opt-in caching](/guides/caching.md)+to help you work with expensive or side-effectful notebooks. marimo's+can cache expensive functions in memory and expensive blocks of code to disk,+letting you skip entire sections of your code and automatically loading+variables in memory on notebook startup. Read our [caching+guide](/api/caching.md) to learn more.+:::++_When sharing a notebook as an app with `marimo run`, this setting has+no effect._++## On module change++When module autoreloading is enabled, marimo automatically runs cells when you+edit Python files. Based on static analysis, the reloader only runs cells+affected by your edits. The reloader is recursive, meaning that marimo tracks+modifications for modules imported by your notebook's imported modules too.++:::{admonition} Why autoreload?+:class: tip++Autoreloading enables a workflow that many developers find+productive: develop complex logic in Python modules, and use the marimo+notebook as a DAG or main script that orchestrates your logic.+:::++Autoreloading comes in two types:++1. **autorun**: automatically re-runs cells affected by module modification.+++<figure>+<video controls loop width="100%" height="100%" align="center" src="/_static/docs-module-reloading.mp4"> </video>+<figcaption align="center">When set to autorun, marimo's reloader automatically run cells when you edit Python files.</figcaption>+</figure>+++2. **lazy**: marks cells affected by module+ modifications as stale, letting you know which cells need to be re-run.++<figure>+<video controls loop width="100%" height="100%" align="center" src="/_static/docs-module-reloading-lazy.mp4"> </video>+<figcaption align="center">When set to lazy, marimo's reloader marks cells as stale when you edit Python files.</figcaption>+</figure>diff --git a/docs/guides/index.md b/docs/guides/index.mdindex 6cde8809a4..1af5b9bc73 100644--- a/docs/guides/index.md+++ b/docs/guides/index.md@@ -22,7 +22,7 @@statewasmexporting- configuration+ configuration/indextroubleshootingdeploying/index```@@ -49,7 +49,7 @@ These guides cover marimo's core concepts.| {doc}`state` | Mutable, reactive state || {doc}`wasm` | Create notebooks in our online playground! || {doc}`exporting` | Exporting notebooks to HTML and flat scripts |-| {doc}`configuration` | User and app configuration |+| {doc}`configuration/index` | User and app configuration || {doc}`deploying/index` | Deploying marimo notebooks and apps |```{admonition} Learn by doing!diff --git a/docs/guides/overview.md b/docs/guides/overview.mdindex 0552e42039..8aa7f26490 100644--- a/docs/guides/overview.md+++ b/docs/guides/overview.md@@ -33,7 +33,7 @@ variables defined by that cell._ This is reactive execution.If you don't want cells to run automatically, the runtime can beconfigured to be lazy, only running cells when you ask for them to be run andmarking affected cells as stale. Learn more in the-[runtime configuration guide](/guides/runtime_configuration.md)+[runtime configuration guide](/guides/configuration/runtime_configuration.md)```**Execution order.**diff --git a/docs/guides/reactivity.md b/docs/guides/reactivity.mdindex 22738284ee..c99da6ea21 100644--- a/docs/guides/reactivity.md+++ b/docs/guides/reactivity.md@@ -22,7 +22,7 @@ When a cell is run, marimo automatically runs all other cells thatThe runtime can be configured to be lazy, only running cells when you ask forthem to be run and marking affected cells as stale, instead of automaticallyrunning them. Learn more in the-[runtime configuration guide](/guides/runtime_configuration.md)+[runtime configuration guide](/guides/configuration/runtime_configuration.md)```## References and definitions@@ -164,53 +164,9 @@ makes marimo easy to understand and encourages well-organized notebook code.## Runtime configurationThrough the notebook settings menu, you can configure how and when marimo runs-cells.--### On cell change: disabling automatic execution--You can disable automatic execution of cells by configuring the runtime to be-**lazy**: the lazy runtime only runs cells when you ask for them to be run,-marking downstream cells as stale instead of running them.--When your notebook has expensive cells or dangerous side-effects, choosing lazy-execution can be key to having a good experience in marimo.--### On startup: disabling autorun--By default, marimo notebooks run automatically on startup; just how the command--```-python main.py-```--executes a script,--```-marimo edit notebook.py-```--executes the notebook. You can disable autorun on startup in the notebook-settings.--<a href="module-change"></a>--### On module change: autoreloading--When module autoreloading is enabled,-marimo tracks when Python modules used by your notebook are changed and reloads-them so you can use the latest version of your code.-This works recursively, meaning that marimo tracks modifications for modules-imported by your notebook's imported modules too.--Autoreloading comes in two types:--- "lazy": automatically marks cells affected by module- modifications as stale, letting you know which cells need to be re-run.-- "autorun": automatically re-runs cells affected by module modification.--**Why autoreload?** Autoreloading enables a workflow that many developers find-productive: develop complex logic in Python modules, and use the marimo-notebook as a DAG or main script that orchestrates your logic.+cells. In particular, you can disable autorun on startup, disable autorun+on cell execution, and enable a powerful module autoreloader. Read our+[runtime configuration guide](/guides/configuration/runtime_configuration.md) to learn more.## Disabling cellsdiff --git a/docs/guides/runtime_configuration.md b/docs/guides/runtime_configuration.mddeleted file mode 100644index b4d00db3df..0000000000--- a/docs/guides/runtime_configuration.md+++ /dev/null@@ -1,50 +0,0 @@-# Runtime configuration--Through the notebook settings menu, you can configure how and when marimo-runs cells.--## On startup--By default, marimo runs notebooks automatically on startup. Disable-this by unchecking "Autorun on startup".--_When sharing a notebook as an app with `marimo run`, this setting has-no effect._--## On cell change--By default, when a cell is run or a UI element is interacted with, marimo-automatically runs cells that reference any of its variables. **You can disable-automatic execution of cell's descendants in the notebook settings menu by-setting `"On cell change"` to `"lazy"`.**--When the runtime is lazy, running a cell marks affected cells as stale but-doesn't automatically run them. Lazy evaluation means cells are only run when-their outputs are needed. If you run a cell that has stale ancestors, those-ancestors will also run to make sure your cell doesn't use stale inputs. You-can always click the notebook run button or use the keyboard shortcut to run-all stale cells.--**When should I use lazy evaluation?** Choosing the lazy runtime can be helpful-when working on notebooks with expensive cells.--_When sharing a notebook as an app with `marimo run`, this setting has-no effect._--## On module change--Enable module autoreloading via the settings icon (top right). When enabled,-when Python modules that your notebook imports are modified, marimo reloads-those modifications so you can use the latest version of your code. This works-recursively, meaning that marimo tracks modifications for modules imported-by your notebook's imported modules too.--Autoreloading comes in two types:--- "lazy": automatically marks cells affected by module- modifications as stale, letting you know which cells need to be re-run.-- "autorun": automatically re-runs cells affected by module modification.--**Why autoreload?** Autoreloading enables a workflow that many developers find-productive: develop complex logic in Python modules, and use the marimo-notebook as a DAG or main script that orchestrates your logic.diff --git a/docs/guides/scripts.md b/docs/guides/scripts.mdindex 18d1fc93f2..c3e93aab16 100644--- a/docs/guides/scripts.md+++ b/docs/guides/scripts.md@@ -14,9 +14,14 @@ up in your terminal.You can pass arguments to your notebook at the command-line: seethe [docs page on CLI args](/api/cli_args.md) to learn more.-```{admonition} Future plans+++:::{admonition} Producing notebook outputs:class: note-In the future, we may give you the option to generate a PDF or HTML of the cell-outputs when running as a script.+To run as a script while also producing HTML of the noteobok outputs, use++```bash+marimo export html notebook.py -o notebook.html```+:::diff --git a/docs/guides/sql.md b/docs/guides/sql.mdindex d37944b566..4202027276 100644--- a/docs/guides/sql.md+++ b/docs/guides/sql.md@@ -1,18 +1,32 @@# SQL-With marimo, you can mix-and-match both **Python and SQL**. To create a SQL-cell, you first need to install additional dependencies, including-[duckdb](https://duckdb.org/). Install dependencies with+marimo lets you can mix and match **Python and SQL**: Use SQL to query+Python dataframes (or databases like SQLite and Postgres), and get+the query result back as a Python dataframe.++To create a SQL cell, you first need to install additional dependencies,+including [duckdb](https://duckdb.org/):```bashpip install marimo[sql]```-This will enable SQL cells in your notebook. Once you've installed-the dependencies, you can create a SQL cell by right-clicking an **Add Cell**-button and choosing "SQL cell", by converting an empty cell to SQL via the cell-context menu, or via the SQL button that appears when you mouse hover at the-bottom of your notebook.+## Example++In this example notebook, we have a Pandas dataframe and a SQL cell+that queries it. Notice that the query result is returned as a Python+dataframe and usable in subsequent cells.++<iframe src="https://marimo.app/l/38dxkd?embed=true" class="demo xlarge" height="800px" frameBorder="0"> </iframe>++## Creating SQL cells++You can create SQL cells in one of three ways:++1. **Right-click** an "add cell" button ("+" icon) next to a cell and choose "SQL cell"+2. Convert a empty cell to SQL via the cell+ context menu+3. Click the SQL button that appears at the bottom of the notebook<div align="center"><figure>@@ -21,15 +35,22 @@ bottom of your notebook.</figure></div>-This creates a "**SQL**" cell for you, while in reality this is actually Python code. Since we store marimo files as pure Python files, the translated code looks like:+This creates a "**SQL**" cell for you, which is syntactic sugar for Python code.+The underlying code looks like:```pythonoutput_df = mo.sql(f"SELECT * FROM my_table LIMIT {max_rows.value}")```-Notice that we have an **`output_df`** variable in the cell. This is a resulting Polars DataFrame (if you have `polars` installed) or a Pandas DataFrame (if you don't). One of them must be installed in order to interact with the SQL result.+Notice that we have an **`output_df`** variable in the cell. This contains+the query result, and is a Polars DataFrame (if you have `polars` installed) or+a Pandas DataFrame (if you don't). One of them must be installed in order to+interact with the query result.-The SQL statement itself is an formatted string (f-string), so this means they can contain any valid Python code, such as the values of UI elements. This means your SQL statement and results can be reactive! 🚀+The SQL statement itself is an f-string, letting you+interpolate Python values into the query with `{}`. In particular, this means+your SQL queries can depend on the values of UI elements or other Python values,+and they are fit into marimo's reactive dataflow graph.## Reference a local dataframediff --git a/marimo/_cli/convert/commands.py b/marimo/_cli/convert/commands.pyindex f7c782a1b3..cd139f30ac 100644--- a/marimo/_cli/convert/commands.py+++ b/marimo/_cli/convert/commands.py@@ -34,11 +34,11 @@ def convert(Example usage:- marimo convert your_nb.ipynb > your_nb.py+ marimo convert your_nb.ipynb -o your_nb.pyor- marimo convert your_nb.md > your_nb.py+ marimo convert your_nb.md -o your_nb.pyJupyter notebook conversion will strip out all outputs. Markdown cellconversion with occur on the presence of `\`\`\`{python}` code blocks.