Andrea Telatin
Andrea Telatin Head of Bioinformatics at the Quadram Institute Bioscience, Norwich.

UV: A Fast Package Manager for Python

UV: A Fast Package Manager for Python

As a bioinformatician, you likely use Python packages like BioPython, scanpy, or scikit-bio. Installing and managing these packages has traditionally been done with pip or conda, but these tools can be slow.

Today, I want to introduce you to uv, a new blazingly fast package manager that can make your life easier.

Why Should You Care?

  1. Speed: uv is 10-100x faster than pip. When you’re setting up an environment with multiple bioinformatics packages (which often have complex dependency trees), this can reduce waiting time from minutes to seconds.

  2. Simplicity: Instead of juggling between pip, venv, and other tools, uv provides a unified interface for all package management tasks.

  3. Reliability: uv has better dependency resolution and creates reproducible environments, which is crucial for bioinformatics workflows.

Getting Started

First, install uv on your system:

1
2
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

Common Usage Scenarios

  1. Creating a New Environment for Your Analysis
1
2
3
4
5
6
7
8
9
10
# Create a new directory for your project
mkdir rna_analysis
cd rna_analysis

# Initialize a new Python project
uv init .

# Create and activate a virtual environment
uv venv
source .venv/bin/activate  # On Linux/MacOS
  1. Installing Packages
1
2
3
4
5
6
# Install commonly used bioinformatics packages
uv add numpy pandas scipy biopython
uv add scanpy anndata

# Install a specific version
uv add "scikit-learn==1.3.0"
  1. Running Scripts with Dependencies

Let’s say you have a script that needs specific packages. Instead of installing them globally, you can use uv to manage them:

1
2
3
4
5
6
7
8
# Create a new analysis script
echo 'import scanpy as sc; print(sc.__version__)' > analyze.py

# Add dependencies to the script
uv add --script analyze.py scanpy

# Run the script (uv will handle the environment automatically)
uv run analyze.py
  1. Using Bioinformatics Tools

Many bioinformatics tools are distributed as Python packages. You can use uvx to run them without installation:

1
2
3
4
5
# Run a tool without installing it permanently
uvx multiqc .

# If you use a tool frequently, install it permanently
uv tool install multiqc
  1. Managing Multiple Projects

If you work on different analyses that require different package versions:

1
2
3
4
5
6
7
8
9
# Each project can have its own environment and dependencies
mkdir project_a
cd project_a
uv init .
uv add "scanpy>=1.9.0"

cd ../project_b
uv init .
uv add "scanpy>=1.8.0,<1.9.0"  # Different version for different analysis
  1. Creating Reproducible Environments

To ensure reproducibility of your analysis:

1
2
3
4
5
# Lock your dependencies
uv lock

# On another machine or for sharing
uv sync  # This will install exact versions from the lock file

Pro Tips

  1. Use uv pip tree to visualize dependency relationships between packages
  2. If you need to check what versions are installed: uv pip list
  3. For cleaning up: uv cache clean will free up disk space
  4. Use uv python install 3.11 to install specific Python versions

Comparison with Conda

While uv doesn’t replace Conda/Mamba for managing non-Python packages, it’s an excellent alternative when you’re working with Python-only bioinformatics tools. It’s significantly faster and simpler to use for Python package management. ~

comments powered by Disqus