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: package reproducibility (#3392)
Akshay Agrawal8c53055a0e52
diff --git a/README.md b/README.mdindex cbb555b667..edec1f999a 100644--- a/README.md+++ b/README.md@@ -104,11 +104,11 @@ order, based on variable references instead of cells' positions on the page.Organize your notebooks to best fit the stories you'd like to tell.**Built-in package management.** marimo has built-in support for all major-package managers, letting you install packages on import. marimo can even+package managers, letting you [install packages on import](https://docs.marimo.io/guides/editor_features/package_management.html). marimo can even[serialize package-requirements](https://docs.marimo.io/guides/editor_features/package_management.html#auto-tracking-inline-script-metadata)+requirements](https://docs.marimo.io/guides/package_reproducibility.html)in notebook files, and auto install them in-[isolated venv sandboxes](https://docs.marimo.io/guides/editor_features/package_management.html#running-marimo-in-a-sandbox-environment-uv-only).+isolated venv sandboxes.**Batteries-included.** marimo comes with GitHub Copilot, AI assistants, Ruffcode formatting, HTML export, fast code completion, a [VS Codediff --git a/docs/guides/editor_features/package_management.md b/docs/guides/editor_features/package_management.mdindex 3bfc70109b..a18ab59dc7 100644--- a/docs/guides/editor_features/package_management.md+++ b/docs/guides/editor_features/package_management.md@@ -8,50 +8,11 @@ Once the module is installed, all cells that depend on the module will be rerun.We use some heuristic for guessing the package name in your registry (e.g. PyPI) from the module name. It is possible that the package name is different from the module name. If you encounter an error, please file an issue or help us by adding your mapping [directly to the codebase](https://github.com/marimo-team/marimo/blob/main/marimo/_runtime/packages/module_name_to_pypi_name.py).-## Running `marimo` in a sandbox environment (`uv` only)+## Package reproducibility-If you want to run marimo in a sandbox environment, you can use the `--sandbox` flag. This will create an isolated virtual environment (using [uv](https://docs.astral.sh/uv)) and install any packages listed in the script metadata, per [PEP 723](https://peps.python.org/pep-0723/). If there is no package metadata in the script, marimo will still prompt you to install any missing packages.+marimo is the only Python notebook that is reproducible down to the packages+they use. This makes it possible to share standalone notebooks without shipping+`requirements.txt` files alongside them, and guarantees your notebooks will+work weeks, months, even years into the future.-This is useful when you want to run marimo in a clean environment without affecting your global environment.--```bash-marimo edit --sandbox notebook.py-```--### Auto-tracking inline script metadata { #auto-tracking-inline-script-metadata }--When running with `--sandbox`, marimo will automatically track the package name metadata in your notebook file, per [PEP 723](https://peps.python.org/pep-0723/). This metadata is used to manage the notebook's dependencies and Python version.--For example, whenever you add or remove a package, marimo will automatically update the script metadata in your notebook file:--```python-# /// script-# requires-python = ">=3.11"-# dependencies = [-# "pandas==<version>",-# "altair==<version>",-# ]-# ///-```--This means your notebook file is a completely self-contained artifact with all the necessary information to run.--### Sandbox creation configuration--Running marimo in a sandbox environment uses `uv` to create a virtual environment. You can use any of `uv`'s [supported environment variables](https://docs.astral.sh/uv/configuration/environment/).--#### Choosing the Python version--For example, you can specify the Python version using the `UV_PYTHON` environment variable:--```bash-UV_PYTHON=3.13 marimo edit --sandbox notebook.py-```--#### Other common configuration--or you can use `uv`'s link mode:--```bash-UV_LINK_MODE="copy" marimo edit --sandbox notebook.py-```+To learn more, see the [Package Reproducibility Guide](../package_reproducibility.md)diff --git a/docs/guides/index.md b/docs/guides/index.mdindex 0383e35670..26e0e19438 100644--- a/docs/guides/index.md+++ b/docs/guides/index.md@@ -7,25 +7,26 @@ These guides cover marimo's core concepts.Prefer a hands-on learning experience? marimo comes packaged with interactivetutorials that you can launch with `marimo tutorial` at the command line.-| Guide | Description |-| :--------------------------------------------------- | :--------------------------------------------------------- |-| [Running cells](reactivity.md) | Understanding how marimo runs cells |-| [Interactive elements](interactivity.md) | Using interactive UI elements |-| [Visualizing outputs](outputs.md) | Creating markdown, plots, and other visual outputs |-| [Migrating from Jupyter](coming_from/jupyter.md) | Tips for transitioning from Jupyter |-| [Expensive notebooks](expensive_notebooks.md) | Tips for working with expensive notebooks |-| [Working with data](working_with_data/index.md) | Using SQL cells, no-code dataframe, and reactive plots |-| [Apps](apps.md) | Running notebooks as apps |-| [Scripts](scripts.md) | Running notebooks as scripts |-| [Tests](testing/index.md) | Running unit tests in notebooks |-| [Export notebooks](exporting.md) | Exporting notebooks to HTML, ipynb, flat scripts, and more |+| Guide | Description |+| :---------------------------------------------------- | :--------------------------------------------------------- |+| [Running cells](reactivity.md) | Understanding how marimo runs cells |+| [Interactive elements](interactivity.md) | Using interactive UI elements |+| [Visualizing outputs](outputs.md) | Creating markdown, plots, and other visual outputs |+| [Migrating from Jupyter](coming_from/jupyter.md) | Tips for transitioning from Jupyter |+| [Expensive notebooks](expensive_notebooks.md) | Tips for working with expensive notebooks |+| [Working with data](working_with_data/index.md) | Using SQL cells, no-code dataframe, and reactive plots |+| [Package reproducibility](package_reproducibility.md) | Making notebooks reproducible down to the packages |+| [Editor Features](editor_features/index.md) | View variables, dataframe schemas, docstrings, and more |+| [Apps](apps.md) | Running notebooks as apps |+| [Scripts](scripts.md) | Running notebooks as scripts |+| [Tests](testing/index.md) | Running unit tests in notebooks |+| [Export notebooks](exporting.md) | Exporting notebooks to HTML, ipynb, flat scripts, and more || [Publish to the web](publishing/index.md) | Edit and publish notebooks on the web |-| [Run notebooks with WebAssembly](wasm.md) | Create notebooks in our online playground |-| [Deploying](deploying/index.md) | Deploying marimo notebooks and apps |-| [Editor Features](editor_features/index.md) | View variables, dataframe schemas, docstrings, and more |-| [Configuration](configuration/index.md) | Configure various settings |-| [Coming from other tools](coming_from/index.md) | Transitioning from Jupyter and other tools |-| [Extending marimo](integrating_with_marimo/index.md) | Rich displays of objects, custom UI plugins |-| [State management](state.md) | Advanced: mutable reactive state |-| [Best practices](best_practices.md) | Best practices to help you get the most out of marimo |-| [Troubleshooting](troubleshooting.md) | Troubleshooting notebooks |+| [Run notebooks with WebAssembly](wasm.md) | Create notebooks in our online playground |+| [Deploying](deploying/index.md) | Deploying marimo notebooks and apps |+| [Configuration](configuration/index.md) | Configure various settings |+| [Coming from other tools](coming_from/index.md) | Transitioning from Jupyter and other tools |+| [Extending marimo](integrating_with_marimo/index.md) | Rich displays of objects, custom UI plugins |+| [State management](state.md) | Advanced: mutable reactive state |+| [Best practices](best_practices.md) | Best practices to help you get the most out of marimo |+| [Troubleshooting](troubleshooting.md) | Troubleshooting notebooks |diff --git a/docs/guides/package_reproducibility.md b/docs/guides/package_reproducibility.mdnew file mode 100644index 0000000000..9e8775f987--- /dev/null+++ b/docs/guides/package_reproducibility.md@@ -0,0 +1,127 @@+# Package Reproducibility++marimo is the only Python notebook that is reproducible down to the packages,+serializing requirements in notebook files and running notebooks in+sandboxed venvs. This lets you share standalone notebooks without shipping+`requirements.txt` files alongside them, and guarantees your notebooks will+work weeks, months, even years into the future.++To opt-in to package reproducibility, use the `sandbox` flag:++=== "edit"++ ```bash+ marimo edit --sandbox notebook.py+ ```+++=== "run"++ ```bash+ marimo run --sandbox notebook.py+ ```+++=== "new"++ ```bash+ marimo new --sandbox+ ```++When running with `--sandbox`, marimo:++1. tracks the packages and versions used by your notebook, saving+ them in the notebook file;+2. runs in an isolated virtual environment ("sandbox") that only+ contains the notebook dependencies.++marimo's sandbox provides two key benefits. (1) Notebooks that carry their own+dependencies are easy to share — just send the `.py` file. (2) Isolating a+notebook from other installed packages prevents obscure bugs.+++!!! note "Requires uv"++ Sandboxed notebooks require the uv package manager+ ([installation+ instructions](https://docs.astral.sh/uv/getting-started/installation/)).++!!! tip "Solving the notebook reproducibility crisis"++ marimo's support for package sandboxing is only possible because marimo+ notebooks are stored as pure Python files, letting marimo take advantage+ of new Python standards like [PEP+ 723](https://peps.python.org/pep-0723/) and tools like uv. In contrast,+ traditional notebooks like Jupyter are stored as JSON files, and which suffer+ from a [reproducibility+ crisis](https://leomurta.github.io/papers/pimentel2019a.pdf) due to the lack+ of package management.+++## Inline script metadata { #auto-tracking-inline-script-metadata }++When running with `--sandbox`, marimo automatically tracks package metadata in+your notebook file using inline script metadata, which per [PEP+723](https://peps.python.org/pep-0723/) is essentially a pyproject.toml inlined+as the script's header. This metadata is used to manage the+notebook's dependencies and Python version, and looks something like this:++```python+# /// script+# requires-python = ">=3.11"+# dependencies = [+# "pandas==<version>",+# "altair==<version>",+# ]+# ///+```++!!! example "Example notebooks"++ The [example+ notebooks](https://github.com/marimo-team/marimo/tree/main/examples) in our+ GitHub repo were all created using `--sandbox`. Take a look at any of them+ for an example of the full script metadata.++### Adding and removing packages+When you import a module, if marimo detects that it is a third-party+package, it will automatically be added to the script metadata. Removing+an import does _not_ remove it from the script metadata (since library+code may still use the package).++Adding packages via the package manager panel will also add packages to script+metadata, and removing packages from the panel will in turn remove them from+the script metadata.++You can also edit the script metadata manually in an editor like VS Code or+neovim.++### Package locations++By default, marimo will look for packages on PyPI. You can edit the script+metadata to look for packages elsewhere, such as on GitHub. Consult the [Python+packaging+documentation](https://packaging.python.org/en/latest/specifications/dependency-specifiers/#examples)+for more information.++## Configuration++Running marimo in a sandbox environment uses `uv` to create an isolated virtual+environment. You can use any of `uv`'s [supported environment+variables](https://docs.astral.sh/uv/configuration/environment/).++#### Choosing the Python version++For example, you can specify the Python version using the `UV_PYTHON` environment variable:++```bash+UV_PYTHON=3.13 marimo edit --sandbox notebook.py+```++#### Other common configuration++Another common configuration is `uv`'s link mode:++```bash+UV_LINK_MODE="copy" marimo edit --sandbox notebook.py+```diff --git a/docs/index.md b/docs/index.mdindex 493b877456..702bb5d652 100644--- a/docs/index.md+++ b/docs/index.md@@ -119,11 +119,11 @@ order, based on variable references instead of cells' positions on the page.Organize your notebooks to best fit the stories you'd like to tell.**Built-in package management.** marimo has built-in support for all major-package managers, letting you install packages on import. marimo can even+package managers, letting you [install packages on import](guides/editor_features/package_management.md). marimo can even[serialize package-requirements](guides/editor_features/package_management.md#auto-tracking-inline-script-metadata)+requirements](guides/package_reproducibility.md)in notebook files, and auto install them in-[isolated venv sandboxes](guides/editor_features/package_management.md#running-marimo-in-a-sandbox-environment-uv-only).+isolated venv sandboxes.**Batteries-included.** marimo comes with GitHub Copilot, AI assistants, Ruffcode formatting, HTML export, fast code completion, a [VS Codediff --git a/mkdocs.yml b/mkdocs.ymlindex 7122b18f91..7d2956dd1b 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -86,6 +86,7 @@ nav:- DataFrames: guides/working_with_data/dataframes.md- SQL: guides/working_with_data/sql.md- Plotting: guides/working_with_data/plotting.md+ - Package reproducibility: guides/package_reproducibility.md- Editor features:- Editor features: guides/editor_features/index.md- Editor overview: guides/editor_features/overview.md