You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[`uv` is a fast, modern Python package manager](https://github.com/astral-sh/uv) designed for creating reproducible environments with minimal overhead. In Metaflow, you can use projects managed by `uv` directly by
5
+
specifying `--environment=uv`, enabling you to manage dependencies the same way you would in any contemporary Python project. This makes it easy to develop locally and seamlessly run flows in the cloud with all dependencies included.
6
+
7
+
`uv` takes a more holistic approach to package and project management in contrast to `conda` and `pip`. As a result,
8
+
when using `--environment=uv`, Metaflow lets `uv` install and handle dependencies using its native approach.
9
+
A downside of this is that `uv` doesn't benefit from [Metaflow's internal package snapshotting](/scaling/dependencies/internals) which provides stronger guarantees for scalability and availability of packages, which matters especially
10
+
when running tasks at large scale.
11
+
12
+
:::tip
13
+
`uv` is often a convenient starting point. If you run into any issues at scale, you can always switch to `@pypi`
14
+
or `@conda` later.
15
+
:::
16
+
17
+
## Setting up a Metaflow project with `uv`
18
+
19
+
Metaflow works with `uv` as any other Python library, so you can use `uv` as usual. Here's an example:
20
+
21
+
1. Initialize a project: `uv init myflow; cd myflow`.
22
+
23
+
2. Add packages you need, including Metaflow: `uv add pandas metaflow`.
24
+
25
+
3. Run a flow `uv run flow.py run`.
26
+
27
+
## Running tasks remotely
28
+
29
+
Metaflow will package and ship the `uv` project in the cloud when you specify `--environment=uv`:
30
+
31
+
```
32
+
uv run flow.py --environment=uv run
33
+
```
34
+
Or, more conveniently, you can set an environment variable
35
+
```
36
+
export METAFLOW_ENVIRONMENT=uv
37
+
```
38
+
so you don't need to add the command line option in every execution.
39
+
40
+
After this, you can use Metaflow's compute layer to [run the flow in the cloud](/scaling/remote-tasks/requesting-resources) with all the packages defined in your `uv` environment included, e.g. [using Kubernetes](/scaling/remote-tasks/kubernetes) ([or `--with batch`](/scaling/remote-tasks/aws-batch)):
41
+
42
+
```
43
+
uv run flow.py run --with kubernetes
44
+
```
45
+
46
+
Remember to set the `environment=uv` when [deploying to production](/production/introduction) as well.
0 commit comments