Skip to content
v0.1.3

Serializer Module API Reference

This section documents the internals of the serializer module in Bijux CLI.

bijux_cli.contracts.serializer

Defines the contract for the object serialization service.

This module specifies the SerializerProtocol, a formal interface that any service responsible for serializing objects to strings or bytes (e.g., in JSON or YAML format) and deserializing them back must implement.

SerializerProtocol

Bases: Protocol[T]

Defines the contract for stateless, thread-safe object serialization.

This interface specifies methods for serializing and deserializing objects to and from strings or bytes in various formats, such as JSON or YAML.

dumps

dumps(
    obj: T,
    *,
    fmt: OutputFormat = JSON,
    pretty: bool = False,
) -> str

Serializes an object to a string.

Parameters:

  • obj (T) –

    The object to serialize.

  • fmt (OutputFormat, default: JSON ) –

    The output format. Defaults to OutputFormat.JSON.

  • pretty (bool, default: False ) –

    If True, formats the output for human readability.

Returns:

  • str ( str ) –

    The serialized object as a string.

Source code in src/bijux_cli/contracts/serializer.py
def dumps(
    self,
    obj: T,
    *,
    fmt: OutputFormat = OutputFormat.JSON,
    pretty: bool = False,
) -> str:
    """Serializes an object to a string.

    Args:
        obj (T): The object to serialize.
        fmt (OutputFormat): The output format. Defaults to `OutputFormat.JSON`.
        pretty (bool): If True, formats the output for human readability.

    Returns:
        str: The serialized object as a string.
    """
    ...

dumps_bytes

dumps_bytes(
    obj: T,
    *,
    fmt: OutputFormat = JSON,
    pretty: bool = False,
) -> bytes

Serializes an object to bytes.

Parameters:

  • obj (T) –

    The object to serialize.

  • fmt (OutputFormat, default: JSON ) –

    The output format. Defaults to OutputFormat.JSON.

  • pretty (bool, default: False ) –

    If True, formats the output for human readability.

Returns:

  • bytes ( bytes ) –

    The serialized object as bytes.

Source code in src/bijux_cli/contracts/serializer.py
def dumps_bytes(
    self,
    obj: T,
    *,
    fmt: OutputFormat = OutputFormat.JSON,
    pretty: bool = False,
) -> bytes:
    """Serializes an object to bytes.

    Args:
        obj (T): The object to serialize.
        fmt (OutputFormat): The output format. Defaults to `OutputFormat.JSON`.
        pretty (bool): If True, formats the output for human readability.

    Returns:
        bytes: The serialized object as bytes.
    """
    ...

emit

emit(
    payload: T,
    *,
    fmt: OutputFormat = JSON,
    pretty: bool = False,
) -> None

Serializes and emits a payload to standard output.

Parameters:

  • payload (T) –

    The object to serialize and emit.

  • fmt (OutputFormat, default: JSON ) –

    The output format.

  • pretty (bool, default: False ) –

    If True, formats the output for human readability.

Returns:

  • None ( None ) –
Source code in src/bijux_cli/contracts/serializer.py
def emit(
    self, payload: T, *, fmt: OutputFormat = OutputFormat.JSON, pretty: bool = False
) -> None:
    """Serializes and emits a payload to standard output.

    Args:
        payload (T): The object to serialize and emit.
        fmt (OutputFormat): The output format.
        pretty (bool): If True, formats the output for human readability.

    Returns:
        None:
    """
    ...

loads

loads(
    data: str | bytes,
    *,
    fmt: OutputFormat = JSON,
    pretty: bool = False,
) -> T

Deserializes data from a string or bytes into an object.

Parameters:

  • data (str | bytes) –

    The string or bytes to deserialize.

  • fmt (OutputFormat, default: JSON ) –

    The format of the input data. Defaults to OutputFormat.JSON.

  • pretty (bool, default: False ) –

    A hint that may affect parsing, though often unused during deserialization.

Returns:

  • T ( T ) –

    The deserialized object.

Source code in src/bijux_cli/contracts/serializer.py
def loads(
    self,
    data: str | bytes,
    *,
    fmt: OutputFormat = OutputFormat.JSON,
    pretty: bool = False,
) -> T:
    """Deserializes data from a string or bytes into an object.

    Args:
        data (str | bytes): The string or bytes to deserialize.
        fmt (OutputFormat): The format of the input data. Defaults to
            `OutputFormat.JSON`.
        pretty (bool): A hint that may affect parsing, though often unused
            during deserialization.

    Returns:
        T: The deserialized object.
    """
    ...