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.cli.pyrit_shell

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() → int

Entry point for pyrit_shell.

Returns:

print_deprecation_message(old_item: type | Callable[..., Any] | str, new_item: type | Callable[..., Any] | str, removed_in: str) → None

Emit a deprecation warning.

ParameterTypeDescription
old_item`typeCallable[..., Any]
new_item`typeCallable[..., Any]
removed_instrThe version in which the deprecated item will be removed

PyRITShell

Bases: cmd.Cmd

Interactive shell for PyRIT.

Constructor Parameters:

ParameterTypeDescription
no_animationboolIf True, skip the animated startup banner. Defaults to False.
config_fileOptional[Path]Path to a YAML configuration file. Defaults to None.
databaseOptional[str]Database type (InMemory, SQLite, or AzureSQL). Defaults to None.
initialization_scriptsOptional[list[Path]]Initialization script paths. Defaults to None.
initializer_namesOptional[list[Any]]Initializer entries (names or dicts). Defaults to None.
env_filesOptional[list[Path]]Environment file paths to load in order. Defaults to None.
log_levelOptional[int]Logging level constant (e.g., logging.WARNING). Defaults to None.
contextOptional[frontend_core.FrontendCore]Deprecated. Pre-created FrontendCore context. Use the individual keyword arguments instead. Defaults to None.

Methods:

cmdloop

cmdloop(intro: Optional[str] = None) → None

Override cmdloop to play animated banner before starting the REPL.

default

default(line: str) → None

Handle unknown commands and convert hyphens to underscores.

do_clear

do_clear(arg: str) → None

Clear the screen.

do_exit

do_exit(arg: str) → bool

Exit the shell. Aliases: quit, q.

Returns:

do_help

do_help(arg: str) → None

Show help. Usage: help [command].

do_list_initializers

do_list_initializers(arg: str) → None

List all available initializers.

do_list_scenarios

do_list_scenarios(arg: str) → None

List all available scenarios.

do_print_scenario

do_print_scenario(arg: str) → None

Print detailed results for scenario runs.

do_run

do_run(line: str) → None

Run a scenario.

do_scenario_history

do_scenario_history(arg: str) → None

Shows a numbered list of all scenario runs with the commands used.

emptyline

emptyline() → bool

Don’t repeat last command on empty line.

Returns:

ScenarioResult

Scenario result class for aggregating scenario results.

Constructor Parameters:

ParameterTypeDescription
scenario_identifierScenarioIdentifierIdentifier for the executed scenario.
objective_target_identifierUnion[Dict[str, Any], TargetIdentifier]Target identifier.
attack_resultsdict[str, List[AttackResult]]Results grouped by atomic attack name.
objective_scorer_identifierUnion[Dict[str, Any], ScorerIdentifier]Objective scorer identifier.
scenario_run_stateScenarioRunStateCurrent scenario run state. Defaults to 'CREATED'.
labelsOptional[dict[str, str]]Optional labels. Defaults to None.
completion_timeOptional[datetime]Optional completion timestamp. Defaults to None.
number_triesintNumber of run attempts. Defaults to 0.
idOptional[uuid.UUID]Optional scenario result ID. Defaults to None.
objective_scorerOptional[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.

ParameterTypeDescription
atomic_attack_nameOptional[str]Name of specific atomic attack to include. If None, includes objectives from all atomic attacks. Defaults to None. Defaults to None.

Returns:

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:

get_strategies_used

get_strategies_used() → list[str]

Get the list of strategies used in this scenario.

Returns:

normalize_scenario_name

normalize_scenario_name(scenario_name: str) → str

Normalize 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().

ParameterTypeDescription
scenario_namestrThe scenario name to normalize.

Returns:

objective_achieved_rate

objective_achieved_rate(atomic_attack_name: Optional[str] = None) → int

Get the success rate of this scenario.

ParameterTypeDescription
atomic_attack_nameOptional[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: