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.api_client

Async REST client for the PyRIT backend API.

Uses httpx internally but defers the import to method calls so that importing this module does not trigger the import-guard ban on httpx at CLI parse time.

PyRITApiClient

Lightweight async REST client for the PyRIT backend.

No heavy pyrit imports.

Use as an async context manager::

async with PyRITApiClient(base_url="http://localhost:8000") as client:
    scenarios = await client.list_scenarios_async()

Constructor Parameters:

ParameterTypeDescription
base_urlstrBase URL of the PyRIT backend (e.g., "http://localhost:8000").

Methods:

cancel_scenario_run_async

cancel_scenario_run_async(scenario_result_id: str) → dict[str, Any]

Cancel a running scenario.

Returns:

close_async

close_async() → None

Close the underlying HTTP client.

get_scenario_async

get_scenario_async(scenario_name: str) → dict[str, Any] | None

Get metadata for a single scenario.

Returns:

Raises:

get_scenario_run_async

get_scenario_run_async(scenario_result_id: str) → dict[str, Any]

Get the current status of a scenario run.

Returns:

get_scenario_run_results_async

get_scenario_run_results_async(scenario_result_id: str) → dict[str, Any]

Get detailed results for a completed scenario run.

Returns:

health_check_async

health_check_async() → bool

Probe the server health endpoint.

Returns:

list_initializers_async

list_initializers_async(limit: int = 200) → dict[str, Any]

List all available initializers.

Returns:

list_scenario_runs_async

list_scenario_runs_async(limit: int = 100) → dict[str, Any]

List tracked scenario runs.

Returns:

list_scenarios_async

list_scenarios_async(limit: int = 200) → dict[str, Any]

List all available scenarios.

Returns:

list_targets_async

list_targets_async(limit: int = 200) → dict[str, Any]

List all available targets.

Returns:

register_initializer_async

register_initializer_async(name: str, script_content: str) → dict[str, Any]

Register a custom initializer by uploading Python source code.

ParameterTypeDescription
namestrRegistry name for the initializer.
script_contentstrPython source code containing a PyRITInitializer subclass.

Returns:

Raises:

start_scenario_run_async

start_scenario_run_async(request: dict[str, Any]) → dict[str, Any]

Start a new scenario run.

ParameterTypeDescription
requestdict[str, Any]RunScenarioRequest-shaped dict.

Returns:

ServerNotAvailableError

Bases: Exception

Raised when the CLI cannot reach the PyRIT backend server.