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
Copy file name to clipboardExpand all lines: docs/platforms/python/uv.md
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,6 +102,29 @@ To add a dependency to a specific group, use the `--group` flag:
102
102
uv add --group group_name package_name
103
103
```
104
104
105
+
#### Managing Tools: Global vs. Project-Specific
106
+
107
+
**uv** makes it easy to install CLI tools
108
+
109
+
##### Installing Global Tools
110
+
111
+
```shell
112
+
uv tool install black
113
+
```
114
+
115
+
This makes **black** available across all your projects but keeps it in its isolated virtual environment, avoiding system-wide conflicts.
116
+
117
+
##### Project-Specific Tools
118
+
119
+
If you need a tool for a specific project, add it directly as a dependency:
120
+
121
+
```shell
122
+
uv add --group dev ruff
123
+
```
124
+
125
+
This keeps the tool local to your project and listed in your `pyproject.toml`.
126
+
Your other projects remain unaffected, allowing for isolated development environments.
127
+
105
128
### Running Python scripts with UV
106
129
107
130
Once you install the necessary dependencies, you can start working on your Python scripts as usual. UV provides a few different ways to run Python code:
@@ -112,6 +135,13 @@ uv run hello.py
112
135
113
136
The run command ensures that the script is executed inside the virtual environment UV created for the project.
114
137
138
+
#### Environment variables
139
+
140
+
`uv run` can load [environment variables](https://docs.astral.sh/uv/configuration/files/#env) from dotenv files (e.g., `.env`, `.env.local`, `.env.development`), powered by the [dotenvy](https://github.com/allan2/dotenvy) crate.
141
+
To load a `.env` file from a dedicated location, set the `UV_ENV_FILE` environment variable, or pass the `--env-file` flag to `uv run`.
142
+
143
+
The `--env-file` flag can be provided multiple times, with subsequent files overriding values defined in previous files.
144
+
115
145
### Changing Python versions for the current project
116
146
117
147
You can switch Python versions for your current UV project at any point as long as the new version satisfies the specifications in your pyproject.toml file.
@@ -134,7 +164,7 @@ UV provides two special interfaces to manage these packages:
134
164
uv tool run black hello.py
135
165
```
136
166
137
-
2. Using the shorter and more convenient`uvx` command:
167
+
2. Running Tools Ephemerally with`uvx` command:
138
168
139
169
```shell
140
170
uvx black hello.py
@@ -369,3 +399,5 @@ uv cache prune
369
399
* UV [Working on projects](https://docs.astral.sh/uv/guides/projects/)
370
400
* Beyond Hypermodern: [Python is easy now](https://rdrn.me/postmodern-python/)
371
401
* Python UV: [The Ultimate Guide to the Fastest Python Package Manager](https://www.datacamp.com/tutorial/python-uv)
402
+
* [Writing your pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/)
403
+
* Mastering Python Project Management with uv: Part 2 — [Deep Dives and Advanced Use](https://bury-thomas.medium.com/mastering-python-project-management-with-uv-part-2-deep-dives-and-advanced-use-1e2540e6f4a6)
0 commit comments