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_path`strpathlib.Path

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_scripts`Sequence[strpathlib.Path]
initializers`Sequence[PyRITInitializer]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. Defaults to True.
env_files`Sequence[pathlib.Path]None`
env_akv_ref`Sequence[str]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. Defaults to False.
seed`intNone`
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. Defaults to True.
**memory_instance_kwargs`AnyNone`

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.

Examples:

Methods:

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. 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) → 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_file`pathlib.PathNone`
memory_db_type`strNone`
initializers`Sequence[strdict[str, Any]]
initialization_scripts`Sequence[str]None`
env_files`Sequence[str]None`
env_akv_ref`Sequence[str]None`
env_akv_strict`boolNone`

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) → 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.

Returns:

Raises: