Module containing initialization PyRIT.
Functions¶
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.
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, silent: bool = False, 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` |
silent | bool | If True, suppresses print statements about environment file loading and schema migration. Defaults to False. Defaults to False. |
**memory_instance_kwargs | `Any | None` |
Raises:
ValueError— If an unsupported memory_db_type is provided or if env_files contains non-existent files.
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.
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:
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() → NoneInitialize PyRIT with the loaded configuration.
This method resolves all initializer names to instances and calls the core initialize_pyrit_async function.
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) → 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)
This is a staticmethod (not classmethod) because it’s a pure factory function that doesn’t need access to class state and can be reused by multiple interfaces (CLI, shell, programmatic API).
| 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` |
Returns:
ConfigurationLoader— A merged ConfigurationLoader instance.
Raises:
FileNotFoundError— If an explicitly specified config_file does not exist.ValueError— If the configuration is invalid.
resolve_env_akv_ref¶
resolve_env_akv_ref() → list[str] | NoneReturn the list of AKV secret URLs, or None when not configured.
Returns:
list[str] | None— list[str] | None: The configured AKV 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 Sequence of resolved Path objects if paths are specified.
resolve_initializers¶
resolve_initializers() → Sequence[PyRITInitializer]Resolve initializer names to PyRITInitializer instances.
Uses the InitializerRegistry to look up initializer classes by name and instantiate them with optional arguments.
Returns:
Sequence[PyRITInitializer]— Sequence of PyRITInitializer instances.
Raises:
ValueError— If an initializer name is not found in the registry.