betty.model.graph 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.model.graph module

Entity graph management.

Entities and their associations represent a graph where entities are nodes and associations are vertices. This module provides utilities to (de)construct these graphs from and to entity collections, such as ancestries.

class betty.model.graph.EntityGraphBuilder

  Bases: `_EntityGraphBuilder`

  Assemble entities and their associations.

  (De)serializing data often means that special care must be taken with the associations, relationships, or links between data points, as those form a graph, a network, a tangled web of data. When deserializing entity A with an association to entity B, that association cannot be finalized until entity B is parsed as well. But, if entity B subsequently has an association with entity A (the association is bidirectional), this results in an endless cycle.

  This class prevents the problem by letting you add entities and associations separately. Associations are finalized when you are done adding, avoiding cycle errors.

  add_association(owner_type: type[Entity], owner_id: str, owner_attr_name: str, associate_type: type[Entity], associate_id: str) → None

    Add an association between two entities to the graph.

  add_entity(*entities: Entity | AliasedEntity[Entity]) → None

    Add entities to the graph.