-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs: integration with marimo guide #13691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
48385ee
418531c
2e01685
eb42e18
9c2ac0b
19b7207
c7e0b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
title: Using uv with marimo | ||
description: | ||
A complete guide to using uv with marimo notebooks for interactive computing, script execution, | ||
and data apps. | ||
--- | ||
|
||
# Using uv with marimo | ||
|
||
[marimo](https://github.com/marimo-team/marimo) is an open-source Python notebook that blends | ||
interactive computing with the reproducibility and reusability of traditional software, letting you | ||
version with Git, run as scripts, and share as apps. Because marimo notebooks are stored as pure | ||
Python scripts, they are able to integrate tightly with uv. | ||
|
||
You can readily use marimo as a standalone tool, as scripts that contain their own dependencies, in | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
projects, and in non-project environments. | ||
|
||
## Using marimo as a standalone tool | ||
|
||
For adhoc access to marimo notebooks, start a marimo server at any time in an isolated environment | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with: | ||
|
||
```console | ||
$ uvx marimo edit | ||
``` | ||
|
||
Start a specific notebook with | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```console | ||
$ uvx marimo edit my_notebook.py | ||
``` | ||
|
||
## Using marimo with inline script metadata | ||
|
||
Because marimo notebooks are stored as Python scripts, they can encapsulate their own dependencies | ||
using inline script metadata, via uv's [support for scripts](../../guides/scripts.md). For example: | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```console | ||
$ uv add --script my_notebook.py numpy | ||
``` | ||
|
||
To run a notebook containing script metadata, use | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```console | ||
$ uvx marimo edit --sandbox my_notebook.py | ||
``` | ||
|
||
and marimo will automatically use uv to start your notebook in an isolated virtual environment with | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
your script's dependencies. Packages installed from the marimo UI will automatically be added to the | ||
notebook's script metadata. | ||
|
||
You can optionally run these notebooks as scripts with | ||
|
||
```console | ||
$ uv run my_notebook.py | ||
``` | ||
|
||
## Using marimo within a project | ||
|
||
If you're working within a [project](../../concepts/projects/index.md), you can start a marimo | ||
notebook with access to the project's virtual environment via the following command (assuming marimo | ||
is a project dependency): | ||
|
||
```console | ||
$ uv run marimo edit my_notebook.py | ||
``` | ||
|
||
To make additional packages available to your notebook, either add them to your project with | ||
`uv add`, or use marimo's built-in package installation UI, which will invoke `uv add` on your | ||
behalf. | ||
|
||
If marimo is not a project dependency, you can still run a notebook with | ||
|
||
```console | ||
$ uv run --with marimo marimo edit my_notebook.py | ||
``` | ||
|
||
which will let you import your project's modules. However, packages installed via marimo's UI when | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
running in this way will not be added to your project, and may disappear on subsequent marimo | ||
invocations. | ||
|
||
## Using marimo in a non-project environment | ||
|
||
To run marimo in a virtual environment that isn't associated with a | ||
[project](../../concepts/projects/index.md), add marimo to the environment directly: | ||
|
||
=== "macOS and Linux" | ||
akshayka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```console | ||
$ uv venv | ||
$ uv pip install numpy | ||
$ uv pip install marimo | ||
$ .venv/bin/marimo edit | ||
zanieb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
=== "Windows" | ||
|
||
```pwsh-session | ||
PS> uv venv | ||
PS> uv pip install numpy | ||
PS> uv pip install marimo | ||
PS> .venv\Scripts\marimo edit | ||
``` | ||
|
||
From here, `import numpy` will work within the notebook, and marimo's UI installer will add packages | ||
to the environment with `uv pip install` on your behalf. | ||
|
||
## Running marimo notebooks as scripts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this section differ from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added more context — notebooks can be run as scripts even if they don't have inline script metadata. If you think this is redundant, or obvious, I am happy to remove this section. |
||
|
||
Run your notebooks as scripts with | ||
|
||
```console | ||
$ uv run my_notebook.py | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.