Omnist logo Omnist Tutorial Step 12 of 15

Custom formats

Register your own format plugin — usable everywhere Doc reads and writes by name.

Formats are plugins. Registering one makes it usable everywhere a Doc reads or writes a format by name, the same way JSON or YAML are:

from omnist import Format, register_format, Doc

register_format(Format(
    name="lines",
    read=lambda text: [("n", int(x)) for x in text.split()],
    write=lambda node, **opts: " ".join(str(v) for _, v in node),
))
Doc.from_format("lines", "1 2 3").to_format("lines")
Output
'1 2 3'

Learn more