Work with Virtual Environments
Angreal provides virtual environment management using UV, a fast Python package installer and resolver.
The virtual environment integration provides:
- Create and manage virtual environments
- Install packages and requirements
- Ensure specific Python versions
- Automatic environment activation for tasks
from angreal.integrations.venv import VirtualEnv
# Create a new environment
venv = VirtualEnv("myproject-env")
# Install packages
venv.install_packages(["django", "requests"])
# Install from requirements file
venv.install_requirements("requirements.txt")
from angreal.integrations.venv import venv_required
import angreal
@angreal.command(name="analyze", about="Run data analysis")
@venv_required(".venv", requirements=["pandas", "numpy"])
def analyze_data():
"""This function runs in an isolated environment."""
import pandas as pd
import numpy as np
# Your code here
from angreal.integrations.venv import VirtualEnv
# Create environment with specific Python version
venv = VirtualEnv("py312-env", python="3.12")
# List available Python versions
pythons = VirtualEnv.discover_available_pythons()
for version, path in pythons:
print(f"{version}: {path}")
- Virtual Environment API Reference - Complete API documentation
- Create Tasks - How to integrate environments with tasks
- Read the Virtual Environment API Reference for complete API documentation
- Learn about UV Integration Architecture for implementation details
- Explore Creating Tasks to integrate environments with your automation workflows