PyRIT Shell - Interactive REPL for PyRIT.
This module provides an interactive shell where PyRIT modules are loaded once at startup, making subsequent commands instant.
Functions¶
main¶
main() → intEntry point for pyrit_shell.
Returns:
int— Exit code.
print_deprecation_message¶
print_deprecation_message(old_item: type | Callable[..., Any] | str, new_item: type | Callable[..., Any] | str, removed_in: str) → NoneEmit a deprecation warning.
| Parameter | Type | Description |
|---|---|---|
old_item | `type | Callable[..., Any] |
new_item | `type | Callable[..., Any] |
removed_in | str | The version in which the deprecated item will be removed |
PyRITShell¶
Bases: cmd.Cmd
Interactive shell for PyRIT.
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
no_animation | bool | If True, skip the animated startup banner. Defaults to False. |
config_file | Optional[Path] | Path to a YAML configuration file. Defaults to None. |
database | Optional[str] | Database type (InMemory, SQLite, or AzureSQL). Defaults to None. |
initialization_scripts | Optional[list[Path]] | Initialization script paths. Defaults to None. |
initializer_names | Optional[list[Any]] | Initializer entries (names or dicts). Defaults to None. |
env_files | Optional[list[Path]] | Environment file paths to load in order. Defaults to None. |
log_level | Optional[int] | Logging level constant (e.g., logging.WARNING). Defaults to None. |
context | Optional[frontend_core.FrontendCore] | Deprecated. Pre-created FrontendCore context. Use the individual keyword arguments instead. Defaults to None. |
Methods:
cmdloop¶
cmdloop(intro: Optional[str] = None) → NoneOverride cmdloop to play animated banner before starting the REPL.
default¶
default(line: str) → NoneHandle unknown commands and convert hyphens to underscores.
do_clear¶
do_clear(arg: str) → NoneClear the screen.
do_exit¶
do_exit(arg: str) → boolExit the shell. Aliases: quit, q.
Returns:
bool— True to exit the shell.
do_help¶
do_help(arg: str) → NoneShow help. Usage: help [command].
do_list_initializers¶
do_list_initializers(arg: str) → NoneList all available initializers.
do_list_scenarios¶
do_list_scenarios(arg: str) → NoneList all available scenarios.
do_print_scenario¶
do_print_scenario(arg: str) → NonePrint detailed results for scenario runs.
do_run¶
do_run(line: str) → NoneRun a scenario.
do_scenario_history¶
do_scenario_history(arg: str) → NoneShows a numbered list of all scenario runs with the commands used.
emptyline¶
emptyline() → boolDon’t repeat last command on empty line.
Returns:
bool— False to prevent repeating the last command.
ScenarioResult¶
Scenario result class for aggregating scenario results.
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
scenario_identifier | ScenarioIdentifier | Identifier for the executed scenario. |
objective_target_identifier | Union[Dict[str, Any], TargetIdentifier] | Target identifier. |
attack_results | dict[str, List[AttackResult]] | Results grouped by atomic attack name. |
objective_scorer_identifier | Union[Dict[str, Any], ScorerIdentifier] | Objective scorer identifier. |
scenario_run_state | ScenarioRunState | Current scenario run state. Defaults to 'CREATED'. |
labels | Optional[dict[str, str]] | Optional labels. Defaults to None. |
completion_time | Optional[datetime] | Optional completion timestamp. Defaults to None. |
number_tries | int | Number of run attempts. Defaults to 0. |
id | Optional[uuid.UUID] | Optional scenario result ID. Defaults to None. |
objective_scorer | Optional[Scorer] | Deprecated scorer object parameter. Defaults to None. |
Methods:
get_objectives¶
get_objectives(atomic_attack_name: Optional[str] = None) → list[str]Get the list of unique objectives for this scenario.
| Parameter | Type | Description |
|---|---|---|
atomic_attack_name | Optional[str] | Name of specific atomic attack to include. If None, includes objectives from all atomic attacks. Defaults to None. Defaults to None. |
Returns:
list[str]— List[str]: Deduplicated list of objectives.
get_scorer_evaluation_metrics¶
get_scorer_evaluation_metrics() → Optional[ScorerMetrics]Get the evaluation metrics for the scenario’s scorer from the scorer evaluation registry.
Returns:
Optional[ScorerMetrics]— The evaluation metrics object, or None if not found.
get_strategies_used¶
get_strategies_used() → list[str]Get the list of strategies used in this scenario.
Returns:
list[str]— List[str]: Atomic attack strategy names present in the results.
normalize_scenario_name¶
normalize_scenario_name(scenario_name: str) → strNormalize a scenario name to match the stored class name format.
Converts CLI-style snake_case names (e.g., “foundry” or “content_harms”) to PascalCase class names (e.g., “Foundry” or “ContentHarms”) for database queries. If the input is already in PascalCase or doesn’t match the snake_case pattern, it is returned unchanged.
This is the inverse of ScenarioRegistry._class_name_to_scenario_name().
| Parameter | Type | Description |
|---|---|---|
scenario_name | str | The scenario name to normalize. |
Returns:
str— The normalized scenario name suitable for database queries.
objective_achieved_rate¶
objective_achieved_rate(atomic_attack_name: Optional[str] = None) → intGet the success rate of this scenario.
| Parameter | Type | Description |
|---|---|---|
atomic_attack_name | Optional[str] | Name of specific atomic attack to calculate rate for. If None, calculates rate across all atomic attacks. Defaults to None. Defaults to None. |
Returns:
int— Success rate as a percentage (0-100).