langchain.document_loaders.blob_loaders.schema.Blob¶

class langchain.document_loaders.blob_loaders.schema.Blob(*, data: Optional[Union[bytes, str]] = None, mimetype: Optional[str] = None, encoding: str = 'utf-8', path: Optional[Union[str, PurePath]] = None)[source]¶

Bases: BaseModel

A blob is used to represent raw data by either reference or value.

Provides an interface to materialize the blob in different representations, and help to decouple the development of data loaders from the downstream parsing of the raw data.

Inspired by: https://developer.mozilla.org/en-US/docs/Web/API/Blob

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param data: Optional[Union[bytes, str]] = None¶
param encoding: str = 'utf-8'¶
param mimetype: Optional[str] = None¶
param path: Optional[Union[str, pathlib.PurePath]] = None¶
as_bytes() bytes[source]¶

Read data as bytes.

as_bytes_io() Generator[Union[BytesIO, BufferedReader], None, None][source]¶

Read data as a byte stream.

as_string() str[source]¶

Read data as a string.

validator check_blob_is_valid  »  all fields[source]¶

Verify that either data or path is provided.

classmethod from_data(data: Union[str, bytes], *, encoding: str = 'utf-8', mime_type: Optional[str] = None, path: Optional[str] = None) Blob[source]¶

Initialize the blob from in-memory data.

Parameters
  • data – the in-memory data associated with the blob

  • encoding – Encoding to use if decoding the bytes into a string

  • mime_type – if provided, will be set as the mime-type of the data

  • path – if provided, will be set as the source from which the data came

Returns

Blob instance

classmethod from_path(path: Union[str, PurePath], *, encoding: str = 'utf-8', mime_type: Optional[str] = None, guess_type: bool = True) Blob[source]¶

Load the blob from a path like object.

Parameters
  • path – path like object to file to be read

  • encoding – Encoding to use if decoding the bytes into a string

  • mime_type – if provided, will be set as the mime-type of the data

  • guess_type – If True, the mimetype will be guessed from the file extension, if a mime-type was not provided

Returns

Blob instance

property source: Optional[str]¶

The source location of the blob as string if known otherwise none.

model Config[source]¶

Bases: object

arbitrary_types_allowed = True¶
frozen = True¶

Examples using Blob¶