betty.portable package

Submodules

Module contents

The portable data API.

Portable data can easily be persistent or transmitted across and between systems.

final class betty.portable.CallbackPorter

Bases: Porter, Generic

Make data portable using a separate loader and dumper.

__init__(loader: Callable[[PortableData], DataClsT], dumper: Callable[[DataClsT], PortableDataT], /)
dump(data: DataClsT) PortableDataT

Dump data to its portable form.

load(portable: PortableData) DataClsT

Load data from its portable form.

final class betty.portable.OptionalPorter

Bases: Porter[PortableT | None, PortableDataT | None], Generic

Add optional (None) support to another porter.

__init__(upstream: Porter[PortableT, PortableDataT])
dump(data: PortableT | None) PortableDataT | None

Dump data to its portable form.

load(portable: PortableData) PortableT | None

Load data from its portable form.

class betty.portable.Portable

Bases: ABC, Generic

A class that can be dumped to and loaded from portable data.

abstractmethod dump() PortableDataT

Dump the instance to portable data.

Raises:

betty.portable.error.NotPortable – Raised if any part of the data is not portable.

abstractmethod classmethod load(portable: PortableData, /) Self

Create a new instance from portable data.

Raises:

betty.exception.HumanFacingException – Raised if the portable data is invalid.

class betty.portable.PortablePorter

Bases: Porter, Generic

Expose a portable data type as a porter.

__init__(cls: type[PortableT])
dump(data: PortableT) PortableDataT

Dump data to its portable form.

load(portable: PortableData) PortableT

Load data from its portable form.

class betty.portable.Porter

Bases: ABC, Generic

An object capable of dumping and loading data to and from portable data.

copy(data: DataClsT) DataClsT

Deep-copy data into a new instance.

abstractmethod dump(data: DataClsT, /) PortableDataT

Dump data to its portable form.

abstractmethod load(portable: PortableData, /) DataClsT

Load data from its portable form.