pyrit.models.DataTypeSerializer#

class DataTypeSerializer[source]#

Bases: ABC

Abstract base class for data type normalizers.

Responsible for reading and saving multi-modal data types to local disk or Azure Storage Account.

__init__()#

Methods

__init__()

data_on_disk()

Returns True if the data is stored on disk.

get_data_filename()

Generates or retrieves a unique filename for the data file.

get_extension(file_path)

Get the file extension from the file path.

get_mime_type(file_path)

Get the MIME type of the file path.

get_sha256()

read_data()

Reads the data from the storage.

read_data_base64()

Reads the data from the storage.

save_b64_image(data[, output_filename])

Saves the base64 encoded image to storage.

save_data(data)

Saves the data to storage.

Attributes

abstract data_on_disk() bool[source]#

Returns True if the data is stored on disk.

data_sub_directory: str#
data_type: Literal['text', 'image_path', 'audio_path', 'url', 'error']#
file_extension: str#
async get_data_filename() Path | str[source]#

Generates or retrieves a unique filename for the data file.

static get_extension(file_path: str) str | None[source]#

Get the file extension from the file path.

static get_mime_type(file_path: str) str | None[source]#

Get the MIME type of the file path.

async get_sha256() str[source]#
async read_data() bytes[source]#

Reads the data from the storage.

Returns:

The data read from storage.

Return type:

bytes

async read_data_base64() str[source]#

Reads the data from the storage.

async save_b64_image(data: str, output_filename: str = None) None[source]#

Saves the base64 encoded image to storage. :param data: string with base64 data :param output_filename: filename to store image as. Defaults to UUID if not provided :type output_filename: optional, str

async save_data(data: bytes) None[source]#

Saves the data to storage.

value: str#