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):
- CLI checks if
aider/.venvexists - If not, creates it using UV
- Installs dependencies from
aider/pyproject.toml - 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 Aiderwseng 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:
- Make changes to Python code in
aider/directory - Test Python code directly:
cd aider uv run python -m my_module - Integrate with TypeScript command
- 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 --versionorpython3 --versionto verify
Dependencies out of sync:
cd aider
uv sync --reinstall
cd ..
Virtual environment corrupted:
rm -rf aider/.venv
wseng <python-command> # Will recreate automatically
Related Docs
Creating Commands
Learn how to create commands that call Python.
Command Architecture
Understanding the broader CLI architecture.