Set up a PyRIT development environment on your local machine.
**Development Version:** Contributor installations use the **latest development code** from the `main` branch, not a stable release. The notebooks in your cloned repository will match your code version.
uv is a fast Python package installer and resolver. We recommend it for PyRIT development.
Why uv?
- Much faster than pip (10-100x faster dependency resolution)
- Simpler than conda/mamba for pure Python projects
- Native Windows support — no WSL required, although if using a devcontainer, WSL is recommended
- Automatic virtual environment management
- Compatible with existing pyproject.toml
-
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 | shor
wget -qO- https://astral.sh/uv/install.sh | sh -
Python 3.12: uv will automatically download and use the correct Python version based on
.python-version -
Git. Git is required to clone the repo locally. It is available to download here.
git clone https://github.com/microsoft/PyRIT
-
Node.js and npm. Required for building the TypeScript/React frontend. Download Node.js (which includes npm). Version 18 or higher is recommended.
-
Navigate to the directory where you cloned the PyRIT repo.
-
The repository includes a
.python-versionfile that pins Python 3.12. Run:
uv sync --extra devThis command will:
- Create a
.venvdirectory with a virtual environment - Install Python 3.12 if not already available
- Install PyRIT in editable mode;
uv syncby default installs in editable mode so no extra flag is necessary - Install all dependencies including dev tools (pytest, black, ruff, etc.)
- Create a
uv.lockfile for reproducible builds
If you are having problems getting pip to install, try this link for details here: this post for more details.
- Verify Installation
uv pip show pyritYou should see output showing the most recent PyRIT version and your Python dependencies.
VS Code should automatically detect the .venv virtual environment. If not:
- Press
Ctrl+Shift+P - Type "Python: Select Interpreter"
- Choose
.venv\Scripts\python.exe
You can create a Jupyter kernel by first installing ipykernel:
uv add --dev ipykernelthen, create the kernel using:
uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=pyrit-devStart the server using
uv run jupyter labor 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.
Use uv run to execute Python with the virtual environment:
uv run python your_script.pyuv run pytest tests/uv run pytest tests/unit/test_something.pyuv run pyrit_scan --help
uv run pyrit_shelluv run jupyter labPyRIT 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 gcgEdit pyproject.toml to add dependencies, then run:
uv syncuv lock --upgrade
uv syncuv run black .
uv run ruff check --fix .uv run ty check pyrit/uv run pre-commit install
uv run pre-commit run --all-filesIf you prefer conda for environment management, you can use it to create a Python environment and install PyRIT for development.
-
Conda or Miniconda: Download from https://docs.anaconda.com/free/miniconda/
-
Git: Clone the repository:
git clone https://github.com/microsoft/PyRIT
-
Node.js and npm: Required for building the frontend. Download Node.js (version 18+).
- Create a conda environment with the correct Python version:
conda create -y -n pyrit-dev python=3.12
conda activate pyrit-dev- Navigate to the cloned PyRIT directory and install in editable mode with dev dependencies:
pip install -e .[dev]- Verify installation:
pip show pyritCreate 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 labAfter installing, configure your AI endpoint credentials.
Jump to [Configure PyRIT](./configuration.md) to set up your credentials.
Having issues? See the Local Dev Troubleshooting guide for common problems and solutions.