Coming from Papermill¶
marimo provides built-in support for parametrizing and executing marimo notebooks. If you're familiar with Papermill, this guide will help you understand how to achieve similar functionality using marimo's features.
Parameterizing Notebooks¶
Papermill
Papermill allows you to parameterize Jupyter notebooks by defining a "parameters" cell and injecting values at runtime.
marimo
marimo offers two main ways to parameterize notebooks:
- Command Line Arguments:
Use
mo.cli_args
to access command-line arguments passed to your notebook.
import marimo as mo
# Access CLI args
args = mo.cli_args()
param1 = args.get("param1", "default_value")
Run your notebook as a script with:
Run your notebook as an app with:
- Query Parameters:
For web apps, use
mo.query_params
to access URL query parameters.
import marimo as mo
# Access query params
params = mo.query_params()
param1 = params.get("param1", "default_value")
Access your app with:
Then visit:
Executing Notebooks¶
Papermill
Papermill allows you to execute notebooks programmatically and pass parameters.
marimo
marimo notebooks are pure Python files, making them easy to execute programmatically.
- Running a named cell:
After naming a cell in your file, you can run it using the cell execution API.
from my_notebook import my_cell
# last_expression is the visual output of the cell
# definitions is a dictionary of the variables defined by the cell
last_expression, definitions = my_cell.run()
This API also allows for parametrizing the inputs to the cell; to learn more, make sure to checkout the example in our API reference.
- Using subprocess:
Storing or Sharing Artifacts¶
Papermill
Papermill can store executed notebooks with output.
marimo
marimo offers several options for storing and sharing outputs:
- Export to HTML:
- Deploy as Web App:
- Auto-export HTML:
You can configure marimo to automatically export to HTML during the editing process.
This is configured in the marimo application settings directly in the editor.
This way, after changes are made to your notebook, an HTML snapshot is generated,
and placed in a
.marimo/
directory in the same location as your notebook.
Workflow Integration¶
Papermill
Papermill is often used in data pipelines and workflow systems.
marimo
marimo notebooks can be easily integrated into workflows:
-
As Python Scripts: marimo notebooks are Python files, so they can be executed directly in most workflow systems. See our examples for integrating with popular tools.
-
Programmatic Execution: Importing notebook as Python modules or executing via subprocess allows for chaining together multiple notebooks in a workflow.