pyrit.memory.MemoryExporter#
- class MemoryExporter[source]#
Bases:
object
Handles the export of data to various formats, currently supporting only JSON format. This class utilizes the strategy design pattern to select the appropriate export format.
Methods
__init__
()export_data
(data, *[, file_path, export_type])Exports the provided data to a file in the specified format.
export_to_csv
(data[, file_path])Exports the provided data to a CSV file at the specified file path.
export_to_json
(data[, file_path])Exports the provided data to a JSON file at the specified file path.
- export_data(data: list[PromptRequestPiece], *, file_path: Path = None, export_type: str = 'json')[source]#
Exports the provided data to a file in the specified format.
- Parameters:
data (list[PromptRequestPiece]) – The data to be exported, as a list of PromptRequestPiece instances.
file_path (str) – The full path, including the file name, where the data will be exported.
export_type (str, Optional) – The format for exporting data. Defaults to “json”.
- Raises:
ValueError – If no file_path is provided or if the specified export format is not supported.
- export_to_csv(data: list[PromptRequestPiece], file_path: Path = None) None [source]#
Exports the provided data to a CSV file at the specified file path. Each item in the data list, representing a row from the table, is converted to a dictionary before being written to the file.
- Parameters:
data (list[PromptRequestPiece]) – The data to be exported, as a list of PromptRequestPiece instances.
file_path (Path) – The full path, including the file name, where the data will be exported.
- Raises:
ValueError – If no file_path is provided.
- export_to_json(data: list[PromptRequestPiece], file_path: Path = None) None [source]#
Exports the provided data to a JSON file at the specified file path. Each item in the data list, representing a row from the table, is converted to a dictionary before being written to the file.
- Parameters:
data (list[PromptRequestPiece]) – The data to be exported, as a list of PromptRequestPiece instances.
file_path (Path) – The full path, including the file name, where the data will be exported.
- Raises:
ValueError – If no file_path is provided.