TECH

uv Python Package Manager for Faster Development

uv is a fast Python package and project manager written in Rust. Developed by Astral, it combines dependency management, virtual environments, Python version management, and command-line tool installation in one utility. It provides a unified workflow that can replace or complement tools such as pip, pipx, virtualenv, and pyenv.

Designed for both small scripts and larger applications, uv helps developers install packages, manage project dependencies, and create reproducible environments with fewer separate tools. Its optimized dependency resolver and caching system can make many operations significantly faster than traditional Python package management workflows, although actual performance depends on the project and environment.

Key Features of uv

Fast Package Installation and Resolution

uv uses an efficient implementation and global cache to reduce repeated downloads and package installation time. It supports dependency resolution and installation from Python package indexes, making it useful for local development and automated build pipelines.

Python Project and Dependency Management

Developers can initialize projects, add dependencies, generate lockfiles, and synchronize environments with a consistent set of commands. Lockfiles help preserve resolved dependency versions across development machines and CI/CD systems.

Python Version Management

uv can download and manage Python installations, allowing projects to use specific interpreter versions. This is helpful when maintaining applications that depend on different Python releases.

Script and Command-Line Tool Support

uv can execute Python scripts with declared dependencies and run command-line tools without requiring a permanent global installation. It also offers a pip-compatible interface for common package installation workflows.

How to Install uv

Choose an installation method that matches your operating system. The official documentation provides additional options and platform-specific instructions.

macOS and Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows PowerShell:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Install using pip:

python -m pip install uv

After installation, check the installed version:

uv --version

For security, review installer instructions and use trusted distribution channels, particularly on managed or production systems.

Create a Python Project with uv

Start a project, add a dependency, and synchronize its environment with the following commands:

uv init my_project
cd my_project
uv add requests
uv lock
uv sync

The uv init command creates a project structure, while uv add records a dependency in the project configuration. The lock and sync commands resolve dependency versions and align the environment with the project configuration.

To run a project command inside the managed environment, use:

uv run python main.py

Run Python Scripts with Dependencies

uv supports inline dependency metadata for standalone Python scripts. This approach is useful for automation tasks that need packages without a complete project setup.

uv add --script script.py requests
uv run script.py

uv resolves the script’s declared dependencies and runs it in an appropriate environment. Review scripts and their dependencies before execution, especially when they come from an untrusted source.

Manage Python Versions and CLI Tools

Install a Python version and pin the version required by a project:

uv python install 3.11
uv python pin 3.11

You can also install a command-line tool such as Ruff using uv:

uv tool install ruff
ruff --version

For temporary or on-demand tool execution, uvx provides a convenient alternative to installing a tool permanently:

uvx ruff --version

Update uv and Explore the Documentation

For installations managed by uv’s standalone installer, update the utility with:

uv self update

This command may not apply to installations managed through every package manager. Follow the update procedure for your original installation method when necessary.

Visit the official uv GitHub repository for source code, release notes, and installation details. Developers working with Python dependencies can also explore our guide to Gitleaks for detecting exposed secrets, which can help identify accidentally committed credentials in project repositories.

By bringing package installation, project management, Python version control, and tool execution into one interface, uv simplifies common development tasks. Its lockfile support and environment management make it a practical option for developers who want faster, more consistent Python workflows.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

2 weeks ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

2 weeks ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

2 weeks ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

2 months ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago