Python Integration

How Python commands integrate with the TypeScript CLI using UV and virtual environments.

Overview

Certain commands require Python (primarily Aider-based commands for code generation). The CLI manages Python environments automatically using UV.

Python Environment

Location: aider/.venv (UV-managed virtual environment)

Package manager: UV - Fast Python package installer

Dependencies: Defined in aider/pyproject.toml

How It Works

When you run a command that needs Python (e.g., wseng rca-fix):

  1. CLI checks if aider/.venv exists
  2. If not, creates it using UV
  3. Installs dependencies from aider/pyproject.toml
  4. Executes Python command in the virtual environment

This happens automatically - no manual setup required.

Adding Python Dependencies

To add a new Python dependency:

cd aider
uv add <package-name>
uv sync
cd ..

This updates aider/pyproject.toml and aider/uv.lock.

Python-Based Commands

Commands that use Python:

  • wseng rca-fix - Implements RCA fixes using Aider
  • wseng prompt-with-files - Code generation with Aider
  • Other Aider-based code modification commands

Calling Python from TypeScript

Example pattern:

import { exec } from "child_process";
import { promisify } from "util";

const execAsync = promisify(exec);

@Service()
export class MyPythonCommand implements TypedCommand {
    async execute() {
        const venvPath = path.join(__dirname, "../../../aider/.venv");
        const pythonBin = path.join(venvPath, "bin", "python");

        const { stdout } = await execAsync(`${pythonBin} -m my_module --arg value`);

        this.logger.info(stdout);
    }
}

Development Workflow

Developing Python features:

  1. Make changes to Python code in aider/ directory
  2. Test Python code directly:
    cd aider
    uv run python -m my_module
    
  3. Integrate with TypeScript command
  4. Test full CLI command:
    pnpm run build
    wseng my-command
    

Why UV?

UV is significantly faster than pip/conda:

  • 10-100x faster package installation
  • Built-in virtual environment management
  • Compatible with pip/PyPI packages
  • Lockfile support for reproducible builds

Troubleshooting

Python not found:

  • Ensure Python 3.x is installed and in PATH
  • Run python --version or python3 --version to verify

Dependencies out of sync:

cd aider
uv sync --reinstall
cd ..

Virtual environment corrupted:

rm -rf aider/.venv
wseng <python-command>  # Will recreate automatically

Learn how to create commands that call Python.

Understanding the broader CLI architecture.