Introduction
When it comes to python package development tools, there are an increasing number of options available. You may have heard of tools like hatch and poetry, but there’s a new kid on the block. UV enables you to create python projects, manage environments, and even install different versions of python. All through the command line. In terms of performance, UV joins the ranks of python projects that use Rust as their core language. This makes it lightning fast compared to tools like poetry and pdm. Let’s jump into some usage so you can see how to leverage this incredible tool!
Install UV
First things first, you need to install uv using pip. Simple use the command below in your terminal.
pip install uv
Initialize Your First Project
Once you have uv, you can initialize a project by typing the following into your command terminal.
uv init demo
The result of this command will be a brand new python application project. You’ll notice that all essential files are created as well as a new git repository. With the creation of the new git repository, a .gitignore
file is also created with preloaded exclusions. This make it so you can easily publish to GitHub without including files that should be there. And this is probably one of my favorite features.
Initialize a Package Project
Let’s say that you want to create a python package project instead of an application. You can do this by modifying the init
command. Simply add --package
after the project name.
uv init demo2 --package
Now when you initialize the new project, you should see everything in a standard python package structure including the pyproject.toml
file. This file contains information needed to build and publish your package. By default, UV will use hatchling as the build tool, but you can select a different options such as flit, pdm, or maturin.
Why UV is Awesome for Project Creation
As you look through the two new python projects you just created, you’ll see that UV takes care of all of the setup for you including creation of the essential files. To give a quick recap, here are some of the highlights and benefits of initiating a project with UV.
- UV automatically creates a git repository with preloaded .gitignore.
- You can specify the type of project structure you want.
- You can pick the build backend you plan to use.