1. Installation#

To install PyRIT as a library, the simplest way to do it is just pip install pyrit. This is documented here.

However, there are many reasons to install as a contributor. Yes, of course, if you want to contribute. But also because of the nature of the tool, it is often the case that targets/orchestrators/converters/core code needs to be modified. This section walks through how to install PyRIT as a contributor.

Prerequisite software#

This is a list of the prerequisites needed to run this library.

  1. Conda Install conda to create Python environments. (Note: Both Miniconda and Anaconda Distribution work for PyRIT. Read this guide for more on which download to choose.)

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

    git clone https://github.com/Azure/PyRIT
    

Note: PyRIT requires Python version 3.10, 3.11, or 3.12. If using Conda, you’ll set the environment to use this version. If running PyRIT outside of a python environment, make sure you have this version installed.

Installation#

This is a guide for how to install PyRIT into a conda environment.

  1. Navigate to the directory where you cloned the PyRIT repo. Make sure your current working directory has a pyproject.toml file.

    # Navigate to the root directory of the repository which contains the pyproject.toml file
    cd $GIT_PROJECT_HOME/pyrit
    
  2. Initialize environment.

    conda create -n pyrit-dev python=3.11
    

    This will prompt you to confirm the environment creation. Subsequently, activate the environment using

    conda activate pyrit-dev
    

    If you want to look at a list of environments created by conda run

    conda env list
    

    To install PyRIT dependencies run:

    cd $GIT_PROJECT_HOME
    pip install .
    

    OR to install PyRIT in editable mode for development purpose run:

    pip install -e .[dev]
    

    The suffix [dev] installs development-specific requirements such as pytest and pre-commit.

    On some shells quotes are required as follows:

    pip install -e '.[dev]'
    

    If you plan to use the Playwright integration (PlaywrightTarget), install with the playwright extra:

    pip install -e '.[dev,playwright]'
    

    After installing Playwright, install the browser binaries:

    playwright install
    

    See this post for more details.

Local Environment Setup#

PyRIT is compatible with Windows, Linux, and MacOS.

If you’re using Windows and prefer to run the tool in a Linux environment, you can do so using Windows Subsystem for Linux (WSL).

Alternatively, you can run the tool directly on Windows using PowerShell.

Visual Studio Code is the code editor of choice for the AI Red Team: Download here.

Running Jupyter Notebooks in VS Code#

note: When constructing a pull request, notebooks should not be edited directly. Instead, edit the corresponding .py file. See notebooks.md for more details.

Selecting a Kernel#

With a Jupyter Notebook (.ipynb file) window open, 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.

Jupyter Variables#

To view the variables that are populated by code examples, go to View > Output > Jupyter.

Populating Secrets#

See this for more details on populating secrets.