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

# betty.model package

## Submodules

- betty.model.ancestry module
  - `Ancestry`
    - `Ancestry.__init__()`
    - `Ancestry.add_unchecked_graph()`
  - `Citation`
    - `Citation.__init__()`
    - `Citation.dump_linked_data()`
    - `Citation.facts`
    - `Citation.label`
    - `Citation.linked_data_schema()`
    - `Citation.plugin_id()`
    - `Citation.plugin_label()`
    - `Citation.plugin_label_plural()`
    - `Citation.source`
  - `Dated`
    - `Dated.__init__()`
    - `Dated.dump_linked_data()`
    - `Dated.linked_data_schema()`
  - `Described`
    - `Described.__init__()`
    - `Described.description`
    - `Described.dump_linked_data()`
    - `Described.linked_data_schema()`
  - `Enclosure`
    - `Enclosure.__init__()`
    - `Enclosure.enclosed_by`
    - `Enclosure.encloses`
    - `Enclosure.plugin_id()`
    - `Enclosure.plugin_label()`
    - `Enclosure.plugin_label_plural()`
  - `Event`
    - `Event.__init__()`
    - `Event.dump_linked_data()`
    - `Event.event_type`
    - `Event.label`
    - `Event.linked_data_schema()`
    - `Event.place`
    - `Event.plugin_id()`
    - `Event.plugin_label()`
    - `Event.plugin_label_plural()`
    - `Event.presences`
  - `File`
    - `File.__init__()`
    - `File.dump_linked_data()`
    - `File.label`
    - `File.linked_data_schema()`
    - `File.name`
    - `File.path`
    - `File.plugin_id()`
    - `File.plugin_label()`
    - `File.plugin_label_plural()`
    - `File.referees`
  - `FileReference`
    - `FileReference.__init__()`
    - `FileReference.file`
    - `FileReference.focus`
    - `FileReference.plugin_id()`
    - `FileReference.plugin_label()`
    - `FileReference.plugin_label_plural()`
    - `FileReference.referee`
  - `HasCitations`
    - `HasCitations.__init__()`
    - `HasCitations.citations`
    - `HasCitations.dump_linked_data()`
    - `HasCitations.linked_data_schema()`
  - `HasFileReferences`
    - `HasFileReferences.__init__()`
    - `HasFileReferences.file_references`
  - `HasLinks`
    - `HasLinks.__init__()`
    - `HasLinks.dump_linked_data()`
    - `HasLinks.linked_data_schema()`
    - `HasLinks.links`
  - `HasLinksEntity`
    - `HasLinksEntity.dump_linked_data()`
  - `HasMediaType`
    - `HasMediaType.__init__()`
    - `HasMediaType.dump_linked_data()`
    - `HasMediaType.linked_data_schema()`
  - `HasNotes`
    - `HasNotes.__init__()`
    - `HasNotes.dump_linked_data()`
    - `HasNotes.linked_data_schema()`
    - `HasNotes.notes`
  - `HasPrivacy`
    - `HasPrivacy.__init__()`
    - `HasPrivacy.dump_linked_data()`
    - `HasPrivacy.linked_data_schema()`
    - `HasPrivacy.own_privacy`
    - `HasPrivacy.privacy`
    - `HasPrivacy.private`
    - `HasPrivacy.public`
  - `Link`
    - `Link.__init__()`
    - `Link.dump_linked_data()`
    - `Link.label`
    - `Link.linked_data_schema()`
    - `Link.relationship`
    - `Link.url`
  - `Note`
    - `Note.__init__()`
    - `Note.dump_linked_data()`
    - `Note.entity`
    - `Note.label`
    - `Note.linked_data_schema()`
    - `Note.plugin_id()`
    - `Note.plugin_label()`
    - `Note.plugin_label_plural()`
    - `Note.text`
  - `Person`
    - `Person.__init__()`
    - `Person.ancestors`
    - `Person.children`
    - `Person.descendants`
    - `Person.dump_linked_data()`
    - `Person.label`
    - `Person.linked_data_schema()`
    - `Person.names`
    - `Person.parents`
    - `Person.plugin_id()`
    - `Person.plugin_label()`
    - `Person.plugin_label_plural()`
    - `Person.presences`
    - `Person.siblings`
  - `PersonName`
    - `PersonName.__init__()`
    - `PersonName.affiliation`
    - `PersonName.dump_linked_data()`
    - `PersonName.individual`
    - `PersonName.label`
    - `PersonName.linked_data_schema()`
    - `PersonName.person`
    - `PersonName.plugin_id()`
    - `PersonName.plugin_label()`
    - `PersonName.plugin_label_plural()`
  - `Place`
    - `Place.__init__()`
    - `Place.coordinates`
    - `Place.dump_linked_data()`
    - `Place.enclosed_by`
    - `Place.encloses`
    - `Place.events`
    - `Place.label`
    - `Place.linked_data_schema()`
    - `Place.names`
    - `Place.plugin_id()`
    - `Place.plugin_label()`
    - `Place.plugin_label_plural()`
    - `Place.walk_encloses`
  - `PlaceName`
    - `PlaceName.__init__()`
    - `PlaceName.dump_linked_data()`
    - `PlaceName.linked_data_schema()`
    - `PlaceName.name`
  - `Presence`
    - `Presence.__init__()`
    - `Presence.event`
    - `Presence.label`
    - `Presence.person`
    - `Presence.plugin_id()`
    - `Presence.plugin_label()`
    - `Presence.plugin_label_plural()`
    - `Presence.role`
  - `Privacy`
    - `Privacy.PRIVATE`
    - `Privacy.PUBLIC`
    - `Privacy.UNDETERMINED`
  - `Source`
    - `Source.__init__()`
    - `Source.citations`
    - `Source.contained_by`
    - `Source.contains`
    - `Source.dump_linked_data()`
    - `Source.label`
    - `Source.linked_data_schema()`
    - `Source.plugin_id()`
    - `Source.plugin_label()`
    - `Source.plugin_label_plural()`
    - `Source.walk_contains`
  - `is_private()`
  - `is_public()`
  - `merge_privacies()`
  - `ref_link()`
  - `ref_link_collection()`
  - `ref_media_type()`
  - `resolve_privacy()`
- betty.model.event_type module
  - `Adoption`
  - `Baptism`
  - `Birth`
    - `Birth.comes_before()`
  - `Burial`
  - `Conference`
  - `Confirmation`
  - `Correspondence`
  - `CreatableDerivableEventType`
    - `CreatableDerivableEventType.may_create()`
  - `Cremation`
  - `Death`
    - `Death.comes_after()`
    - `Death.may_create()`
  - `DerivableEventType`
  - `Divorce`
    - `Divorce.comes_after()`
  - `DivorceAnnouncement`
    - `DivorceAnnouncement.comes_after()`
    - `DivorceAnnouncement.comes_before()`
  - `DuringLifeEventType`
    - `DuringLifeEventType.comes_after()`
    - `DuringLifeEventType.comes_before()`
  - `EVENT_TYPE_REPOSITORY`
  - `Emigration`
  - `EndOfLifeEventType`
  - `Engagement`
    - `Engagement.comes_before()`
  - `EventType`
    - `EventType.comes_after()`
    - `EventType.comes_before()`
  - `FinalDispositionEventType`
  - `Funeral`
  - `Immigration`
  - `Marriage`
  - `MarriageAnnouncement`
    - `MarriageAnnouncement.comes_before()`
  - `Missing`
  - `Occupation`
  - `PostDeathEventType`
    - `PostDeathEventType.comes_after()`
  - `PreBirthEventType`
    - `PreBirthEventType.comes_before()`
  - `Residence`
  - `Retirement`
  - `StartOfLifeEventType`
  - `UnknownEventType`
  - `Will`
- betty.model.presence_role module
  - `Attendee`
    - `Attendee.plugin_id()`
    - `Attendee.plugin_label()`
  - `Beneficiary`
    - `Beneficiary.plugin_id()`
    - `Beneficiary.plugin_label()`
  - `Celebrant`
    - `Celebrant.plugin_id()`
    - `Celebrant.plugin_label()`
  - `Organizer`
    - `Organizer.plugin_id()`
    - `Organizer.plugin_label()`
  - `PRESENCE_ROLE_REPOSITORY`
  - `PresenceRole`
  - `Speaker`
    - `Speaker.plugin_id()`
    - `Speaker.plugin_label()`
  - `Subject`
    - `Subject.plugin_id()`
    - `Subject.plugin_label()`
  - `Witness`
    - `Witness.plugin_id()`
    - `Witness.plugin_label()`
  - `ref_role()`

## Module contents

Provide Betty’s data model API.

class betty.model.AliasedEntity

  Bases: `Generic`[`_EntityT`]

  An aliased entity wraps an entity and gives aliases its ID.

  Aliases are used when deserializing ancestries from sources where intermediate IDs are used to declare associations between entities. By wrapping an entity in an alias, the alias can use the intermediate ID, allowing it to be inserted into APIs such as `betty.model.EntityGraphBuilder` who will use the alias ID to finalize associations before the original entities are returned.

  __init__(original_entity: _EntityT, aliased_entity_id: str | None = None)
  property id: str

    The alias entity ID.

  property type: builtins.type[Entity]

    The type of the aliased entity.

  unalias() → _EntityT

    Get the original entity.

class betty.model.BidirectionalEntityTypeAssociation

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_EntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional entity type association.

  __init__(owner_type: type[_OwnerT], owner_attr_name: str, associate_type_name: str, associate_attr_name: str)
  property associate_attr_name: str

    The association’s attribute name on the associate type.

  inverse() → BidirectionalEntityTypeAssociation[_AssociateT, _OwnerT]

    Get the inverse association.

class betty.model.BidirectionalToManyEntityTypeAssociation

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `ToManyEntityTypeAssociation`[`_OwnerT`, `_AssociateT`], `BidirectionalEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional *-to-many entity type association.

  initialize(owner: _OwnerT & Entity) → None

class betty.model.BidirectionalToOneEntityTypeAssociation

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `ToOneEntityTypeAssociation`[`_OwnerT`, `_AssociateT`], `BidirectionalEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional *-to-one entity type association.

  set(owner: _OwnerT & Entity, associate: _AssociateT & Entity | None) → None

    Set the associate for the given owner.

betty.model.ENTITY_TYPE_REPOSITORY: PluginRepository[Entity] = <betty.plugin.entry_point.EntryPointPluginRepository object>

  The entity type plugin repository.

  Read more about Entity type plugins.

class betty.model.Entity

  Bases: `LinkedDataDumpable`, `Plugin`

  An entity is a uniquely identifiable data container.

  Read more about Entity type plugins.

  __init__(id: str | None = None, *args: Any, **kwargs: Any)
  property ancestry_id: tuple[builtins.type[Self], str]

    The ancestry ID.

    This MUST be unique per ancestry.

  async dump_linked_data(project: Project) → DumpMapping[Dump]

    Dump this instance to JSON-LD.

  property id: str

    The entity ID.

    This MUST be unique per entity type, per ancestry.

  property label: Localizable

    The entity’s human-readable label.

  async classmethod linked_data_schema(project: Project) → DumpMapping[Dump]

    Define the JSON Schema for `betty.json.linked_data.LinkedDataDumpable.dump_linked_data()`.

  abstract classmethod plugin_label_plural() → Localizable

    The human-readable entity type label, plural.

  property type: builtins.type[Self]

    The entity type.

class betty.model.EntityCollection

  Bases: `Generic`[`_TargetT`], `ABC`

  Provide a collection of entities.

  __init__()
  abstract add(*entities: _TargetT & Entity) → None

    Add the given entities.

  abstract clear() → None

    Clear all entities from the collection.

  abstract remove(*entities: _TargetT & Entity) → None

    Remove the given entities.

  replace(*entities: _TargetT & Entity) → None

    Replace all entities with the given ones.

  property view: list[_TargetT & Entity]

    A view of the entities at the time of calling.

class betty.model.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.

class betty.model.EntityTypeAssociationRegistry

  Bases: `object`

  Inspect any known entity type associations.

  classmethod finalize(*owners: Entity) → None

    Finalize all associations from the given owners.

  classmethod get_all_associations(owner: type | object) → set[ToOneEntityTypeAssociation[Any, Any] | ToManyEntityTypeAssociation[Any, Any]]

    Get all associations for an owner.

  classmethod get_associates(owner: _EntityT, association: ToOneEntityTypeAssociation[_EntityT, _AssociateT] | ToManyEntityTypeAssociation[_EntityT, _AssociateT]) → Iterable[_AssociateT]

    Get the associates for a given owner and association.

  classmethod get_association(owner: type[_OwnerT] | _OwnerT & Entity, owner_attr_name: str) → ToAny[_OwnerT, Any]

    Get the association for a given owner and attribute name.

  classmethod initialize(*owners: Entity) → None

    Initialize the given owners’ associations.

class betty.model.GeneratedEntityId

  Bases: `str`

  Generate a unique entity ID.

  Entities must have IDs for identification. However, not all entities can be provided with an ID that exists in the original data set (such as a third-party family tree loaded into Betty), so IDs can be generated.

  static __new__(cls, entity_id: str | None = None)

class betty.model.ManyToMany

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `BidirectionalToManyEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional many-to-many entity type association.

class betty.model.ManyToOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `BidirectionalToOneEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional many-to-one entity type association.

class betty.model.MultipleTypesEntityCollection

  Bases: `Generic`[`_TargetT`], `EntityCollection`[`_TargetT`]

  Collect entities of multiple types.

  __init__()
  add(*entities: _TargetT & Entity) → None

    Add the given entities.

  clear() → None

    Clear all entities from the collection.

  remove(*entities: _TargetT & Entity) → None

    Remove the given entities.

class betty.model.OneToMany

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `BidirectionalToManyEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional one-to-many entity type association.

class betty.model.OneToOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `BidirectionalToOneEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A bidirectional one-to-one entity type association.

class betty.model.SingleTypeEntityCollection

  Bases: `Generic`[`_TargetT`], `EntityCollection`[`_TargetT`]

  Collect entities of a single type.

  __init__(target_type: type[_TargetT])
  add(*entities: _TargetT & Entity) → None

    Add the given entities.

  clear() → None

    Clear all entities from the collection.

  remove(*entities: _TargetT & Entity) → None

    Remove the given entities.

class betty.model.ToMany

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `ToManyEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-many entity type association.

  initialize(owner: _OwnerT & Entity) → None

class betty.model.ToManyEntityTypeAssociation

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_EntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A to-many entity type association.

  associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None
  delete(owner: _OwnerT & Entity) → None
  disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None
  get(owner: _OwnerT & Entity) → EntityCollection[_AssociateT & Entity]

    Get the associates from the given owner.

  register() → None

    Register a virtual subclass of an ABC.

    Returns the subclass, to allow usage as a class decorator.

  set(owner: _OwnerT & Entity, entities: Iterable[_AssociateT & Entity]) → None

    Set the associates on the given owner.

class betty.model.ToOne

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `ToOneEntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-one entity type association.

class betty.model.ToOneEntityTypeAssociation

  Bases: `Generic`[`_OwnerT`, `_AssociateT`], `_EntityTypeAssociation`[`_OwnerT`, `_AssociateT`]

  A unidirectional to-one entity type association.

  associate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None
  delete(owner: _OwnerT & Entity) → None
  disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) → None
  get(owner: _OwnerT & Entity) → _AssociateT & Entity | None

    Get the associate from the given owner.

  initialize(owner: _OwnerT & Entity) → None
  register() → None

    Register a virtual subclass of an ABC.

    Returns the subclass, to allow usage as a class decorator.

  set(owner: _OwnerT & Entity, associate: _AssociateT & Entity | None) → None

    Set the associate for the given owner.

class betty.model.UserFacingEntity

  Bases: `object`

  A sentinel to mark an entity type as being visible to users (e.g. not internal).

betty.model.many_to_many(owner_attr_name: str, associate_type_name: str, associate_attr_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a bidirectional many-to-many association to an entity or entity mixin.

betty.model.many_to_one(owner_attr_name: str, associate_type_name: str, associate_attr_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a bidirectional many-to-one association to an entity or entity mixin.

betty.model.many_to_one_to_many(left_associate_type_name: str, left_associate_attr_name: str, left_owner_attr_name: str, right_owner_attr_name: str, right_associate_type_name: str, right_associate_attr_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a bidirectional many-to-one-to-many association to an entity or entity mixin.

betty.model.one_to_many(owner_attr_name: str, associate_type_name: str, associate_attr_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a bidirectional one-to-many association to an entity or entity mixin.

betty.model.one_to_one(owner_attr_name: str, associate_type_name: str, associate_attr_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a bidirectional one-to-one association to an entity or entity mixin.

betty.model.record_added(entities: EntityCollection[_EntityT]) → Iterator[MultipleTypesEntityCollection[_EntityT]]

  Record all entities that are added to a collection.

betty.model.to_many(owner_attr_name: str, associate_type_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a unidirectional to-many association to an entity or entity mixin.

betty.model.to_one(owner_attr_name: str, associate_type_name: str) → Callable[[type[_OwnerT]], type[_OwnerT]]

  Add a unidirectional to-one association to an entity or entity mixin.

betty.model.unalias(entity: _EntityT | AliasedEntity[_EntityT]) → _EntityT

  Unalias a potentially aliased entity.