Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Contributor Local Installation

Set up a PyRIT development environment on your local machine.

uv is a fast Python package installer and resolver. We recommend it for PyRIT development.

Why uv?

Prerequisites

  1. Install uv: Download from https://github.com/astral-sh/uv or use: for windows:

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

    for macOS and Linux

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

    or

    wget -qO- https://astral.sh/uv/install.sh | sh
  2. Python 3.12: uv will automatically download and use the correct Python version based on .python-version

  3. Git. Git is required to clone the repo locally. It is available to download here.

    git clone https://github.com/microsoft/PyRIT
  4. Node.js and npm. Required for building the TypeScript/React frontend. Download Node.js (which includes npm). Version 18 or higher is recommended.

Installation

  1. Navigate to the directory where you cloned the PyRIT repo.

  2. The repository includes a .python-version file that pins Python 3.12. Run:

uv sync --extra dev

This command will:

If you are having problems getting pip to install, try this link for details here: this post for more details.

  1. Verify Installation

uv pip show pyrit

You should see output showing the most recent PyRIT version and your Python dependencies.

VS Code Integration

VS Code should automatically detect the .venv virtual environment. If not:

  1. Press Ctrl+Shift+P

  2. Type “Python: Select Interpreter”

  3. Choose .venv\Scripts\python.exe

Running Jupyter Notebooks

You can create a Jupyter kernel by first installing ipykernel:

uv add --dev ipykernel

then, create the kernel using:

uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=pyrit-dev

Start the server using

uv run jupyter lab

or using VS Code, open a Jupyter Notebook (.ipynb file) window, in the top search bar of VS Code, type >Notebook: Select Notebook Kernel > Python Environments... to choose the pyrit-dev kernel when executing code in the notebooks, like those in examples. You can also choose a kernel with the “Select Kernel” button on the top-right corner of a Notebook.

This will be the kernel that runs all code examples in Python Notebooks.

Running Python Scripts

Use uv run to execute Python with the virtual environment:

uv run python your_script.py

Running Tests

uv run pytest tests/

Running Specific Test Files

uv run pytest tests/unit/test_something.py

Using PyRIT CLI Tools

uv run pyrit_scan --help
uv run pyrit_shell

Running Jupyter Notebooks

uv run jupyter lab

Installing Additional Extras

PyRIT has several optional dependency groups. Install them as needed:

# For Hugging Face models
uv sync --extra huggingface

# For all extras
uv sync --extra all

# Multiple extras
uv sync --extra dev --extra playwright --extra gcg

Development Workflow

Adding New Dependencies

Edit pyproject.toml to add dependencies, then run:

uv sync

Updating Dependencies

uv lock --upgrade
uv sync

Running Code Formatters

uv run black .
uv run ruff check --fix .

Running Type Checker

uv run mypy pyrit/

Pre-commit Hooks

uv run pre-commit install
uv run pre-commit run --all-files

Option 2: Conda

If you prefer conda for environment management, you can use it to create a Python environment and install PyRIT for development.

Prerequisites

  1. Conda or Miniconda: Download from https://docs.conda.io/en/latest/miniconda.html

  2. Git: Clone the repository:

    git clone https://github.com/Azure/PyRIT
  3. Node.js and npm: Required for building the frontend. Download Node.js (version 18+).

Installation

  1. Create a conda environment with the correct Python version:

conda create -y -n pyrit-dev python=3.12
conda activate pyrit-dev
  1. Navigate to the cloned PyRIT directory and install in editable mode with dev dependencies:

pip install -e .[dev]
  1. Verify installation:

pip show pyrit

Jupyter Kernel Setup

Create a Jupyter kernel for the conda environment:

pip install ipykernel
python -m ipykernel install --user --name=pyrit-dev --display-name "PyRIT Dev"

Then start Jupyter:

jupyter lab

Next Step: Configure PyRIT

After installing, configure your AI endpoint credentials.

Troubleshooting

Having issues? See the Local Dev Troubleshooting guide for common problems and solutions.