betty.serde.format module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.serde.format module

Provide serialization formats.

class betty.serde.format.Format

  Bases: `ABC`

  Defines a (de)serialization format.

  abstract dump(dump: bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | type[Void]) → str

    Serialize data.

  abstract property extensions: set[str]

    The file extensions this format can (de)serialize.

    Extensions MUST NOT include a leading dot.

  abstract property label: Localizable

    The format’s human-readable label.

  abstract load(dump: str) → bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]

    Deserialize data.

exception betty.serde.format.FormatError

  Bases: `AssertionFailed`

  Raised when data that is being deserialized is provided in an unknown (undeserializable) format.

final class betty.serde.format.FormatRepository

  Bases: `object`

  Exposes the available (de)serialization formats.

  __init__()
  property extensions: tuple[str, ...]

    All file extensions supported by the formats in this repository.

  format_for(extension: str) → Format

    Get the (de)serialization format for the given file extension.

    The extension MUST NOT include a leading dot.

  property formats: tuple[Format, ...]

    All formats in this repository.

final class betty.serde.format.FormatStr

  Bases: `Localizable`

  Localize and format a sequence of (de)serialization formats.

  __init__(serde_formats: Sequence[Format])
  localize(localizer: Localizer) → LocalizedStr

    Localize `self` to a human-readable string.

final class betty.serde.format.Json

  Bases: `Format`

  Defines the JSON (de)serialization format.

  dump(dump: bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | type[Void]) → str

    Serialize data.

  property extensions: set[str]

    The file extensions this format can (de)serialize.

    Extensions MUST NOT include a leading dot.

  property label: Localizable

    The format’s human-readable label.

  load(dump: str) → bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]

    Deserialize data.

final class betty.serde.format.Yaml

  Bases: `Format`

  Defines the YAML (de)serialization format.

  dump(dump: bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | type[Void]) → str

    Serialize data.

  property extensions: set[str]

    The file extensions this format can (de)serialize.

    Extensions MUST NOT include a leading dot.

  property label: Localizable

    The format’s human-readable label.

  load(dump: str) → bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]

    Deserialize data.