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: python/uv.md
+98
Original file line number
Diff line number
Diff line change
@@ -56,13 +56,111 @@ $ cd project_name
56
56
$ uv add requests flask
57
57
```
58
58
59
+
To remove packages:
60
+
61
+
```
62
+
$ uv remove flask
63
+
```
64
+
59
65
Working with development dependencies:
60
66
61
67
```
62
68
$ uv add --dev black
63
69
$ uv run black path\to\file.py
64
70
```
65
71
72
+
73
+
## Running scripts
74
+
75
+
To run python files in you environment use:
76
+
77
+
```
78
+
$ uv run example.py
79
+
```
80
+
81
+
82
+
## Working with tools
83
+
84
+
Tools are pacakges that can perform several functions but are not part of your project. For instance, it is common to use a linter/formatter when developing (e.g., `ruff`). With `uv` you can use tools like `ruff` in different ways.
85
+
86
+
### Ways to use tools
87
+
88
+
1) Running a tool without installing it (it's installed in a temporary environment and deleted after use).
89
+
```
90
+
$ uv tool run ruff check
91
+
```
92
+
The following alias can also be used and results in the same:
93
+
```
94
+
$ uvx ruff check
95
+
```
96
+
97
+
2) When a tool is used frequently it may be usefull to install it to a persistent environment and add it to the `PATH`.
98
+
```
99
+
$ uv tool install ruff
100
+
```
101
+
Now, whatever the project you are wirking in, you can run `ruff` by doing:
102
+
```
103
+
$ ruff check
104
+
```
105
+
106
+
3) You can also install the tool in your project as a development dependency
107
+
```
108
+
$ uv add --dev ruff
109
+
```
110
+
And run it with
111
+
```
112
+
$ uv run ruff check
113
+
```
114
+
115
+
### Upgrading tools
116
+
117
+
Upgrade all tools with:
118
+
```
119
+
$ uv tool upgrade --all
120
+
```
121
+
122
+
Or a single tool with:
123
+
```
124
+
$ uv tool upgrade ruff
125
+
```
126
+
127
+
128
+
129
+
## Working with `jupyter`
130
+
131
+
If you're working within a project, you can start a Jupyter server with access to the project's virtual environment by:
132
+
```
133
+
$ uv run --with jupyter jupyter lab
134
+
```
135
+
136
+
Alternatively you can install Jupyter as a dev dependency in your project
137
+
```
138
+
$ uv add --dev jupyterlab
139
+
$ uv run jupyter lab
140
+
```
141
+
142
+
143
+
## Project entry points and command line interfaces
144
+
145
+
To create a project CLI you need to configure entry point tables in the `pyproject.toml` and add a build system. For example, to declare a command called `hello` that invokes the `hello` function in the `example` module:
146
+
147
+
In the `pyproject.toml` file:
148
+
149
+
```toml
150
+
[build-system]
151
+
requires = ["setuptools>=61.0", "wheel"]
152
+
build-backend = "setuptools.build_meta"
153
+
154
+
[project.scripts]
155
+
hello = "example:hello"
156
+
```
157
+
158
+
You can then run the command with:
159
+
```
160
+
$ uv run hello
161
+
```
162
+
163
+
66
164
## Deploying
67
165
68
166
Deploying the project to production excluding dev dependencies:
0 commit comments