Skip to content
Python

pyproject.toml Explained: uv vs pip vs Poetry

Ihsan Ullah · 15 min read
uv vs pip vs Poetry, Lesson 31 of the Python course: pyproject.toml explained

Python course · Module 6: Modules and environments · Lesson 31 of 63

Quick answer: pyproject.toml is the standard settings file of a Python project. Its [project] table holds the name, version, requires-python and dependencies, and [build-system] says which tool builds the project. pip, uv and Poetry all read it: pip comes with Python but leaves the file and the virtual environment to you, while uv and Poetry write the file, make the venv and save exact versions in a lock file. uv vs pip: learn pip first, then use uv for new projects, and keep Poetry where a team already uses it.

In this lesson you will learn:

  • what pyproject.toml is and what [project], dependencies, requires-python and [build-system] mean
  • how to create, run and change a real project with uv (uv init, uv add, uv run, uv.lock, uv sync)
  • how to install the same project with pip and venv
  • how Poetry does the same job, in brief
  • how uv, pip and Poetry compare, and which one to pick

Before you start: finish Lesson 30, Python Virtual Environments with venv. You also need pip from Lesson 29. We ran everything on Ubuntu 24.04 (Linux) with Python 3.14.6, uv 0.13.7 and Poetry 2.5.1, the newest uv and Poetry on PyPI on our test day. The newest Python on python.org is 3.15.2.

What pyproject.toml is

The Python Packaging User Guide describes pyproject.toml as “a configuration file used by packaging tools”. It lives in the top folder of your project. One file describes the project, and many tools understand it.

The file is written in TOML, a simple settings format:

  • [project] starts a table, a group of settings. A table is a bit like a dictionary.
  • name = "shop-report" is a key with a text value.
  • dependencies = ["rich>=15.0.0"] is a list.

The guide lists four tables: [build-system] (how to build the project), [project] (the project’s details), [dependency-groups] (development tools, such as test tools) and [tool] (settings for one tool, like [tool.poetry]). Let’s see them in a real project.

Create a project with uv init

uv calls itself “an extremely fast Python package and project manager, written in Rust”. It is a separate program; its installation page shows how to install it on Windows, macOS and Linux. uv init creates a new project folder:

$ uv --version
uv 0.13.7 (x86_64-unknown-linux-gnu)
$ uv init shop-report
Initialized project `shop-report` at `/home/learner/python-course/shop-report`
$ cd shop-report
$ ls -A
.git  .gitignore  .python-version  README.md  pyproject.toml  src
$ cat pyproject.toml
[project]
name = "shop-report"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
    { name = "Learner", email = "learner@example.com" }
]
requires-python = ">=3.14"
dependencies = []

[project.scripts]
shop-report = "shop_report:main"

[build-system]
requires = ["uv_build>=0.13.7,<0.14.0"]
build-backend = "uv_build"

uv also started a Git repository (.git, .gitignore) and took the author from the Git settings of our test user, “Learner”.

The pyproject.toml file, line by line

  • name and version are required. The guide says name “is the only field that cannot be marked as dynamic”, which means filled in later by a tool.
  • description, readme and authors are information for people. uv put a placeholder description; change it.
  • requires-python = ">=3.14" means “this project needs Python 3.14 or newer”. The guide says it lets you “declare the minimum version of Python that you support”.
  • dependencies = [] is the list of packages your project needs. It is empty for now.
  • [project.scripts] makes a command called shop-report that runs the main() function in the shop_report package.
  • [build-system] names the tool that turns your code into an installable package, here uv_build. The guide says this table “should always be present, regardless of which build backend you use”. The uv docs note that before uv 0.12, uv init did not add a build system for applications, so older tutorials show a main.py file and no [build-system].

The code lives in src/shop_report/__init__.py. A folder with an __init__.py file is a package, as in Lesson 28.

Run it and add a dependency with uv

$ cat .python-version
3.14
$ cat src/shop_report/__init__.py
def main() -> None:
    print("Hello from shop-report!")
$ uv run shop-report
Using CPython 3.14.6
Creating virtual environment at: .venv
   Building shop-report @ file:///home/learner/python-course/shop-report
      Built shop-report @ file:///home/learner/python-course/shop-report
Installed 1 package in 1ms
Hello from shop-report!
  • .python-version tells uv which Python to use for the venv.
  • uv run created the .venv virtual environment and a uv.lock file, installed our project into the venv and ran the shop-report command. There was nothing to activate.

Now add a package. rich prints nice tables in the terminal:

$ uv add rich
Resolved 5 packages in 197ms
   Building shop-report @ file:///home/learner/python-course/shop-report
      Built shop-report @ file:///home/learner/python-course/shop-report
Downloading pygments (1.2MiB)
 Downloaded pygments
Prepared 5 packages in 133ms
Uninstalled 1 package in 0.67ms
Installed 5 packages in 9ms
 + markdown-it-py==4.2.0
 + mdurl==0.1.2
 + pygments==2.21.0
 + rich==15.0.0
 ~ shop-report==0.1.0 (from file:///home/learner/python-course/shop-report)
$ grep -A 3 "^dependencies" pyproject.toml
dependencies = [
    "rich>=15.0.0",
]

$ ls -A
.git  .gitignore  .python-version  .venv  README.md  pyproject.toml  src  uv.lock

One command wrote "rich>=15.0.0" into dependencies, found the three packages rich needs, installed them into .venv and updated uv.lock. + marks new packages and ~ our reinstalled project. Your times will differ.

uv run and the uv.lock file

Replace the code in src/shop_report/__init__.py with this program:

from rich.console import Console
from rich.table import Table


def main() -> None:
    table = Table(title="Shop report")
    table.add_column("Item")
    table.add_column("Price", justify="right")
    for item, price in [("Notebook", 450), ("Pen", 60), ("Backpack", 3200)]:
        table.add_row(item, str(price))
    Console().print(table)
$ uv run shop-report
    Shop report     
┏━━━━━━━━━━┳━━━━━━━┓
┃ Item     ┃ Price ┃
┡━━━━━━━━━━╇━━━━━━━┩
│ Notebook │   450 │
│ Pen      │    60 │
│ Backpack │  3200 │
└──────────┴───────┘
$ grep -c "^\[\[package\]\]" uv.lock
5
$ grep -A 2 '^name = "rich"' uv.lock
name = "rich"
version = "15.0.0"
source = { registry = "https://pypi.org/simple" }

pyproject.toml says what you want (“rich 15.0.0 or newer”). uv.lock records what you got: the exact version of all 5 packages (our project and four from PyPI), so every computer gets the same ones. The uv project guide says uv.lock “should be checked into version control” and “should not be edited manually”.

uv vs pip diagram from Lesson 31: pyproject.toml lists rich>=15.0.0, uv.lock pins the exact versions of 5 packages, and uv sync builds the .venv folder from the lock file.
pyproject.toml says what you want, uv.lock records the exact versions you got, and uv sync turns the lock file into a .venv folder.

The venv itself can always be rebuilt from the lock file. Delete it and run uv sync:

$ rm -rf .venv
$ uv sync
Using CPython 3.14.6
Creating virtual environment at: .venv
Resolved 5 packages in 0.88ms
Installed 5 packages in 7ms
 + markdown-it-py==4.2.0
 + mdurl==0.1.2
 + pygments==2.21.0
 + rich==15.0.0
 + shop-report==0.1.0 (from file:///home/learner/python-course/shop-report)
$ uv run shop-report
    Shop report     
┏━━━━━━━━━━┳━━━━━━━┓
┃ Item     ┃ Price ┃
┡━━━━━━━━━━╇━━━━━━━┩
│ Notebook │   450 │
│ Pen      │    60 │
│ Backpack │  3200 │
└──────────┴───────┘

This is what a teammate does after cloning your project: uv sync, then uv run. Nothing was downloaded this time, because uv reused the packages in its cache.

The same project with pip and venv

pip reads pyproject.toml too. We copy the code and pyproject.toml (not .venv or uv.lock) into a new folder, make a venv by hand (Lesson 30) and install the project with pip install -e .. The dot means “the project in this folder”, and -e (editable) means changes to your code work without reinstalling:

$ mkdir shop-report-pip
$ cd shop-report-pip
$ cp -r ../shop-report/src ../shop-report/pyproject.toml ../shop-report/README.md .
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -m pip install -e .
Obtaining file:///home/learner/python-course/shop-report-pip
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting rich>=15.0.0 (from shop-report==0.1.0)
  Downloading rich-15.0.0-py3-none-any.whl.metadata (18 kB)
Collecting markdown-it-py>=2.2.0 (from rich>=15.0.0->shop-report==0.1.0)
  Downloading markdown_it_py-4.2.0-py3-none-any.whl.metadata (7.4 kB)
Collecting pygments<3.0.0,>=2.13.0 (from rich>=15.0.0->shop-report==0.1.0)
  Downloading pygments-2.21.0-py3-none-any.whl.metadata (2.5 kB)
Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich>=15.0.0->shop-report==0.1.0)
  Downloading mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)
Downloading rich-15.0.0-py3-none-any.whl (310 kB)
Downloading pygments-2.21.0-py3-none-any.whl (1.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 3.9 MB/s  0:00:00

Downloading markdown_it_py-4.2.0-py3-none-any.whl (91 kB)
Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Building wheels for collected packages: shop-report
  Building editable for shop-report (pyproject.toml) ... done
  Created wheel for shop-report: filename=shop_report-0.1.0-py3-none-any.whl size=1664 sha256=143f69eb69fd9bd3a46593bd770839502987daac9528cb3db07299af33564daa
  Stored in directory: /tmp/pip-ephem-wheel-cache-mzqf_9p2/wheels/a5/77/2c/873158bbaf35579184cd8e5edba53e1416fe50319526ab91f3
Successfully built shop-report
Installing collected packages: pygments, mdurl, markdown-it-py, rich, shop-report


Successfully installed markdown-it-py-4.2.0 mdurl-0.1.2 pygments-2.21.0 rich-15.0.0 shop-report-0.1.0
(.venv) $ shop-report
    Shop report     
┏━━━━━━━━━━┳━━━━━━━┓
┃ Item     ┃ Price ┃
┡━━━━━━━━━━╇━━━━━━━┩
│ Notebook │   450 │
│ Pen      │    60 │
│ Backpack │  3200 │
└──────────┴───────┘
(.venv) $ python -m pip freeze
markdown-it-py==4.2.0
mdurl==0.1.2
Pygments==2.21.0
rich==15.0.0
# Editable install with no version control (shop-report==0.1.0)
-e /home/learner/python-course/shop-report-pip

The same pyproject.toml worked. (The speed, hash and temporary folder name vary on every run.) pip read [build-system], installed the uv_build tool to build our project, then installed rich and its helpers from dependencies.

The difference is the extra work. With pip you create and activate the venv yourself, you type new packages into dependencies by hand and run pip install -e . again, and there is no lock file. Most pip users save exact versions with pip freeze > requirements.txt. pip also has a pip lock command that writes a pylock.toml file, but the pip docs still mark it “EXPERIMENTAL”.

Poetry in brief

Poetry is another all-in-one tool that many teams use. Its docs say to install it in its own environment, for example with pipx install poetry, and never “in the environment of the project”. Poetry needs Python 3.10 or newer. Here is a new project with Poetry 2.5.1:

$ poetry --version
Poetry (version 2.5.1)
$ poetry new shop-report-poetry
Created package shop_report_poetry in shop-report-poetry
$ cd shop-report-poetry
$ cat pyproject.toml
[project]
name = "shop-report-poetry"
version = "0.1.0"
description = ""
authors = [
    {name = "Learner",email = "learner@example.com"}
]
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
]

[tool.poetry]
packages = [{include = "shop_report_poetry", from = "src"}]

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
$ poetry add rich
Creating virtualenv shop-report-poetry-VI2X_M0w-py3.14 in /root/.cache/pypoetry/virtualenvs
Using version ^15.0.0 for rich

Updating dependencies
Resolving dependencies...

Package operations: 4 installs, 0 updates, 0 removals

  - Installing mdurl (0.1.2)
  - Installing markdown-it-py (4.2.0)
  - Installing pygments (2.21.0)
  - Installing rich (15.0.0)

Writing lock file
$ grep -A 3 "^dependencies" pyproject.toml
dependencies = [
    "rich (>=15.0.0,<16.0.0)"
]

$ poetry run python -c "import rich, sys; print(sys.prefix)"
/root/.cache/pypoetry/virtualenvs/shop-report-poetry-VI2X_M0w-py3.14
  • Poetry 2 uses the same standard [project] table. Its pyproject docs say “With Poetry 2.0, you should consider using the project.dependencies section”. Older tutorials show the Poetry 1 style, [tool.poetry.dependencies].
  • Poetry-only settings go in [tool.poetry], and the build tool is poetry-core.
  • poetry add wrote rich (>=15.0.0,<16.0.0): by default Poetry also blocks the next major version, while uv wrote only >=15.0.0.
  • It wrote poetry.lock, the same idea as uv.lock. The basic usage page says application developers should commit it.
  • The venv is not in the project folder. By default Poetry keeps it in its cache folder; here that is /root/.cache/pypoetry/virtualenvs, because our test machine runs as the root user, and the VI2X_M0w part differs on each computer. poetry run runs a command inside it.

uv vs pip vs Poetry: comparison

Questionpip + venvuvPoetry
Comes with Python?YesNo, install it onceNo, install it once (pipx)
Creates the venvYou run python -m venv .venvAutomatic, .venv in the projectAutomatic, in Poetry’s cache folder by default
Adds a package to pyproject.tomlNo, edit it by handuv add richpoetry add rich
Lock fileNone by default (pip freeze, or the experimental pip lock)uv.lockpoetry.lock
Run your programActivate, then run ituv runpoetry run
Installs Python itselfNoYes, uv python installExperimental, poetry python install
Build tool in our projectAny (it used uv_build here)uv_buildpoetry-core

The uv docs claim uv is “10-100x faster than pip”; we did not measure that, but in our runs uv’s install steps took milliseconds. And poetry python install is marked “experimental” in the Poetry command docs.

Which one should you pick?

  • You are learning Python: use pip and venv first. They come with Python and show you what the other tools do for you.
  • You start a new project: uv is a good default. One tool makes the venv, edits pyproject.toml, writes the lock file and can even install Python (Lesson 2 showed uv python install).
  • Your team already uses Poetry: keep Poetry. Since version 2 it uses the standard [project] table.

All three read the same pyproject.toml, so you are not locked in: we installed the uv project with pip without changing a line.

Try it yourself

Exercise 1: Read pyproject.toml with Python

Python 3.11 and newer include tomllib, which reads TOML files. Write read_pyproject.py in the shop-report folder that prints the project name, requires-python, the dependencies and the build backend. The tomllib docs say the file must be opened in binary mode, "rb" (Lesson 32 explains with open()).

Exercise 2: Add a second package with uv

Add humanize to shop-report with uv, check the dependencies list, and print humanize.intcomma(3710) with uv run.

Exercise 3: Remove it again

Remove humanize with uv and check that dependencies contains only rich.

Solutions

Solution 1

import tomllib

with open("pyproject.toml", "rb") as f:
    data = tomllib.load(f)

project = data["project"]
print("Name:", project["name"])
print("Python:", project["requires-python"])
print("Dependencies:", project["dependencies"])
print("Build backend:", data["build-system"]["build-backend"])
$ python3 read_pyproject.py
Name: shop-report
Python: >=3.14
Dependencies: ['rich>=15.0.0']
Build backend: uv_build

tomllib.load() turns the file into normal dictionaries and lists, so data["project"]["name"] works like any dictionary lookup.

Solution 2

$ uv add humanize
Resolved 6 packages in 78ms
   Building shop-report @ file:///home/learner/python-course/shop-report
      Built shop-report @ file:///home/learner/python-course/shop-report
Prepared 2 packages in 86ms
Uninstalled 1 package in 4ms
Installed 2 packages in 2ms
 + humanize==4.16.0
 ~ shop-report==0.1.0 (from file:///home/learner/python-course/shop-report)
$ grep -A 4 "^dependencies" pyproject.toml
dependencies = [
    "humanize>=4.16.0",
    "rich>=15.0.0",
]

$ uv run python -c "import humanize; print(humanize.intcomma(3710))"
3,710

uv keeps the list in alphabetical order, and uv run python runs Python inside the project’s venv.

Solution 3

$ uv remove humanize
Resolved 5 packages in 14ms
   Building shop-report @ file:///home/learner/python-course/shop-report
      Built shop-report @ file:///home/learner/python-course/shop-report
Prepared 1 package in 5ms
Uninstalled 2 packages in 6ms
Installed 1 package in 1ms
 - humanize==4.16.0
 ~ shop-report==0.1.0 (from file:///home/learner/python-course/shop-report)
$ grep -A 3 "^dependencies" pyproject.toml
dependencies = [
    "rich>=15.0.0",
]

uv remove updates pyproject.toml, uv.lock and .venv together; the - line shows the removed package.

Common mistakes

  • Running the project with plain python3. The packages are in .venv, so python3 -c "import rich" fails with ModuleNotFoundError: No module named 'rich'. Use uv run, poetry run, or activate the venv.
  • Using pip inside a uv project. uv’s venv has no pip: uv run python -m pip --version printed /home/learner/python-course/shop-report/.venv/bin/python: No module named pip. Use uv add, so pyproject.toml and uv.lock stay correct.
  • Editing uv.lock or poetry.lock by hand. Change pyproject.toml (or use add and remove) and let the tool rewrite the lock file.
  • Committing .venv but not the lock file. It should be the other way round: commit pyproject.toml and the lock file, and let everyone rebuild the venv.
  • Installing Poetry into the project’s venv. Poetry’s docs say it should run in its own environment, so install it with pipx or its installer.

Frequently asked questions

Is uv better than pip?

For managing a whole project, uv does more: it creates the venv, edits pyproject.toml and writes a lock file, which pip does not do by default. pip is still the standard installer that comes with Python.

Do I still need requirements.txt if I have pyproject.toml?

Not with uv or Poetry: dependencies lists what you need and the lock file pins exact versions. With plain pip, many projects still use pip freeze > requirements.txt to pin exact versions.

Can I use pip with a project made by uv or Poetry?

Yes. Both write a standard [project] table and a [build-system] table, so pip install -e . works, as we showed. You lose the lock file’s exact versions, because pip does not read uv.lock or poetry.lock.

Summary

  • pyproject.toml describes a project: [project] (name, version, requires-python, dependencies) and [build-system] (the build tool).
  • uv: uv init creates the project, uv add adds packages, uv run runs it, uv.lock pins exact versions and uv sync rebuilds .venv.
  • pip + venv reads the same file with pip install -e ., but you edit dependencies by hand and have no lock file by default.
  • Poetry 2 uses the same [project] table, poetry add, poetry run and poetry.lock, with the venv in its cache folder.
  • Learn with pip, start new projects with uv, and keep Poetry where a team already uses it.

Next lesson

Next: Lesson 32, Python Read and Write Files: open(), with and encoding.

Sources

Ihsan Ullah

Written & tested by Ihsan Ullah

Data analyst with 3 years of experience and a Bachelor's degree in Computer Science. I write clear, practical guides on data, SQL, Python and AI.

More about me →

Leave a comment

Your email address will not be published. Required fields are marked *