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.

pyrit.setup

Module containing initialization PyRIT.

Functions

get_lazy_dir

get_lazy_dir(module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → list[str]

Return package attributes and unresolved public exports.

ParameterTypeDescription
module_globalsdict[str, Any]The package globals.
exportsMapping[str, LazyExport]Public names and their implementation locations.

Returns:

initialize_from_config_async

initialize_from_config_async(config_path: str | pathlib.Path | None = None) → ConfigurationLoader

Initialize PyRIT from a configuration file.

This is a convenience function that loads a ConfigurationLoader from a YAML file and initializes PyRIT.

ParameterTypeDescription
config_pathstr | pathlib.Path | NonePath to the configuration file. If None, uses the default path (~/.pyrit/.pyrit_conf). Can be a string or pathlib.Path. Defaults to None.

Returns:

Raises:

Examples:

initialize_pyrit_async

initialize_pyrit_async(memory_db_type: MemoryDatabaseType | str, initialization_scripts: Sequence[str | pathlib.Path] | None = None, initializers: Sequence[PyRITInitializer] | None = None, load_defaults: bool = True, env_files: Sequence[pathlib.Path] | None = None, env_akv_ref: Sequence[str] | None = None, env_akv_strict: bool = True, silent: bool = False, seed: int | None = None, raise_on_initializer_error: bool = True, memory_instance_kwargs: Any = {}) → None

Initialize PyRIT with the provided memory instance and loads environment files.

ParameterTypeDescription
memory_db_typeMemoryDatabaseTypeThe MemoryDatabaseType string literal which indicates the memory instance to use for central memory. Options include “InMemory”, “SQLite”, and “AzureSQL”.
initialization_scriptsSequence[str | pathlib.Path] | NoneOptional sequence of local Python script paths that define PyRITInitializer subclasses. Every initializer subclass defined in each file is loaded and executed. Loading is handled by the InitializerRegistry. Defaults to None.
initializersSequence[PyRITInitializer] | NoneOptional sequence of PyRITInitializer instances to execute directly. These provide type-safe, validated configuration with clear documentation. Defaults to None.
load_defaultsboolIf True (default) AND the caller supplies neither initializers nor initialization_scripts, a default initializer set is run so a bare initialize_pyrit_async(...) yields a usable environment: the core attack-technique catalog (TechniqueInitializer, populating the AttackTechniqueRegistry) plus the available default targets (TargetInitializer, registering whatever endpoints are configured via env vars). Supplying any initializer or script means the caller owns setup, so the defaults are skipped; set this to False to also skip them on a bare call (e.g. to start from an empty state). Only the core techniques and default targets are loaded — extra / per-source technique groups and scorer target variants remain opt-in.
env_filesSequence[pathlib.Path] | NoneOptional sequence of environment file paths to load in order. Ordinary files fill missing process values; files named .env.local override. If omitted, PyRIT auto-discovers supported .env and .env.local files. Defaults to None.
env_akv_refSequence[str] | NoneOptional zero-or-one-item sequence containing an Azure Key Vault URL whose secret value is a bootstrap dotenv document. The document fills missing process values and supports complete-value references to scalar secrets. Requires azure-keyvault-secrets. Defaults to None.
env_akv_strictboolIf True, reject malformed bootstrap entries and Key Vault reference syntax. If False, warn and skip those entries. Operational Key Vault failures always raise. Defaults to True.
silentboolIf True, suppresses print statements about environment file loading and schema migration. Defaults to False.
seedint | NoneOptional root seed for deterministic converter operations. Converters derive independent named child streams automatically. Initialize PyRIT before constructing components whose defaults are selected randomly. This does not control remote model output. Defaults to None.
raise_on_initializer_errorboolIf True, raise when loading or executing an initializer fails. If False, log each failure and continue with the remaining initializers. Defaults to True.
**memory_instance_kwargsAny | NoneAdditional keyword arguments to pass to the memory instance. Azure SQL checks the schema without migrating by default. Pass skip_schema_migration=False to explicitly migrate a non-production database. SQLite retains automatic initialization. Defaults to {}.

Raises:

Examples:

resolve_lazy_export

resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → Any

Resolve and cache one package export.

ParameterTypeDescription
namestrPublic attribute requested from the package.
module_namestrPackage name used in an AttributeError.
module_globalsdict[str, Any]Package globals where the resolved value is cached.
exportsMapping[str, LazyExport]Public names and their implementation locations.

Returns:

Raises:

ConfigurationLoader

Bases: YamlLoadable

Loader for PyRIT configuration from YAML files.

This class loads configuration from a YAML file and provides methods to initialize PyRIT with the loaded configuration.

Attributes:

ParameterTypeDescription
memory_db_typestrThe type of memory database (in_memory, sqlite, azure_sql).
initializerslist[str | dict[str, Any]]List of initializer configurations (name + optional args).
initialization_scriptslist[str] | NoneList of paths to custom initialization scripts. None means “use defaults”, [] means “load nothing”.
env_fileslist[str] | NoneList of environment file paths to load. None means auto-discover supported .env and .env.local; [] means “load nothing”.
env_akv_reflist[str] | NoneList containing at most one Key Vault bootstrap secret URL.
env_akv_strictboolWhether malformed or valueless entries in a Key Vault bootstrap document should fail initialization.
custom_initializers_sourcestr | NoneLocal directory or Azure Blob container URI, optionally followed by a blob prefix, used to persist custom initializer Python scripts.
scenario_presets_sourcestr | NoneLocal directory or Azure Blob container URI, optionally followed by a blob prefix, used to persist scenario presets.
scenario_suites_sourcestr | NoneLocal directory or Azure Blob container URI, optionally followed by a blob prefix, used to persist scenario suites.
registry_recipes_sourcestr | NoneLocal directory or Azure Blob container URI, optionally followed by a blob prefix, used to persist saved targets, converters, scorers, and techniques.
silentboolWhether to suppress initialization messages.
seedint | NoneOptional root seed for deterministic converter operations.
operatorstr | NoneName for the current operator, e.g. a team or username.
operationstr | NoneName for the current operation.
enable_live_reinitializationboolWhether administrators may replace the live single-process backend runtime from the GUI.
target_upload_directorystr | NoneFolder that targets created through the backend API may upload local files from. When unset, those targets cannot be created through the API.

Examples:

Methods:

apply_prepared_reinitialization_async

apply_prepared_reinitialization_async(prepared: PreparedReinitialization) → None

Apply a preflighted replacement while preserving the current memory instance.

Raises:

from_dict

from_dict(data: dict[str, Any]) → ConfigurationLoader

Create a ConfigurationLoader from a dictionary.

ParameterTypeDescription
datadict[str, Any]Dictionary containing configuration values.

Returns:

Raises:

get_default_config_path

get_default_config_path() → pathlib.Path

Get the default configuration file path.

Returns:

initialize_pyrit_async

initialize_pyrit_async(raise_on_initializer_error: bool = True) → None

Initialize PyRIT with the loaded configuration.

Resolves the .pyrit_conf initializers to instances and calls the core initialize_pyrit_async function.

ParameterTypeDescription
raise_on_initializer_errorboolWhether initializer resolution, loading, validation, or execution failures should abort initialization. Defaults to True.

Raises:

load_with_overrides

load_with_overrides(config_file: pathlib.Path | None = None, memory_db_type: str | None = None, initializers: Sequence[str | dict[str, Any]] | None = None, initialization_scripts: Sequence[str] | None = None, env_files: Sequence[str] | None = None, env_akv_ref: Sequence[str] | None = None, env_akv_strict: bool | None = None, strict: bool = False) → ConfigurationLoader

Load configuration with optional overrides.

This factory method implements a 3-layer configuration precedence:

  1. Default config file (~/.pyrit/.pyrit_conf) if it exists

  2. Explicit config_file argument if provided

  3. Individual override arguments (non-None values take precedence)

ParameterTypeDescription
config_filepathlib.Path | NoneOptional path to a YAML-formatted configuration file. Defaults to None.
memory_db_typestr | NoneOverride for database type (in_memory, sqlite, azure_sql). Defaults to None.
initializersSequence[str | dict[str, Any]] | NoneOverride for initializer list. Defaults to None.
initialization_scriptsSequence[str] | NoneOverride for initialization script paths. Defaults to None.
env_filesSequence[str] | NoneOverride for environment file paths. Defaults to None.
env_akv_refSequence[str] | NoneOverride containing at most one Azure Key Vault bootstrap secret URL. Defaults to None.
env_akv_strictbool | NoneOverride for strict Key Vault bootstrap validation. Defaults to None.
strictboolReject malformed default layers instead of ignoring them. Defaults to False.

Returns:

Raises:

preflight_reinitialization_async

preflight_reinitialization_async(environment_values: dict[str, str]) → PreparedReinitialization

Validate replacement scripts and initializer configuration without changing live PyRIT state.

Returns:

Raises:

resolve_env_akv_ref

resolve_env_akv_ref() → list[str] | None

Return the AKV bootstrap secret URLs, or None when not configured.

Returns:

resolve_env_files

resolve_env_files() → Sequence[pathlib.Path] | None

Resolve environment file paths.

Returns:

resolve_initialization_scripts

resolve_initialization_scripts() → Sequence[pathlib.Path] | None

Resolve initialization script paths.

Returns:

resolve_initializers

resolve_initializers(raise_on_initializer_error: bool = True, registry: InitializerRegistry | None = None) → Sequence[PyRITInitializer]

Resolve initializer names to PyRITInitializer instances.

Uses the InitializerRegistry to look up initializer classes by name and instantiate them with optional arguments.

ParameterTypeDescription
raise_on_initializer_errorboolWhether to raise when an initializer cannot be resolved. If False, log the failure and continue resolving the remaining initializers. Defaults to True.
registryInitializerRegistry | NoneIsolated initializer registry to use instead of the live singleton. Defaults to None.

Returns:

Raises: