Skip to content

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.

docs: integrations guide (#1158)

Akshay Agrawale67b722a3357
diff --git a/docs/api/inputs/anywidget.md b/docs/api/inputs/anywidget.md
index 0144179e77..d6d77b364a 100644
--- a/docs/api/inputs/anywidget.md
+++ b/docs/api/inputs/anywidget.md
@@ -1,5 +1,8 @@
# AnyWidget
+Build custom UI plugins that hook into marimo's reactive
+execution engine by using [AnyWidget](https://anywidget.dev/).
+
[AnyWidget](https://anywidget.dev/) is a Python library and specification for creating custom Jupyter-compatible widgets. marimo supports AnyWidget, allowing you to import AnyWidget widgets or create your own custom widgets and use them in your notebooks and apps.
## Custom widget
@@ -56,7 +59,7 @@ widget.value
# pip install drawdata
from drawdata import ScatterWidget
-widget mo.ui.anywidget(ScatterWidget())
+widget = mo.ui.anywidget(ScatterWidget())
# In another cell, you can access the widget's value
widget.value
diff --git a/docs/api/miscellaneous.md b/docs/api/miscellaneous.md
index dfb9262783..752cf278a2 100644
--- a/docs/api/miscellaneous.md
+++ b/docs/api/miscellaneous.md
@@ -1,15 +1,10 @@
# Miscellaneous
-Use `mo.running_in_notebook()` to tell if Python is running in a marimo
-notebook.
```{eval-rst}
.. autofunction:: marimo.running_in_notebook
```
-Use `mo.defs` and `mo.refs` to get the global definitions and references of
-a cell.
-
```{eval-rst}
.. autofunction:: marimo.defs
```
diff --git a/docs/guides/editor_features.md b/docs/guides/editor_features.md
index bc08f68dbe..1d0ee616e9 100644
--- a/docs/guides/editor_features.md
+++ b/docs/guides/editor_features.md
@@ -82,6 +82,27 @@ Hit `Cmd/Ctrl+K` to open the command palette.
_Missing a command? File a
[GitHub issue](https://github.com/marimo-team/marimo/issues)._
+## Module autoreloading
+
+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:
+
+- "detect": 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.
+
+**Note:** Make sure the imported modules are in packages/folders with
+`__init__.py` files, otherwise marimo's detection may fail.
+
+**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.
+
## Export to static HTML
Export the current view your notebook to static HTML via the notebook
@@ -94,6 +115,13 @@ menu:
</figure>
</div>
+You can also export to HTML at the command-line:
+
+```bash
+marimo export html notebook.py -o notebook.html
+```
+
+
## Configuration
Click the settings icon in the top right to access important configuration
@@ -107,7 +135,7 @@ You can also enable GitHub Copilot from this menu.
</figure>
</div>
-A non-exhausted list of settings (for searchability):
+A non-exhausted list of settings:
- Vim keymaps
- Dark mode
@@ -116,6 +144,7 @@ A non-exhausted list of settings (for searchability):
- Editor font-size
- Formatting rules
- GitHub Copilot
+- Autoreloading/Hot-reloading
## Send feedback
diff --git a/docs/guides/index.md b/docs/guides/index.md
index 63cc59cc3f..e9ba3b5645 100644
--- a/docs/guides/index.md
+++ b/docs/guides/index.md
@@ -14,6 +14,7 @@
dataframes
plotting
state
+ integrating_with_marimo/index
apps
scripts
wasm
@@ -25,24 +26,25 @@
These guides cover marimo's core concepts.
-| | |
-| :------------------------- | :------------------------------------------------------ |
-| {doc}`overview` | An overview of basic concepts |
-| {doc}`reactivity` | How reactive execution works |
-| {doc}`interactivity` | Using interactive UI elements |
-| {doc}`coming_from_jupyter` | marimo for Jupyter users |
-| {doc}`outputs` | Markdown, plots, and other visual outputs |
-| {doc}`editor_features` | View variables, cell dependencies, errors, and more |
-| {doc}`dataframes` | Working with dataframes |
-| {doc}`plotting` | Interactive and reactive plots |
-| {doc}`state` | Mutable, reactive state |
-| {doc}`apps` | Running notebooks as apps |
-| {doc}`scripts` | Running notebooks as scripts |
-| {doc}`best_practices` | Best practices when working with marimo |
-| {doc}`performance` | Writing performant notebooks |
-| {doc}`wasm` | Running notebooks in the browser (no backend required!) |
-| {doc}`ai_completion` | Using AI to speed up your coding |
-| {doc}`deploying/index` | Deploying marimo notebooks and apps |
+| | |
+| :----------------------------------- | :------------------------------------------------------ |
+| {doc}`overview` | An overview of basic concepts |
+| {doc}`reactivity` | How reactive execution works |
+| {doc}`interactivity` | Using interactive UI elements |
+| {doc}`coming_from_jupyter` | marimo for Jupyter users |
+| {doc}`outputs` | Markdown, plots, and other visual outputs |
+| {doc}`editor_features` | View variables, cell dependencies, errors, and more |
+| {doc}`dataframes` | Working with dataframes |
+| {doc}`plotting` | Interactive and reactive plots |
+| {doc}`state` | Mutable, reactive state |
+| {doc}`integrating_with_marimo/index` | Rich displays of objects, custom UI plugins |
+| {doc}`apps` | Running notebooks as apps |
+| {doc}`scripts` | Running notebooks as scripts |
+| {doc}`best_practices` | Best practices when working with marimo |
+| {doc}`performance` | Writing performant notebooks |
+| {doc}`wasm` | Running notebooks in the browser (no backend required!) |
+| {doc}`ai_completion` | Using AI to speed up your coding |
+| {doc}`deploying/index` | Deploying marimo notebooks and apps |
```{admonition} Learn by doing!
:class: tip
diff --git a/docs/guides/integrating_with_marimo/custom_ui_plugins.md b/docs/guides/integrating_with_marimo/custom_ui_plugins.md
new file mode 100644
index 0000000000..44b5a673e7
--- /dev/null
+++ b/docs/guides/integrating_with_marimo/custom_ui_plugins.md
@@ -0,0 +1,2 @@
+```{include} /api/inputs/anywidget.md
+```
diff --git a/docs/guides/integrating_with_marimo/displaying_objects.md b/docs/guides/integrating_with_marimo/displaying_objects.md
new file mode 100644
index 0000000000..dde7c821a4
--- /dev/null
+++ b/docs/guides/integrating_with_marimo/displaying_objects.md
@@ -0,0 +1,87 @@
+# Richly display objects
+
+marimo has built-in rich representations of many objects, including native
+Python objects like lists and dicts as well as marimo objects like [UI
+elements](/guides/interactivity.md) and libraries, including matplotlib,
+seaborn, Plotly, altair pandas, and more. These rich representations are
+displayed for the last expression of a cell, or when using
+[`mo.output.append`](#marimo.output.append).
+
+You can register rich displays with marimo for your own objects.
+
+### Option 1: Implement a `_mime_` method
+
+When displaying an object, marimo's media viewer checks for the presence of a
+method called `_mime_`. This method should take no arguments and return
+a tuple of two strings, the [mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) and data to be displayed.
+
+**Examples.**
+
+```{eval-rst}
+.. marimo-embed::
+ :size: medium
+ :mode: edit
+
+ @app.cell(hide_code=True)
+ def __():
+ mo.md("**JSON**")
+
+ @app.cell
+ def __():
+ import json
+
+ class MyJSONObject(object):
+ def __init__(self, data: dict[str, object]) -> None:
+ self.data = data
+
+ def _mime_(self) -> tuple[str, str]:
+ return ("application/json", json.dumps(self.data))
+
+ MyJSONObject({"hello": "world"})
+
+ @app.cell(hide_code=True)
+ def __():
+ mo.md("**HTML**")
+
+ @app.cell
+ def __():
+ class Colorize(object):
+ def __init__(self, text: str) -> None:
+ self.text = text
+
+ def _mime_(self) -> tuple[str, str]:
+ return (
+ "text/html",
+ "<span style='color:red'>" + self.text + "</span>",
+ )
+
+ Colorize("Hello!")
+
+ @app.cell(hide_code=True)
+ def __():
+ mo.md("**Image**")
+
+ @app.cell
+ def __():
+ class Image(object):
+ def __init__(self, url: str) -> None:
+ self.url = url
+
+ def _mime_(self) -> tuple[str, str]:
+ return ("image/png", self.url)
+
+ Image("https://raw.githubusercontent.com/marimo-team/marimo/main/docs/_static/marimo-logotype-thick.svg")
+```
+
+### Option 2: Add a formatter to the marimo repo
+
+When you don't have the ability to implement a `_mime_` method on the type
+you want displayed, you can register custom formatters with marimo.
+
+We welcome contributors to add formatters to the marimo codebase. [Look at our
+codebase for
+examples](https://github.com/marimo-team/marimo/tree/main/marimo/_output/formatters),
+then open a pull request.
+
+
+[AnyWidget](/api/inputs/anywidget.md)
diff --git a/docs/guides/integrating_with_marimo/index.md b/docs/guides/integrating_with_marimo/index.md
new file mode 100644
index 0000000000..42e6d35a8e
--- /dev/null
+++ b/docs/guides/integrating_with_marimo/index.md
@@ -0,0 +1,31 @@
+# Integrating with marimo
+
+```{eval-rst}
+.. toctree::
+ :maxdepth: 2
+ :hidden:
+
+ displaying_objects
+ custom_ui_plugins
+```
+
+These guides will help you integrate your objects with marimo and hook
+into marimo's reactive execution engine for UI plugins.
+
+Still need help? Reach out to us on [Discord](https://discord.gg/JE7nhX6mD8) or
+[GitHub issues](https://github.com/marimo-team/marimo/issues).
+
+```{admonition} Checking if running in a marimo notebook
+:class: tip
+
+You can check if Python is running in a marimo notebook with
+[`mo.running_in_notebook`](#marimo.running_in_notebook). This can be helpful
+when developing library code that integrates with marimo.
+```
+
+
+
+| | |
+| :------------------------ | :------------------------------------------------------------------------ |
+| {doc}`displaying_objects` | Richly display objects by hooking into marimo's media viewer |
+| {doc}`custom_ui_plugins` | Build custom UI plugins that hook into marimo's reactive execution engine |