uv - .venv & Package Manager
Mastering uv by Astral(founder: Charlie Marsh). An ultra fast alternative to pip and conda for modern Python development.
Jan 11, 2026

๐ uv โ Modern Python Package & Environment Manager
uv is a fast, modern, and opinionated Python package manager designed to replace
pip, virtualenv, pip-tools, and partially even poetry.
It is written in Rust, which means it is:
- Extremely fast
- Deterministic
- Reproducible by default
โ Why uv?
Problems with the traditional Python workflow
- Manual virtual environment creation and activation
- Slow dependency resolution
requirements.txtdoes not guarantee reproducibility- Different environments across machines
- Global installation of tools like
ruff,black, etc.
What uv fixes
- โก Very fast dependency resolution (Rust-based)
- ๐ง Automatic virtual environment management
- ๐ Reproducible builds using
pyproject.toml&uv.lock
๐ฆ Installation
Official documentation:
https://docs.astral.sh/uv/getting-started/installation/
๐งฑ ๐ Initialize uv in the new or current existing project
(Automatically Creates Virtual Environment โ No Manual Setup)
uv automatically creates and manages the .venv for you.
You never need to activate or configure it manually.
๐น SYNTAX
To initialze uv in a new project(with default available python version)
uv init app_name
OR
To initialze uv in a new project(with specific/particular python version)
uv init app_name -p <python-version>
OR
To Initialize uv in the existing project(with specific python version)
uv init -p <python-version>
OR
To Initialize uv in the existing project(without specific python version)
uv init .
๐น EXAMPLES
โก๏ธ Default project structure
uv init new_app --app
OR
uv init -p 3.14.2
OR
uv init -p 3.14.2 .
OR
uv init --python 3.14.2 .
โก๏ธ Build app as a Python package
uv init new_app --lib
๐ข Install partiuclar python version that you need inside uv environment
๐น Syntax
uv python install <version>
๐น Example
uv python install 3.13.3
To list the installed python versions in uv environment
๐น EXAMPLES:
To check all the installed(downloaded) python in the uv
uv python list
To check the current running version of python inside uv
uv run py -V
OR
uv run python --version
To uninstall :-
๐น Example
uv python uninstall 3.13.3
Creating virtual environment (.venv)
There are two ways to create .venv:-
One Way:- Creating .venv without any dependencies/packages installed.
uv venv
Another Way :- Creating .venv automatically while adding/installing dependencies/packages.
Syntax:-
uv add package_name
Example
uv add "fastapi[standard]"
uv add pydantic
uv add sqlalchemy
v add psycopg[binary]
๐ uv directory structure
uv directory structure
๐ Initializing uv in cloned remote project
๐ Syncing Environment
Use this when: - you have to synchronize .venv (or create a .venv) for a project.
How "uv sync" command works?
- It looks for the
pyproject.tomlfile and then createsuv.lockfile. - Now, using
uv.lockfile it creates .venv directory. - It is mostly used command.
uv sync --> searches pyproject.toml --> creates uv.lock ---> creates .venv (install all dependencies)
๐น Command
uv sync
๐ Locking / Freezing Environment
How "uv lock" command works?
- It looks for the
pyproject.tomlfile and then createsuv.lockfile, but doesn't creates .venv (no dependencies installation). - It is rarely used command.
uv lock --> searches pyproject.toml --> creates uv.lock (listing all minor dependencies without installation)
uv.lock file
โป๏ธ Migrate existing pip managed project to uv managed
If you already have a project created using pip and want to move it to uv:
โ No need to create a new project
โ No need to migrate manually
๐ช Step 1: Initialize uv
uv init
๐ช Step 2: Install all packages from requirements.txt
uv add -r requirements.txt
๐ป Run project using uv
There are two ways to run project:-
๐ก One Way:- Use uv run command each time.
๐น Syntax
uv run project_file.py
๐น Example 1
uv run main.py
If you are using django and you want to run server.
๐น Example 2
uv run python manage.py runserver
๐ Another Way :- Activate .venv manually and run command without uv
Activate virtual environment
For Windows:
.venv\Scripts\activate
For Linux:
source .venv/bin/activate
Run project file
๐น Example 1
python main.py
If you are using django and you want to run server.
๐น Example 2
python manage.py runserver
๐ Your existing project is now fully managed by uv.
โ Add a Package Using uv
๐น Syntax
uv add package_name
OR
uv add package_name1 package_name2 ...
๐น Example
uv add flask
OR
uv add pandas flask django
โ Remove Packages/Dependencies
Remove specific packages
๐น Syntax
uv remove package_name
๐น Example
uv remove flask
Remove all packages
Step 1 : Manually remove all dependencies from pyproject.toml
[project]
name = "new-app"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13.3"
dependencies = [] #empty dependencies list
Step 2 : Regenerates uv.lock with zero runtime dependencies.
uv lock
Step 3: Sync the environment
uv sync
This sync everything.
๐ณ Visualize Dependency Tree
See exactly which package depends on what:
uv tree
Helpful when debugging dependency conflicts.
ยฎ๏ธ Running Tools with uvx
โWhat is uvx? Why it is required?
uvx is a tool runner, similar to:
- pipx
- npx
It's job :
- Run CLI applications (like streamlit, black, ruff, pytest)
- Install them temporarily or globally
Use uvx when:
- Youโre running a tool
- The tool has a CLI
uvx does one core thing:
- Run a Python CLI tool via its entry point, in an isolated environment.
There are two different method to run tools:-
๐ Installs the tool into a persistent tool environment managed by uv
What it actually means :-
- Installs the tool into uv-managed tool environment, in a global location under your user home directory.
~/.local/share/uv/
- NOT your project .venv
- Creates a stable CLI command on your PATH
Consequences :-
- Tool is installed once
- Reused across projects
๐น Syntax
uv tool install tool_name
๐น Example Command
uv tool install ruff
Installs ruff into uvโs tool environment and exposes ruff on your PATH.
๐นRun the tool
ruff check
BONUS / TIPS
๐ What uv python pin actually does?
- Creates/updates .python-version
- Tells uv which interpreter to run commands with.
๐น Syntax
uv python pin python_version
๐น Example
uv python pin 3.13.3
โ Summary
- Automatic virtual environments
- Clean dependency management
- Reproducible builds via
uv.lock - Temporary tooling without system pollution
- Simple, fast, and reliable Python workflow