## Hey, ps, This is not another tool that comes and goes. This one here, is here to stay
In a fast paced world where there are new tools coming up every day and the focus is quickly shifting from tools to concept, allow me to plug you to one that will make your journey easier. Even better if you are a beginner.
UV by Astral
What Exactly does UV do?
To capture your attention fast, I will tell you what UV does then we can delve into the complexities of each task separately
Replaces Pip for package management
Replaces venv for creating virtual environments
Replaces pip tools and pip X
Runs python files in the project folder
All in one package!
Why do I need to replace all the above yet none has failed to function as it should?
Before someone sells me a new tool, to perform a task that I already do well, I usually ask this question. To answer it in this context, UV is faster than pip in pulling the packages and running the files in the folder. Also, with just one command, you are able to create a project folder, and have the following files automatically withing the folder
- toml file- This has the projects metadata and user dependencies
- uv.lock - This file is machine generated freeze/lock for identical reproducible builds
- main.py - This file is a placeholder for the python file you'd like to have
- .venv - This is a virtual environment that is autogenerated
- .git - This initializes git
- .gitignore - This stores some of the files that should not be shared on github such as passwords and logins
If you have used the packages earlier stated to create a virtual environment, initialize git for version control, install dependencies in your virtual environment or heavens forbid to reinstate your project if you've happened to delete your .venv you know the number of commands you will need to start or reinstate your project.
Having one command that does all that sounds just about perfect.
Now that I've taken you through the functions of UV and why it beats the existing packages, allow me to delve into the useful daily commands that can be used when using UV. You will have to begin with downloading uv. The docs have links for each specific operating system.
Navigating UV
uv init folder_name
This file command creates a folder with the name folder_name. In this folder is where you will find the 6 or more files that uv auto generates. If you have an existing folder, you can run cd existing_folder_name then run uv init in the folder
uv add package_name
This command is equivalent of pip install package_name and its used to download dependencies into the virtual environment
uv run file.py
This command is used to run the python file that is created in the folder. It is equivalent to python3 file.py
uv tree
This command is used to create a graphical structure indicating how the dependencies relate to each other like which dependency/package is dependent on which other one
uv
The command I found most interesting is uv. This command proceeds to list commands that are available in the package. Some of the commands are as below
uv remove- Used to remove dependenciesuv syc- used to update the project's environmentuv tool- used to run and install python toolsuv python- Used to manage python and its installations
Another very useful feature or should we call it fact about uv is its global caching. If one, for example, is running multiple projects which all require flask, requirements and say pandas, uv will only download the package once to be used for all projects which saves a lot of disk space as opposed to downloading a package for each time there is a new project
Also, should you lose your .venv, but still have your .toml and lock file, if you run the python file, .venv is automatically restored and is fast while at it.
Given its ease of use and one stop shop type of structure, I bet you will find it a useful tool. Make sure to give it a try. Also, give me a thumbs up to motivate me to write more of these.
Top comments (0)