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
This is an example project demonstrating how to build a Python package (wheel or sdist) using [uv](https://docs.astral.sh/uv/) with `pyproject.toml` for configuration.
4
+
5
+
> [!INFO]
6
+
> uv does not currently have a build _backend_ and defaults to using [hatchling](https://hatch.pypa.io/latest/why/#build-backend) for building packages. For most users, this will be sufficient and invisible.
7
+
8
+
## Commands
9
+
10
+
### Initialize the Project
11
+
Create a new project structure if starting from scratch:
12
+
13
+
```console
14
+
uv init --package demo-uv
15
+
```
16
+
17
+
### Setup Project Environment
18
+
Install project dependencies and create a virtual environment:
19
+
20
+
```console
21
+
uv sync
22
+
```
23
+
24
+
### Running Code
25
+
Execute Python code in the project environment:
26
+
27
+
```console
28
+
uv run python -c "import demo"
29
+
```
30
+
31
+
### Building
32
+
33
+
Build both wheel and source distribution:
34
+
35
+
```console
36
+
uv build
37
+
```
38
+
39
+
To build only one format:
40
+
```console
41
+
uv build --wheel # Build wheel only
42
+
uv build --sdist # Build source distribution only
43
+
```
44
+
45
+
### Publishing
46
+
Upload built distributions to PyPI:
47
+
48
+
```console
49
+
uv publish
50
+
```
51
+
52
+
For TestPyPI, configure an alternative index in `pyproject.toml`:
53
+
54
+
```toml
55
+
[[tool.uv.index]]
56
+
name = "testpypi"
57
+
url = "https://test.pypi.org/simple/"
58
+
publish-url = "https://test.pypi.org/legacy/"
59
+
```
60
+
61
+
Then publish using:
62
+
63
+
```console
64
+
uv publish --index testpypi
65
+
```
66
+
67
+
The built distributions will be placed in the `dist/` directory by default.
68
+
69
+
{{< callout type="info" >}}
70
+
Remember to [set up authentication](https://docs.astral.sh/uv/guides/publish/) before publishing. Use `UV_PUBLISH_TOKEN` environment variable or the `--token` flag to provide your PyPI API token.
0 commit comments