Introduction
marimo is an open-source notebook for Python that saves each notebook as an ordinary Python source file rather than a JSON document like a Jupyter notebook. The file can be read and changed in any editor, compared line by line in version control, imported as a module and run as a script.
marimo notebooks are reactive: marimo works out which variables each cell defines and uses, and when a cell changes it runs the cells that depend on it. Outputs are not saved in the file.
Structure
The file imports marimo and creates an App. Each cell is a
function decorated with @app.cell: its parameters are the variables it
uses from other cells, and it returns the variables it defines. The file ends by running
the app when it is executed as a script. A line near the top records the marimo version
that wrote it.
import marimo
__generated_with = "0.10.0"
app = marimo.App()
@app.cell
def _():
n = 5
return (n,)
@app.cell
def _(n):
squares = [i * i for i in range(n)]
squares
return (squares,)
if __name__ == "__main__":
app.run()
n from the first.