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.executor.core

Core executor module.

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:

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:

Strategy

Bases: ABC, Generic[StrategyContextT, StrategyResultT]

Abstract base class for strategies with enforced lifecycle management.

Ensures a consistent execution flow: validate -> setup -> execute -> teardown. The teardown phase is guaranteed to run even if exceptions occur.

Subclasses must implement: _validate_context(): Validate context _setup_async(): Initialize resources _perform_async(): Execute the logic _teardown_async(): Clean up resources

Constructor Parameters:

ParameterTypeDescription
context_typetype[StrategyContextT]The type of context this strategy will use.
event_handler`StrategyEventHandler[StrategyContextT, StrategyResultT]None`
loggerlogging.LoggerThe logger to use for this strategy. Defaults to logger.

Methods:

execute_async

execute_async(kwargs: Any = {}) → StrategyResultT

Execute the strategy asynchronously with the given keyword arguments.

Returns:

execute_with_context_async

execute_with_context_async(context: StrategyContextT) → StrategyResultT

Execute strategy with complete lifecycle management.

Enforces: validate -> setup -> execute -> teardown.

ParameterTypeDescription
contextStrategyContextTThe context for the strategy, containing configuration and state.

Returns:

Raises:

StrategyContext

Bases: ABC

Base class for all strategy contexts.

Methods:

duplicate

duplicate() → StrategyContextT

Create a deep copy of the context.

Returns:

StrategyConverterConfig

Configuration for converters used in strategies.

This class defines the converter configurations that transform prompts during the strategy process, both for requests and responses.

Examples:

StrategyEvent

Bases: Enum

Enumeration of all strategy lifecycle events.

StrategyEventData

Bases: Generic[StrategyContextT, StrategyResultT]

Data passed to event observers.

StrategyEventHandler

Bases: ABC, Generic[StrategyContextT, StrategyResultT]

Abstract base class for strategy event handlers.

Methods:

on_event_async

on_event_async(event_data: StrategyEventData[StrategyContextT, StrategyResultT]) → None

Handle a strategy event.

ParameterTypeDescription
event_dataStrategyEventData[StrategyContextT, StrategyResultT]Data about the event that occurred.