ds_resource_plugin_py_lib.common.serde.binary

File: binary.py Region: ds_resource_plugin_py_lib/common/serde

Description

Helpers for serializing and deserializing binary payloads via DataFrames.

Attributes

_BINARY_KWARGS

_DEFAULT_COLUMN

_DEFAULT_ROW

Functions

binary_kwargs(→ dict[str, Any])

Return kwargs with binary-specific keys removed.

deserialize_binary(→ pandas.DataFrame)

Wrap raw binary input in a single-row DataFrame.

serialize_binary(→ bytes)

Extract binary payload from a DataFrame row and column.

Module Contents

ds_resource_plugin_py_lib.common.serde.binary._BINARY_KWARGS
ds_resource_plugin_py_lib.common.serde.binary._DEFAULT_COLUMN = 'binary'
ds_resource_plugin_py_lib.common.serde.binary._DEFAULT_ROW = 0
ds_resource_plugin_py_lib.common.serde.binary.binary_kwargs(kwargs: dict[str, Any]) dict[str, Any][source]

Return kwargs with binary-specific keys removed.

ds_resource_plugin_py_lib.common.serde.binary.deserialize_binary(value: Any, *, column: str = _DEFAULT_COLUMN, encoding: str | None = None) pandas.DataFrame[source]

Wrap raw binary input in a single-row DataFrame.

Parameters:
  • value – Binary payload as bytes, bytearray, BytesIO, or str.

  • column – Column name for the binary value.

  • encoding – When set, encode str input with this encoding.

Returns:

A one-row DataFrame containing the binary payload.

Raises:

DeserializationError – If the input is not binary.

ds_resource_plugin_py_lib.common.serde.binary.serialize_binary(obj: pandas.DataFrame, *, column: str = _DEFAULT_COLUMN, row: int = _DEFAULT_ROW, encoding: str | None = None) bytes[source]

Extract binary payload from a DataFrame row and column.

Parameters:
  • obj – Source DataFrame.

  • column – Column containing the binary value.

  • row – Row index to read from.

  • encoding – When set, encode str cell values with this encoding.

Returns:

The binary payload as bytes.

Raises:

SerializationError – If the column, row, or cell value is invalid.