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
Python project metadata is defined in a `pyproject.toml` file.
12
12
13
-
`uv init` can be used to create a new project, with a basic `pyproject.toml` and package definition.
13
+
!!!
14
+
15
+
`uv init` can be used to create a new project. See [Creating projects](#creating-projects) for
16
+
details.
14
17
15
18
A minimal project definition includes a name, version, and description:
16
19
@@ -21,7 +24,7 @@ version = "0.1.0"
21
24
description = "Add your description here"
22
25
```
23
26
24
-
Additionally, it's recommended to include a Python version requirement:
27
+
It's recommended, but not required, to include a Python version requirement:
25
28
26
29
```toml title="pyproject.toml"
27
30
[project]
@@ -39,6 +42,72 @@ dependency list from the command line with `uv add` and `uv remove`. uv also sup
39
42
40
43
See the official [`pyproject.toml` guide](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) for more details on getting started with a `pyproject.toml`.
41
44
45
+
## Creating projects
46
+
47
+
uv supports initializing a project with `uv init`. By default, uv will create a project in the
48
+
working directory. Projects can be created in a target directory by providing a name, e.g.,
49
+
`uv init foo`. If there's already a project in the target directory, i.e., there's a
50
+
`pyproject.toml`, uv will exit with an error.
51
+
52
+
By default, uv will create a project for an [application](#applications). However, the `--lib` flag
53
+
can be used to create a project for a [library](#libraries).
54
+
55
+
## Project types
56
+
57
+
uv groups projects into two types: **applications** and **libraries**.
58
+
59
+
### Applications
60
+
61
+
Application projects are suitable for web servers, scripts, and command-line interfaces.
62
+
63
+
Application projects have the following traits:
64
+
65
+
- A build backend is not defined.
66
+
- Source code is often in the top-level directory, e.g., `hello.py`.
67
+
- The project package is not installed in the project environment.
68
+
69
+
!!! note
70
+
71
+
The `--package` flag can be passed to `uv init` to create a distributable application,
72
+
e.g., if you want to publish a command-line interface via PyPI. uv will define a build
73
+
backend for the project, include a `[project.scripts]` entrypoint, and install the project
74
+
package into the project environment.
75
+
76
+
Similarly, a build backend can be manually defined to treat any application as a distributable
77
+
package. This may require changes to the project directory structure, depending on the build
78
+
backend.
79
+
80
+
### Libraries
81
+
82
+
A library is a project that is intended to be built and distributed as a Python package, for
83
+
example, by uploading it to PyPI. A library provides functions and objects for other projects to
84
+
consume.
85
+
86
+
Library projects have the following traits:
87
+
88
+
- A build backend is required.
89
+
- Source code is typically in a `src/{package}` directory.
90
+
- The project package is installed in the project environment.
91
+
92
+
Libraries can be created with `uv init` by providing the `--lib` flag. uv will assume that any
93
+
project that defines a `[build-system]` is a library.
94
+
95
+
### Other types
96
+
97
+
By default, uv uses the presence of a `[build-system]` in the `pyproject.toml` to determine if a
98
+
project is an application or a library. However, uv also allows manually declaring if a project
99
+
should be treated as a package.
100
+
101
+
To enable or disable build and installation of the project package regardless of the presence of a
102
+
`[build-system]` definition, use the [`tool.uv.package`](../reference/settings.md#package) setting.
103
+
104
+
Setting `tool.uv.package = true` will force a project package to be built and installed into the
105
+
project environment. If no build system is defined, uv will use the setuptools legacy backend.
106
+
107
+
Setting `tool.uv.package = false` will force a project package _not_ to be built and installed into
108
+
the project environment. uv will ignore the declared build system, if any, when interacting with the
109
+
project.
110
+
42
111
## Project environments
43
112
44
113
uv creates a virtual environment in a `.venv` directory next to the `pyproject.toml`. This virtual
0 commit comments