UV: The Python Tool Everyone Is Switching To
Key Takeaways
The video demonstrates the use of UV, a fast and powerful all-in-one package manager for Python, which replaces tools like pip and virtualenv, and provides features like virtual environment management, package management, and dependency resolution. UV is implemented in Rust and has an aggressive caching strategy, making it a high-performance tool.
Full Transcript
Welcome to this video where we're going to take a look at UV, an all-in-one tool that will make working with your Python project simpler and faster. UV is a tool that handles your virtual environment, package management, dependency resolution, and Python version all in one place. It is also very fast. This basically allows it to replace a ton of other tools that you might already be using in your Python workflow. For example, I've been using pip and VM for over a decade myself, and I'm sure some of you have as well. But the increased speed and simplicity offered by UV is just too good to ignore. Which is why it's gained such rapid adoption and now even more so in the age of AI agents and MCP servers where it helps to have a simple way to manage and execute Python packages. So today, let's take a quick look at UV and how we can use it. First, I'll show you how to set up a project with UV and how it manages your virtual environment automatically. Then we'll look at package management and how UV replaces pip with something simpler and faster. Finally, we'll take a look at uvx, a oneline command that lets you run Python tools directly without having to manually set up or install them. Let's get started. First, let's install UV. If you're on Mac, you can use the brew package manager. If you're on Windows, you can use windget. Just run the command that you see here on the screen. Otherwise, if you're on another platform or you want to install it in a different way, then check out the official documentation for more instructions. Once it has been installed, you can verify that it's working by running this command to check the version. Now, let's create a project. We can build a simple API server to see how UV handles everything. You can create a project by using the init command followed by the name of the project. This will create the directory for you. Now, if you already have an existing project or an existing directory, uh you can also just run uv init without having to specify the project name. Behind the scenes, this init command will set up a couple of important files for you inside the project directory. The pi project file is where your project configuration lives. It's similar to package.json or uh the requirements.ext file that you might be used to. It will have all your project metadata and all of your dependencies in one place. Should use pretty straightforward. It also creates a readme file and a main py file as an entry point for your project. Once this is all set up, you can add a dependency by just running this uv command. For example, if I run this line, this will add the fast API dependency to our project configuration and it will also install it to our virtual environment. But wait, you might have noticed that we didn't explicitly create or activate a virtual environment yet. Well, that's exactly right. UV will create and manage this for us behind the scenes as long as we're in this project directory. Now, let's take a moment to pop over to the terminal so we can see this in action. Um, first I'll run UV version to confirm that it's installed. And now let's run this UV init command to create a project. So here it's actually created this directory for me and it's done it inside this folder. So we can go into that project now. And then if I list the files inside, I can see that it's got uh my main file, my project tommo file, and the readme file. Let's see what the main file looks like. Nothing special. It's literally just got this main function that prints hello world. So I can try running it by typing uvun main. And you can see here the first time I run something, it's actually creating uh a virtual environment for me. And it's also picking the Python version that it wants to use. Now let's try adding a dependency to the project. Okay, so I've just added fast API to my project. And then uh if I look in my project directory, I can see that a UV lock file has been created. So let's take a look at what that is. Um and you can see here this is a very long file that has the exact version of everything that I'm using in this project. Now let's open up our project in VS Code. Uh, I'm going to replace this main script with a simple fast API server. And you can see down here that the dependencies all work fine. And that's because VS Code has detected the virtual environment that has been created for us by UV. So if you have any problems where you've already installed the dependency, uh, but you see this editor complaining, then just make sure that you check the interpreter of Python down here and that it is set to the virtual environment for this project. And if you pop over into this pi project tommo file, you could also see that that fast API package has been added to this dependencies list. Now, if we want to run this script, let's go back to the terminal and instead of using the Python command, we will use uv run. Uh, and here you can run whatever you'd normally use Python to run except that this would use the correct virtual environment and it will also pull in any packages it needs to run this with. So, for example, uh, typically to run a fast API application, we'd run it using uicorn. Now, we didn't install Uvoicorn in this environment. So, let's see what happens when we run that. No problem at all. UV figures out that it needs this. So, it sets this up in an isolated environment and it's able to use that to run our app. And then, if we go to this URL over here, you will indeed see that the fast API server is running on our machine. Now, as you can probably see, this workflow is much simpler than what I had before, uh, which was a combination of VM and pip. Here's a snippet of the commands I'd previously run. It's using two different tools and it's not very intuitive. I have to create the virtual environment manually and also remember to activate it every time I want to work on the project. UV already really does help to simplify this part of the workflow. Now that we've got the basics down, let's take this up a notch and look at how UV handles package management differently from pip. The main difference here is that UV uses a proper dependency resolver and it creates a deterministic lock file. Let's run this command to add a couple of new dependencies to our project. UV uses this pi project tommo file instead of the requirements text file that we typically use with pip. So when we add new packages like with that command, it will also actually update this file for us. Uh which is something that pip doesn't automatically do for the requirements.ext file. So after running that command, you could see that the Reddus and SQL Alchemy dependencies have been added to our configuration. And as it's doing this, you could also see that it creates and updates our uv.lock file. Um, and this contains the exact version of every package used in the environment so that whenever you build this project, you get the exact same results. uh because what can happen is that without this version locking sometimes these packages come out with new versions that break compatibility with other packages or with your code. So version locking prevents this from happening and generally it's a really good practice for any production grade software. And if you wanted to check which packages have been installed, you can run this UV tree command. This will show you the dependency tree of your entire project along with the versions that have been installed. For development dependencies, UV keeps them separate. Just use this dev flag with the add command. Here, I'm just going to add the pi test framework to my project, but only for development purposes and not for the production build. And if we go back to the configuration file, you could see that pi test has been added under this dev dependency group. Now, if someone else clones your project fresh, uh, then you can run this uv sync command to set everything up. This will read the lock file and recreate the exact same environment so that you always get consistent builds with your project. You could also use this command whenever you update the dependencies in your project configuration file, whether that's to add or remove a package. it will figure out what to do. So, let's go ahead and try that here. Let's go to our project configuration file and just remove SQL Alchemy from the dependencies. So, I'm going to hit save there. And now, let's go back to the terminal. And here I'm going to type uv sync. And after running u you could see that it's uninstalled SQL Alchemy for us because it realizes that the environment is now different from the configuration. And then if I run it again after that, you could see that uh nothing's happened because it knows that the environment and the configuration are now in sync. Alternatively, instead of removing it from your configuration directly, you could also do it through the command line. So you could use uv remove and then the name of your package. And similarly, this will remove it from everywhere, your dependencies, your lock file, and your environment. Indeed, if we go back to our configuration file, you could see that Reddus is no longer here. Compared to something like pip, this is a much cleaner approach uh to managing your packages and keeping them in sync for your project. The last thing we're going to cover today is UVX, which is UV solution for running Python tools without installing them globally. Now, to demonstrate this, I've intentionally messed up the formatting of my main.py file. Let's say that you want to format this code with black, uh, but you don't want to add it to your project dependencies. Without UV, you'd have to either install it globally, risking version conflicts, or use something like pip X, which is yet another tool. Once again, UV simplifies this for us. You could just run a tool by using this UVX command followed by the name of the tool and any of its arguments. What happens behind the scenes is that UV will automatically create a temporary isolated environment for us, install this tool there, and then execute it. Uh, and this is also cached so that it's a lot faster the second time around. So, let's go ahead and try that out. Uh, the command works, so it's reformatted my file. And then if I go back to my editor, you could see that the formatting is now fixed. And once again, this didn't affect my project at all. This tool was completely isolated. Here are three different examples of other UVX commands you could use just to give you an idea of how it works. You could specify versions with it and you can generally run any tool that is available on Pippi. And if you have tools that you use frequently, you can also just install them. This will make them available globally, but will still keep them isolated from your system Python and from your projects. Now, this is a little bit off topic, but recently I've been looking at how to build AI agents that use MCP servers. And UVX is especially more relevant to me now because a lot of MCP servers are developed in Python. So if I'm working with my Cloud Code CLI agent and I want to use an MCP tool that someone else has built, for example, this Google Sheets tool over here, I can just use the UVX command to spin up that tool without ever having to install it or set up an environment for it myself. And it was this one use case alone that prompted me to start looking into UV as a tool. Now, one last thing I want to cover is that whenever UV is mentioned online, its speed is brought up as a significant advantage over traditional tools like pip. Partly because it is implemented in Rust, which is a high performance language, but also because of its aggressive caching strategy. However, the speed of a package manager has never really been a bottleneck for me personally. I didn't really focus on this aspect of UV because I don't think that it's something that makes or breaks uh a tool for me over other things like simplicity or reliability which I find much more important. One possible case where the speed of package or environment setup could be really useful to you is if you had a CI/CD pipeline or something similar where the Python build step is slow enough to be a bottleneck for you. Now, if you like the idea of UV and you just want to try it out, you don't have to wait until you have to start a new project. You can actually use it with your existing project right now. Uh, just install UV and then run UV in it. Your existing pipbased project will work fine. UV can read the requirements.ext file and help you migrate. So, give it a go and let me know what you think. Otherwise, I'll see you in the next one.
Original Description
UV is a fast, powerful all-in-one package manager for Python that replaces tools like pip and virtualenv. Let's take a look at what it is, how to use it, and why many Python developers are switching to this.
👉 Links
🔗 UV GitHub: https://github.com/astral-sh/uv
🔗 How To Install: https://docs.astral.sh/uv/getting-started/installation
📚 Chapters
00:00 What is UV?
01:14 Project and Environment Setup
05:44 Package Management
08:59 Run Tools with uvx
11:03 UV Speed
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from pixegami · pixegami · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to Build an AWS Lambda Function in Python in Just 7 Minutes!
pixegami
AWS CDK Tutorial: Deploy a Python Lambda Function using AWS
pixegami
I used GPT-3 to Write Poetry • Is AI the Future of Creative Writing?
pixegami
Create NFT Generative Art with Python! (Full Tutorial)
pixegami
Build an AI-driven SaaS Application: FULLSTACK Tutorial with Python, React, and AWS
pixegami
NextJS and TailwindCSS: How to Build a Portfolio Site from Scratch
pixegami
Python Web Scraping Tutorial • Step by Step Beginner's Guide
pixegami
Build Wordle in Python • Word Game Python Project for Beginners
pixegami
How to create 1000+ unique NFT-style images (like Cryptopunk) | Python Tutorial
pixegami
Top 10 Python Modules 2022
pixegami
How to Send SMS Text Messages with Python & Twilio - Quick and Simple!
pixegami
How To Write Unit Tests in Python • Pytest Tutorial
pixegami
How to Style Your React Landing Page with Tailwind CSS
pixegami
FastAPI Python Tutorial - Learn How to Build a REST API
pixegami
How to Deploy FastAPI on AWS EC2: Quick and Easy Steps!
pixegami
PyScript • How to run Python in a browser
pixegami
My Custom Ubuntu Linux Terminal with Themes and Plug-ins 💻
pixegami
Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
pixegami
NextJS Firebase Auth Tutorial • How to Authenticate Users for Your App
pixegami
AWS Lambda Python functions with a database (DynamoDB)
pixegami
How To Build a CRUD (TO-DO) App on AWS using FastAPI and Python
pixegami
How to Make a Discord Bot with Python
pixegami
How To Use GitHub Copilot (with Python Examples)
pixegami
PyTest • REST API Integration Testing with Python
pixegami
Python Beginner Project: Build a Caesar Cipher Encryption App
pixegami
Decorators in Python: How to Write Your Own Custom Decorators
pixegami
NextJS 13 Tutorial: Create a Static Blog from Markdown Files
pixegami
Exploring ChatGPT for Coding and Business ✨ 8 Real Examples!
pixegami
How I Would Learn Python (if I had to start over) • A Roadmap for 2023
pixegami
Build an AI Pokemon Generator with Python and Midjourney
pixegami
Why You Should Learn Python in 2023 (as your first programming language)
pixegami
ChatGPI API in Python ✨ How to Build a Custom AI Chat App
pixegami
Learn Python • #1 Installation and Setup • Get Started With Python!
pixegami
Learn Python • #2 Variables and Data Types • Python's Building Blocks
pixegami
Learn Python • #3 Operators • Add, Subtract and More...
pixegami
Learn Python • #4 Conditions • If / Else Statements
pixegami
Learn Python • #5 Lists • Storing Collections of Data
pixegami
Learn Python • #6 Loops • How to Repeat Code Execution
pixegami
Learn Python • #7 Dictionaries • The Most Useful Data Structure?
pixegami
Learn Python • #8 Tuples and Sets • More Ways To Store Data!
pixegami
Learn Python • #9 Functions • Python's Most Important Concept?
pixegami
Learn Python • #10 User Input • 4 Ways To Get Input From Your User
pixegami
Learn Python • #11 Classes • Create and Use Classes in Python
pixegami
Learn Python • #12 Final Project • Build an Expense Tracking App!
pixegami
Stripe & Firebase Tutorial • Add Payments To Your NextJS App
pixegami
How To Use GitHub Actions • Automate Your AWS Deployments
pixegami
How to Run a Python Docker Image on AWS Lambda
pixegami
My MacOS Terminal Setup for HIGH Productivity
pixegami
Host a Python Discord Bot on AWS Lambda (Free and Easy)
pixegami
Python FastAPI Tutorial: Build a REST API in 15 Minutes
pixegami
Pydantic Tutorial • Solving Python's Biggest Problem
pixegami
How to Get Started with AWS • Crash Course
pixegami
Python Requests Tutorial: HTTP Requests and Web Scraping
pixegami
Amazon Bedrock Tutorial: Generative AI on AWS
pixegami
How to Publish a Python Package to PyPI (pip)
pixegami
Langchain: The BEST Library For Building AI Apps In Python?
pixegami
RAG + Langchain Python Project: Easy AI/Chat For Your Docs
pixegami
Python Dataclasses: Here's 7 Ways It Will Improve Your Code
pixegami
Build a Custom AI RPG Game with OpenAI GPTs
pixegami
Create a Custom AI Assistant + API in 10 Mins
pixegami
More on: AI Pair Programming
View skill →Related Reads
Chapters (5)
What is UV?
1:14
Project and Environment Setup
5:44
Package Management
8:59
Run Tools with uvx
11:03
UV Speed
🎓
Tutor Explanation
DeepCamp AI