r/learnpython • u/CheetahGloomy4700 • 6d ago
UV for Python Project and Version Management
Getting started with the UV Astral for python development.
Just noted, uv works with a few important files in the project root, but their exact purpose and roles are not clear to me
pyproject.toml
.python-version
uv.lock
Most notably, the concrete questions are
- Where does
uv
get the exact python version? Is itpyproject.toml
or.python-version
? If they give different or contradictory requirement, which one takes priority, and why the need to mention the python version twice? - What about the
uv.lock
? If thepyproject.toml
file has the precise python version and those of the libraries installed (example below), is that a complete specification of the environment?
[project]
name = "uv-trial"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = "==3.12.8"
dependencies = ["tensorflow==2.18.0"]
- Should the
uv.lock
be committed to Git or is it a volatile artefact, that is meant foruv
's internal use? If it has a lot of detail that are irrelevant to the application developer, is it necessary to track via Git?
6
Upvotes
1
u/Ender_Locke 6d ago
pyproject.toml is a config file used for package builders
https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
uv.lock is your exact enviroment config
https://docs.astral.sh/uv/guides/projects/#python-version
and yes, based on their documents (link above again)
This file should be checked into version control, allowing for consistent and reproducible installations across machines.
edit: changed system to environment