#268: Manage Projects With uv
Last week we explored the uv tool and saw how much of pip we can reuse while profiting from the massive speed boost. In this post we explore the final part of uv and see how it can help us to manage our projects and prepare our package for pypi.org.
Create a project
The project management part of uv helps us with the set-up of our project. We can create a new project with this command:
This creates us a bunch of files and a skeleton for our code:
cd demo
ls
16/02/2025 12:26 <DIR> .
16/02/2025 12:26 <DIR> ..
16/02/2025 12:26 109 .gitignore
16/02/2025 12:26 5 .python-version
16/02/2025 12:26 82 main.py
16/02/2025 12:26 150 pyproject.toml
16/02/2025 12:26 0 README.md
If we already have a folder with Python files, we can skip the project name:
Manage packages
When we add the first package, uv puts it into the dependencies list of the *.toml file and creates a virtual environment for us:
Should the virtual environment not be activated automatically, we can run this script to activate it:
To pin the current environment with all its dependencies, we can create a lock file with this command:
If we prefer a requirements.txt file, we can convert it with this command:
When we want to sync our virtual environment with our requirements.txt or the lock file, we can use this command:
To upgrade the packages in the lock file, we can use this command:
If we only want to update a specific package, we can specify it:
Create a package
To bundle up our package, we can use this command:
This creates us these files inside the dist folder:
ls dist
16/02/2025 15:14 <DIR> .
16/02/2025 15:14 <DIR> ..
16/02/2025 15:14 1 .gitignore
16/02/2025 15:14 1,205 demo-0.1.0-py3-none-any.whl
16/02/2025 15:14 958 demo-0.1.0.tar.gz
We can kick off the publishing step with this final command - given we have all our package details inside the *.toml file:
Conclusion
With uv we do not only get a faster pip replacement, but we also get a tool to install Python versions, manage packages and create virtual environments. All that makes uv a great helper that starts to shine if we have multiple virtual environments where we need to install mostly the same package versions. Not having to wait on the download for a package we just installed is something we only fully appreciate when we waited a long time with pip.