Skip to content

yggdrasil.pickle.ser.serde

serde

Serialisation / deserialisation entry points for the yggdrasil wire format.

Public API

serialize — wrap any Python object in a :class:~yggdrasil.pickle.ser.serialized.Serialized dump — write a serialised object to a file-like object or path dumps — serialise to bytes (or base-64 str) load — read and optionally unpickle from a file-like object or path loads — read and optionally unpickle from bytes or a base-64 str

serialize

serialize(
    obj: Any,
    *,
    metadata: Mapping[bytes, bytes] | None = None,
    codec: int | None = None
) -> Serialized

Wrap obj in a :class:Serialized instance without writing to a buffer.

dump

dump(
    obj: Any,
    fp: IO[bytes] | Path | str,
    *,
    metadata: Mapping[bytes, bytes] | None = None,
    codec: int | None = None
) -> None

Serialise obj and write it to fp (file-like, :class:~pathlib.Path, or str path).

dumps

dumps(
    obj: Any,
    *,
    metadata: Mapping[bytes, bytes] | None = None,
    codec: int | None = None,
    b64: bool = False
) -> bytes | str

Serialise obj to bytes, or to a URL-safe base-64 str when b64 is True.

load

load(
    fp: IO[bytes] | Path | str,
    *,
    unpickle: bool = True,
    clean_corrupted: bool = False,
    default: Any = None
) -> Any

Read a serialised payload from fp and optionally unpickle it.

loads

loads(s: bytes | str, *, unpickle: bool = True) -> Any

Deserialise from s (bytes or URL-safe base-64 str).