Run Notebooks Like Python Scripts with Marimo

Table of Contents

Run Notebooks Like Python Scripts with Marimo

Marimo as an alternative

This post explains how Marimo notebooks can be a great alternative to Jupyter Notebooks because they run in native Python. Allowing you to run notebooks like Python scripts with marimo. It also has other great features like automatically updating dependent cells, preventing variable redefinition, and more! Learn more about Marimo’s unique features in this overview article.

Before diving deeper into why running the notebook in native Python is a great advantage, let’s look at what makes Jupyter popular in the first place!

Jupyter has become the default interface for many data scientists thanks to its clean layout, inline visualizations, and interactive cell execution. It’s perfect for exploration, prototyping, and sharing results.

The Problem with Traditional Notebooks

However, working with notebooks outside the Jupyter environment can be frustrating. The .ipynb format stores code in a verbose JSON structure, mixing it with metadata, outputs, and execution counts. This clutters version control diffs and complicates automation in CI/CD pipelines.

For example, the following notebook:

is actually a JSON file:

{
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "name = \"Marimo\""
      ],
      "metadata": {},
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "greeting = f\"Hello, {name}!\""
      ],
      "metadata": {},
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "farewell = f\"Goodbye, {name}.\""
      ],
      "metadata": {},
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(greeting)\n",
        "print(farewell)"
      ],
      "metadata": {},
      "execution_count": 4,
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Hello, Marimo!\n",
            "Goodbye, Marimo.\n"
          ]
        }
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language_info": {
        "name": "python"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}

Even when converted to .py, these notebooks can break or lose interactivity. Tools like papermill or jupytext help, but require additional setup like installing dependencies, configuring metadata, or syncing .ipynb and .py files.

How Marimo Solves This

Marimo notebooks are plain .py files under the hood. Each notebook cell is just a standard Python block, making it compatible with any Python interpreter, script runner, or automated pipeline.

For example, the following Marimo notebook:

is actually a Python that looks like this:

# sample_notebook.py

import marimo

__generated_with = "0.12.9-dev12"
app = marimo.App()

@app.cell
def _():
    name = "Marimo"
    return name

@app.cell
def _(name):
    greeting = f"Hello, {name}!"
    return greeting

@app.cell
def _(name):
    farewell = f"Goodbye, {name}."
    return farewell

@app.cell
def _(greeting, farewell):
    print(greeting)
    print(farewell)

if __name__ == "__main__":
    app.run()

Each @app.cell block acts like a cell in a traditional notebook, while still being a valid Python script.

Running Marimo Notebooks

You can run a Marimo notebook just like any other Python file:

python sample_notebook.py

You get the best of both worlds: interactive notebooks and clean, executable scripts.

Explore the full set of features that make Marimo a modern notebook for reproducible data science in this overview article.

Explore Marimo on GitHub.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran