Skip to content

Commit 9b50f4e

Browse files
authored
Update uv.md
1 parent 18fa240 commit 9b50f4e

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

  • programming-notes/python

programming-notes/python/uv.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,70 @@ When starting a new project you can specify the Python version using:
4747
$ uv init project_name --python 3.11
4848
```
4949

50+
### Types of projects
51+
52+
**Application** projects are suitable for web servers, scripts, and command-line interfaces.
53+
54+
```
55+
uv init example-app
56+
uv init example-app --app
57+
```
58+
59+
```
60+
example-app/
61+
├─ main.py
62+
├─ pyproject.toml # [project] metadata only, no [build-system]
63+
├─ README.md
64+
└─ .python-version
65+
```
66+
67+
The `pyproject.toml` includes basic metadata. It does not include a build system, it is not a package and will not be installed into the environment
68+
69+
**Packaged application** projects are suitable if you require a package, for instance, a command-line interface that will be published to PyPI or if you want to define tests in a dedicated directory.
70+
71+
```
72+
uv init --package example-pkg
73+
```
74+
75+
```
76+
example-pkg/
77+
├─ src/
78+
│ └─ example_pkg/
79+
│ ├─ __init__.py
80+
│ ├─ cli.py # CLI entrypoint code
81+
│ └─ core.py
82+
├─ tests/
83+
│ └─ test.py
84+
├─ pyproject.toml # [project] + [project.scripts] + [build-system]
85+
├─ README.md
86+
└─ .python-version
87+
```
88+
89+
The source code is moved into a src directory with a module directory and an `__init__.py` file. A build system is defined, so the project will be installed into the environment.
90+
91+
92+
**Library** projects provide functions and objects for other projects to consume. Libraries are intended to be built and distributed, e.g., by uploading them to PyPI. Using `--lib` implies `--package`. Libraries always require a packaged project.
93+
94+
```
95+
uv init --lib example-lib
96+
```
97+
98+
```
99+
example-lib/
100+
├─ src/
101+
│ └─ example_lib/
102+
│ ├─ __init__.py # library package root
103+
│ └─ module.py # your library code
104+
├─ tests/
105+
│ └─ test.py
106+
├─ pyproject.toml # [project] + [build-system]
107+
├─ README.md
108+
└─ .python-version
109+
```
110+
111+
As with a packaged application, a `src` layout is used. A `py.typed` marker is included to indicate to consumers that types can be read from the library. A `src` layout ensures that the library is isolated from any python invocations in the project root and that distributed library code is well separated from the rest of the project source. A build system is defined, so the project will be installed into the environment.
112+
113+
50114
## Installing packages
51115

52116
To add packages:

0 commit comments

Comments
 (0)