Today, data science projects do not end with the concept test; Each project has the objective of being used in production. It is important, therefore, to deliver a high quality code. I have been working as a data scientist for more than ten years and I have noticed that young people generally have a weak level in development, which is understandable, because to be a data scientist needs to dominate mathematics, statistics, algorithm, development and development and Have knowledge in operational development. In this series of articles, I would like to share some tips and good practices to manage a professional data science project in Python. From Python to Docker, with a detour to Git, I will present the tools I use every day.
The other day, a colleague told me how I had to reinstall Linux due to incorrect manipulation with Python. He had restored an old project that he wanted to customize. As a result of installing and uninstalling packages and changing versions, its Python environment based on Linux was no longer functional: an incident that could easily have been avoided by configuring a virtual environment. But it shows how important it is to manage these environments. Fortunately, there is now an excellent tool for this: grape.
The origin of these two letters is not clear. According to Zanie Blue (one of the creators):
“We consider a ton Of names: It is really difficult to choose a name without collisions this day, so each name was a compensation balance. He gave us UV in Pypi, he is astral (that is, ultraviolet or universal), and it is short And easy to write. “
Now, let's enter a little more detail about this wonderful tool.
Introduction
UV is a modern and minimalist manager of Python projects and packages. Developed completely in Rust, it has been designed to simplify dependency management, the creation of the virtual environment and the organization of projects. UV has been designed to limit the common problems of the Python project, such as dependence and environmental management conflicts. Its objective is to offer a softer and more intuitive experience than traditional tools, such as the Pip + Virtualenv combo or the Conda administrator. It is claimed that it is 10 to 100 times faster than traditional managers.
Whether for small personal projects or in the development of Python applications for production, UV is a robust and efficient solution for package management.
Starting with UV
Facility
To install UV, if you are using Windows, I recommend using this command in a Shell:
winget install --id=astral-sh.uv -e
And, if you are in Mac or Linux, use the command:
To verify the correct installation, simply write the following command in a terminal:
uv version
Creation of a new Python project
Using UV, you can create a new project specifying the Python version. To start a new project, simply write in a terminal:
uv init --python x:xx project_name
python x:xx
must be replaced by the desired version (for example python 3.12
). If you do not have the specified Python version, UV will be in charge of this and download the correct version to start the project.
This command creates and automatically initializes a git repository called Project_name. Contains several files:
- TO
.gitignore
archive. List the elements of the repository that will be ignored in the git version (it is basic and must rewrite for a project ready to implement). - TO
.python-version
archive. Indicates the Python version used in the project. - He
README.md
archive. It has the purpose of describing the project and explains how to use it. - TO
hello.py
archive. - He
pyproject.toml
archive. This file contains all the information about the tools used to create the project. - He
uv.lock
archive. It is used to create the virtual environment when you use UV to execute the script (it can be compared to the requirements.txt)
Package installation
To install new packages in this next environment, you must use:
uv add package_name
When the add The command is used for the first time, UV creates a new virtual environment in the current work directory and installs the specified units. A .Vvenv/. In subsequent executions, UV will use the existing virtual environment and install or update only the new requested packages. In addition, UV has a powerful dependency resolution. When executing the add Command, UV analyzes the entire dependency chart to find a compatible set of packages versions that meet all requirements (package version and Python version). Finally, UV updates the Pyproject.toml and UV.lock files after each add domain.
To uninstall a package, write the command:
uv remove package_name
It is very important to clean the unused package of your environment. You must keep the dependency file as minimal as possible. If a package is not used or it is no longer used, it must be removed.
Run a python script
Now, your repository begins, your packages are installed and your code is ready to be tested. Can activate The virtual environment created as usual, but it is more efficient to use the UV command run
:
uv run hello.py
The use of the executing command guarantees that the script will be executed in the project virtual environment.
Manage Python versions
In general, it is recommended to use different versions of Python. As mentioned before the introduction, it can be working on an old project that requires an old version of Python. And it will often be too difficult to update the version.
uv python list
At any time, it is possible to change the Python version of your project. To do that, you have to modify the line Requires Python in it pyproject.toml
archive.
For example: requires-python = “> = 3.9”
Then you must synchronize your environment using the command:
uv sync
The first command verifies the existing Python facilities. If the requested version is not found, UV downloads and installs. UV also creates a new virtual environment in the project directory, replacing the previous one.
But the new environment does not have the required package. Therefore, after a synchronization command, you must write:
uv pip install -e .
Change from Virtualenv to UV
If you have a Python project started with PIP and Virtualenv and want to use UV, nothing could be simpler. If there is no requirements Archive, you must activate your virtual environment and then recover the package + installed version.
pip freeze > requirements.txt
Then, you must start the project with UV and install the units:
uv init .
uv pip install -r requirements.txt

Use the tools
UV offers the possibility of using tools through UV tool domain. The tools are python packages that provide command interfaces for fail, Pytests, Mypyetc To install a tool, write the command line:
uv tool install tool_name
But, a tool can be used without having been installed:
uv tool run tool_name
For convenience, an alias was created: UVXwhich is equivalent to UV tool execute. So, to execute a tool, just write:
uvx tool_name
Conclusion
UV is a powerful and efficient Python package administrator designed to provide a quick dependency resolution and installation. Significantly exceed traditional tools as nugget either conviction, Making it an excellent option to manage your Python projects.
Whether you are working on small or large projects, I recommend you have the habit of using UV. And believe me, try it means adopting it.
References
1 – UV documentation: https://docs.astral.sh/uv/
2 – UV GITHUB repository: https://github.com/astral-sh/uv
3 – An excellent Datacamp article: https://www.datacamp.com/tutorial/python-uv