betty.serde.format package - 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 package

## Submodules

- betty.serde.format.formats module
  - `Json`
    - `Json.dump()`
    - `Json.extensions()`
    - `Json.load()`
  - `Yaml`
    - `Yaml.dump()`
    - `Yaml.extensions()`
    - `Yaml.load()`

## Module contents

Provide serialization formats.

betty.serde.format.FORMAT_REPOSITORY = <betty.serde.format.FormatRepository object>

  The (de)serialization format plugin repository.

  Read more about Serialization format plugins.

class betty.serde.format.Format

  Bases: `Plugin`

  Defines a (de)serialization format.

  abstractmethod dump(dump: Voidable[Dump]) → str

    Serialize data.

  abstractmethod classmethod extensions() → set[str]

    The file extensions this format can (de)serialize.

  abstractmethod load(dump: str) → Dump

    Deserialize data.

    Raises:

      FormatError – Raised when the dump could not be loaded.

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: `PluginRepository`[`Format`]

  Exposes the available (de)serialization formats.

  __init__()
  async extensions() → set[str]

    All file extensions supported by the formats in this repository.

  async get(plugin_id: MachineName) → type[Format]

    Get a single plugin by its ID.

    Raises:

      PluginNotFound – if no plugin can be found for the given ID.

final class betty.serde.format.FormatStr

  Bases: `Localizable`

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

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

    Localize `self` to a human-readable string.

betty.serde.format.format_for(available_formats: Sequence[type[Format]], extension: str) → type[Format]

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