Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

 

UV

Dependency & Environment Manager

  • Written in Rust.
  • Syntax is lightweight.
  • Automatic Virtual environment creation.

Create a new project:

# Initialize a new uv project
uv init uv_helloworld

Sample layout of the directory structure

.
├── main.py
├── pyproject.toml
├── README.md
└── uv.lock
# Change directory
cd uv_helloworld

# Activate the Virtual environment

# Mac/Linux

source .venv/bin/activate

# Windows

.venv\Scripts\activate

# Verify the Virtual Python version

which python3

# add library (best practice)
uv add faker

# verify the list of libraries under virtual env
uv tree

# To find the list of libraries inside Virtual env

uv pip list

Edit the main.py

from faker import Faker
fake = Faker()
print(fake.name())

Run the script

uv run main.py

Summary

  • Written in Rust.
  • Syntax is lightweight.
  • Automatic Virtual environment creation.