Phase 02 · Python FoundationsLesson 8 of 8
Modern Python Tooling with uv
Manage projects, dependencies and virtual environments the fast, modern way.
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.
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#
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#
| File | Purpose |
|---|---|
pyproject.toml | The list of packages your project needs (human-edited) |
uv.lock | The 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#
uv initthe project.uv addevery dependency you use.- Run code with
uv run. - Commit
pyproject.tomlanduv.lock.
Your project checklist
uv initcreate the projectuv addevery dependency you useuv runrun your code- Commit
pyproject.tomlanduv.lock
Every project you build in the rest of this roadmap, from RAG apps to agents, will follow these four steps.
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.
Recap & next
Key takeaways
uvis a very fast Python package and project manager that covers what pip, venv and pip-tools do.- Start a project with
uv init, add packages withuv add requests, run code withuv run main.py. - A lockfile (
uv.lock) pins exact versions so the project installs the same everywhere. - Virtual environments isolate each project's dependencies, so projects never break each other.
Quick check
2 questions · instant feedback
Go deeper
Finished this lesson?
Mark it complete to track your progress and keep your streak going.