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.
| Parameter | Type | Description |
|---|---|---|
module_globals | dict[str, Any] | The package globals. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
list[str]— list[str]: Sorted package attribute names.
initialize_from_config_async¶
initialize_from_config_async(config_path: str | pathlib.Path | None = None) → ConfigurationLoaderInitialize PyRIT from a configuration file.
This is a convenience function that loads a ConfigurationLoader from a YAML file and initializes PyRIT.
| Parameter | Type | Description |
|---|---|---|
config_path | `str | pathlib.Path |
Returns:
ConfigurationLoader— The loaded ConfigurationLoader instance.
Raises:
FileNotFoundError— If the configuration file does not exist.ValueError— If the configuration is invalid.
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 = {}) → NoneInitialize PyRIT with the provided memory instance and loads environment files.
| Parameter | Type | Description |
|---|---|---|
memory_db_type | MemoryDatabaseType | The MemoryDatabaseType string literal which indicates the memory instance to use for central memory. Options include “InMemory”, “SQLite”, and “AzureSQL”. |
initialization_scripts | `Sequence[str | pathlib.Path] |
initializers | `Sequence[PyRITInitializer] | None` |
load_defaults | bool | If 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_strict | bool | If 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. |
silent | bool | If True, suppresses print statements about environment file loading and schema migration. Defaults to False. Defaults to False. |
seed | `int | None` |
raise_on_initializer_error | bool | If 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 | `Any | None` |
Raises:
TypeError— Ifenv_akv_strictis not a bool or seed is not an int or None.ValueError— If an unsupported memory_db_type is provided or env_files contains non-existent files.
Examples:
resolve_lazy_export¶
resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → AnyResolve and cache one package export.
| Parameter | Type | Description |
|---|---|---|
name | str | Public attribute requested from the package. |
module_name | str | Package name used in an AttributeError. |
module_globals | dict[str, Any] | Package globals where the resolved value is cached. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
Any— The resolved public value.
Raises:
AttributeError— Ifnameis not a declared lazy export.
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]) → ConfigurationLoaderCreate a ConfigurationLoader from a dictionary.
| Parameter | Type | Description |
|---|---|---|
data | dict[str, Any] | Dictionary containing configuration values. |
Returns:
ConfigurationLoader— A new ConfigurationLoader instance.
Raises:
_RemovedConfigurationOptionError— If the removedscenarioblock is present.ValueError— Ifextensionsis present but not a dict.
get_default_config_path¶
get_default_config_path() → pathlib.PathGet the default configuration file path.
Returns:
pathlib.Path— Path to the default config file in ~/.pyrit/.pyrit_conf
initialize_pyrit_async¶
initialize_pyrit_async(raise_on_initializer_error: bool = True) → NoneInitialize PyRIT with the loaded configuration.
Resolves the .pyrit_conf initializers to instances and calls the core
initialize_pyrit_async function.
| Parameter | Type | Description |
|---|---|---|
raise_on_initializer_error | bool | Whether initializer resolution, loading, validation, or execution failures should abort initialization. Defaults to True. Defaults to True. |
Raises:
ValueError— If configuration is invalid or initializers cannot be resolved.
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) → ConfigurationLoaderLoad configuration with optional overrides.
This factory method implements a 3-layer configuration precedence:
Default config file (~/.pyrit/.pyrit_conf) if it exists
Explicit config_file argument if provided
Individual override arguments (non-None values take precedence)
| Parameter | Type | Description |
|---|---|---|
config_file | `pathlib.Path | None` |
memory_db_type | `str | None` |
initializers | `Sequence[str | dict[str, Any]] |
initialization_scripts | `Sequence[str] | None` |
env_files | `Sequence[str] | None` |
env_akv_ref | `Sequence[str] | None` |
env_akv_strict | `bool | None` |
Returns:
ConfigurationLoader— A merged ConfigurationLoader instance.
Raises:
FileNotFoundError— If an explicitly specified config_file does not exist._RemovedConfigurationOptionError— If the removedscenarioblock is present.ValueError— If the configuration is invalid.
resolve_env_akv_ref¶
resolve_env_akv_ref() → list[str] | NoneReturn the AKV bootstrap secret URLs, or None when not configured.
Returns:
list[str] | None— list[str] | None: The configured AKV bootstrap secret URLs, orNone.
resolve_env_files¶
resolve_env_files() → Sequence[pathlib.Path] | NoneResolve environment file paths.
Returns:
Sequence[pathlib.Path] | None— None if field is None (use defaults), empty list if field is [],Sequence[pathlib.Path] | None— or Sequence of resolved Path objects if paths are specified.
resolve_initialization_scripts¶
resolve_initialization_scripts() → Sequence[pathlib.Path] | NoneResolve initialization script paths.
Returns:
Sequence[pathlib.Path] | None— None if field is None (use defaults), empty list if field is [],Sequence[pathlib.Path] | None— or a sequence of resolved Path objects.
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.
| Parameter | Type | Description |
|---|---|---|
raise_on_initializer_error | bool | Whether to raise when an initializer cannot be resolved. If False, log the failure and continue resolving the remaining initializers. Defaults to True. |
Returns:
Sequence[PyRITInitializer]— Sequence of PyRITInitializer instances.
Raises:
ValueError— If an initializer name is not found in the registry.