Skip to content

mambo_power.io.native

The native JSON format: the serialised Network itself. See File formats › Native JSON.

mambo_power.io.native

Native JSON format: the serialised Network itself.

loads(dumps(net)) == net for every valid network. Fields that are None are omitted on write and default back to None on read, so files stay short and round-trip exactly.

dumps

dumps(net: Network) -> str

Serialise to indented JSON without null fields.

Source code in src/mambo_power/io/native.py
def dumps(net: Network) -> str:
    """Serialise to indented JSON without null fields."""
    return net.model_dump_json(indent=2, exclude_none=True)

loads

loads(text: str | bytes) -> Network

Parse JSON text into a validated Network.

Source code in src/mambo_power/io/native.py
def loads(text: str | bytes) -> Network:
    """Parse JSON text into a validated :class:`Network`."""
    return Network.model_validate_json(text)

save

save(net: Network, path: str | PathLike[str]) -> None

Write dumps output to path as UTF-8 with a trailing newline.

Source code in src/mambo_power/io/native.py
def save(net: Network, path: str | PathLike[str]) -> None:
    """Write :func:`dumps` output to ``path`` as UTF-8 with a trailing newline."""
    Path(path).write_text(dumps(net) + "\n", encoding="utf-8", newline="\n")

load

load(path: str | PathLike[str]) -> Network

Read a native JSON file into a validated Network.

Source code in src/mambo_power/io/native.py
def load(path: str | PathLike[str]) -> Network:
    """Read a native JSON file into a validated :class:`Network`."""
    return loads(Path(path).read_text(encoding="utf-8"))