Back to website
Mayank Aggarwal Learning Center

Phase 02 · Python FoundationsLesson 8 of 8

Modern Python Tooling with uv

Manage projects, dependencies and virtual environments the fast, modern way.

  • 25:56 video
  • 2 min read
  • Intermediate
01

The problem

Once you start real projects, you'll install packages: requests for HTTP, pandas for data, an LLM SDK for AI. Managing those packages badly leads to the classic "it works on my machine" problem. uv is a modern, extremely fast tool that handles Python versions, virtual environments and dependencies in one place.

02

The concept

The problem uv solves#

Without isolation, every project on your computer shares one set of installed packages. Project A needs version 1 of a library, project B needs version 2, and upgrading for one breaks the other.

The fix is a virtual environment: a private folder of packages for each project. uv creates and manages these for you automatically.

Without isolation

  • Every project shares one set of installed packages
  • Project A needs version 1, project B needs version 2
  • Upgrading for one breaks the other

Virtual environment

  • A private folder of packages for each project
  • Each project keeps its own versions
  • uv creates and manages it automatically

Core commands#

Terminal
uv init my-project        # create a new project
cd my-project
uv add requests           # install a package and record it
uv add --dev pytest       # a tool only needed during development
uv run main.py            # run your code inside the project's environment
uv remove requests        # uninstall

uv run makes sure the right environment exists and is up to date before running your script, so you rarely need to "activate" anything manually.

What uv creates#

FilePurpose
pyproject.tomlThe list of packages your project needs (human-edited)
uv.lockThe exact versions that were installed (machine-generated)
.venv/The virtual environment itself (don't commit this to git)

Why a lockfile matters#

pyproject.toml might say "requests, version 2 or later". The lockfile records exactly which version was installed, for example 2.32.3. When a teammate or a server runs uv sync, they get identical versions, so the code behaves the same everywhere.

uv vs pip#

You may see pip install in older tutorials. pip still works, but uv bundles what used to take several tools (pip, venv, pip-tools and Python version management) into one, and it's dramatically faster. For new projects, uv is the simpler choice.

Your project checklist#

  1. uv init the project.
  2. uv add every dependency you use.
  3. Run code with uv run.
  4. Commit pyproject.toml and uv.lock.

Your project checklist

  1. uv initcreate the project
  2. uv addevery dependency you use
  3. uv runrun your code
  4. Commitpyproject.toml and uv.lock

Every project you build in the rest of this roadmap, from RAG apps to agents, will follow these four steps.

03

Try it

Your task · about 10 minutes

Create a new project with uv init, add requests, and write a script that prints the status code of any website.

04

Recap & next

Key takeaways

  1. uv is a very fast Python package and project manager that covers what pip, venv and pip-tools do.
  2. Start a project with uv init, add packages with uv add requests, run code with uv run main.py.
  3. A lockfile (uv.lock) pins exact versions so the project installs the same everywhere.
  4. Virtual environments isolate each project's dependencies, so projects never break each other.

Quick check

2 questions · instant feedback

1Why use a virtual environment?
2What does a lockfile do?

Finished this lesson?

Mark it complete to track your progress and keep your streak going.

Next