docs/guides/package_management/using_uv.md
uv is an extremely fast Python package and project manager: you can use it to install packages, manage the dependencies of Python projects, and run scripts. While marimo supports all major package managers, it integrates especially tightly with uv. In particular, marimo's package sandbox feature, which lets you inline dependencies in notebook files, requires uv.
!!! note "No prior knowledge required"
This guide teaches you the basics of using `uv` with marimo. It assumes zero
familiarity with `uv`.
You can manage your notebooks' dependencies in three different ways:
marimo edit --sandbox notebook.pyuv project , which define dependencies declaratively in a pyproject.toml
file;We'll walk through each of these three ways in this guide.
The easiest way to get started is to use marimo's package sandbox
feature, which manages your dependencies for you.
Create or edit your notebook with uvx
command,
making sure to include the --sandbox flag:
uvx marimo edit --sandbox my_notebook.py
This command installs marimo in a temporary environment, activates it, then
runs your marimo notebook. The --sandbox flag is what tells marimo to keep
track of your dependencies and store them in the notebook file. If there are
any dependencies already tracked in the file, this command will download
them and install them in the environment.
Run sandboxed notebooks as scripts with
uv run my_notebook.py
You can also upload sandboxed notebooks to the web, such as on GitHub, and have others run them locally with a single command:
uvx marimo edit --sandbox https://gist.githubusercontent.com/kolibril13/a59135dd0973b97d488ba21c650667fe/raw/5f98021b5d3c024d5827fa9464787517495178b4/marimo_minimal_numpy_example.py
Note:
Would you like to run it in a secure docker container? [Y/n]:
Y.To learn more, read our full guide on using inline dependencies.
A uv project is a directory in which you can store Python code, including
notebooks, alongside a pyproject.toml file that declares the project's
dependencies.
Create a project with uv init:
uv init hello-world
cd hello-world
!!! tip "Starter template"
Get started quickly by cloning our [starter template](https://github.com/marimo-team/marimo-uv-starter-template).
This creates a pyproject.toml and some starter code.
Next, add marimo to your project:
uv add marimo
??? note "Omitting marimo from your project"
Adding marimo to your project is optional. Instead, you can
run marimo in a temporary environment that has access to
your project's dependencies using `uv run --with marimo marimo edit`.
Once you've added marimo, use the uv run command
to run the version of marimo installed in your project:
uv run marimo edit my_notebook.py
Starting marimo in this way will let marimo import any of the packages installed in your project.
Scripts. Run marimo notebooks as scripts with
uv run my_notebook.py
which will run your notebook in an environment containing your project dependencies.
Use uv add to add dependencies:
uv add numpy
You can also specify a version
uv add numpy==2.26
Remove packages with uv remove:
uv remove numpy
If you started marimo with uv run marimo edit, the marimo editor's package
management features will add and remove packages from
your pyproject.toml, so there's no need to use the uv command-line if you
don't want to.
If you are used to a venv and pip based workflow, you can use the uv venv and
uv pip commands for a similar but more performant experience:
uv venv creates a virtual environment in the current directory, at .venvuv pip lets you install and uninstall packages in the venv$ uv venv
$ uv pip install numpy
$ uv pip install marimo
$ uv run 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.