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

## Submodules

- betty.model.ancestry module
  - `Ancestry`
    - `Ancestry.__init__()`
    - `Ancestry.add_unchecked_graph()`
  - `AnonymousCitation`
    - `AnonymousCitation.__new__()`
    - `AnonymousCitation.location`
  - `AnonymousSource`
    - `AnonymousSource.__new__()`
    - `AnonymousSource.name`
  - `Attendee`
    - `Attendee.label`
    - `Attendee.name()`
  - `Beneficiary`
    - `Beneficiary.label`
    - `Beneficiary.name()`
  - `Celebrant`
    - `Celebrant.label`
    - `Celebrant.name()`
  - `Citation`
    - `Citation.__init__()`
    - `Citation.dump_linked_data()`
    - `Citation.entity_type_label()`
    - `Citation.entity_type_label_plural()`
    - `Citation.facts`
    - `Citation.label`
    - `Citation.linked_data_schema()`
    - `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.entity_type_label()`
    - `Enclosure.entity_type_label_plural()`
  - `Event`
    - `Event.__init__()`
    - `Event.associated_files`
    - `Event.dump_linked_data()`
    - `Event.entity_type_label()`
    - `Event.entity_type_label_plural()`
    - `Event.event_type`
    - `Event.label`
    - `Event.linked_data_schema()`
    - `Event.place`
    - `Event.presences`
  - `File`
    - `File.__init__()`
    - `File.dump_linked_data()`
    - `File.entities`
    - `File.entity_type_label()`
    - `File.entity_type_label_plural()`
    - `File.label`
    - `File.linked_data_schema()`
    - `File.name`
    - `File.path`
  - `HasCitations`
    - `HasCitations.__init__()`
    - `HasCitations.citations`
    - `HasCitations.dump_linked_data()`
    - `HasCitations.linked_data_schema()`
  - `HasFiles`
    - `HasFiles.__init__()`
    - `HasFiles.associated_files`
    - `HasFiles.files`
  - `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.entity_type_label()`
    - `Note.entity_type_label_plural()`
    - `Note.label`
    - `Note.linked_data_schema()`
    - `Note.text`
  - `Organizer`
    - `Organizer.label`
    - `Organizer.name()`
  - `Person`
    - `Person.__init__()`
    - `Person.ancestors`
    - `Person.associated_files`
    - `Person.children`
    - `Person.descendants`
    - `Person.dump_linked_data()`
    - `Person.entity_type_label()`
    - `Person.entity_type_label_plural()`
    - `Person.label`
    - `Person.linked_data_schema()`
    - `Person.names`
    - `Person.parents`
    - `Person.presences`
    - `Person.siblings`
  - `PersonName`
    - `PersonName.__init__()`
    - `PersonName.affiliation`
    - `PersonName.dump_linked_data()`
    - `PersonName.entity_type_label()`
    - `PersonName.entity_type_label_plural()`
    - `PersonName.individual`
    - `PersonName.label`
    - `PersonName.linked_data_schema()`
    - `PersonName.person`
  - `Place`
    - `Place.__init__()`
    - `Place.associated_files`
    - `Place.coordinates`
    - `Place.dump_linked_data()`
    - `Place.enclosed_by`
    - `Place.encloses`
    - `Place.entity_type_label()`
    - `Place.entity_type_label_plural()`
    - `Place.events`
    - `Place.label`
    - `Place.linked_data_schema()`
    - `Place.names`
    - `Place.walk_encloses`
  - `PlaceName`
    - `PlaceName.__init__()`
    - `PlaceName.dump_linked_data()`
    - `PlaceName.linked_data_schema()`
    - `PlaceName.name`
  - `Presence`
    - `Presence.__init__()`
    - `Presence.entity_type_label()`
    - `Presence.entity_type_label_plural()`
    - `Presence.event`
    - `Presence.label`
    - `Presence.person`
    - `Presence.role`
  - `PresenceRole`
    - `PresenceRole.label`
    - `PresenceRole.name()`
  - `Privacy`
    - `Privacy.PRIVATE`
    - `Privacy.PUBLIC`
    - `Privacy.UNDETERMINED`
  - `Source`
    - `Source.__init__()`
    - `Source.citations`
    - `Source.contained_by`
    - `Source.contains`
    - `Source.dump_linked_data()`
    - `Source.entity_type_label()`
    - `Source.entity_type_label_plural()`
    - `Source.label`
    - `Source.linked_data_schema()`
    - `Source.walk_contains`
  - `Speaker`
    - `Speaker.label`
    - `Speaker.name()`
  - `Subject`
    - `Subject.label`
    - `Subject.name()`
  - `Witness`
    - `Witness.label`
    - `Witness.name()`
  - `is_private()`
  - `is_public()`
  - `merge_privacies()`
  - `ref_link()`
  - `ref_link_collection()`
  - `ref_media_type()`
  - `ref_role()`
  - `resolve_privacy()`
- betty.model.event_type module
  - `Adoption`
    - `Adoption.label()`
    - `Adoption.name()`
  - `Baptism`
    - `Baptism.label()`
    - `Baptism.name()`
  - `Birth`
    - `Birth.comes_before()`
    - `Birth.label()`
    - `Birth.name()`
  - `Burial`
    - `Burial.label()`
    - `Burial.name()`
  - `Conference`
    - `Conference.label()`
    - `Conference.name()`
  - `Confirmation`
    - `Confirmation.label()`
    - `Confirmation.name()`
  - `Correspondence`
    - `Correspondence.label()`
    - `Correspondence.name()`
  - `CreatableDerivableEventType`
    - `CreatableDerivableEventType.may_create()`
  - `Cremation`
    - `Cremation.label()`
    - `Cremation.name()`
  - `Death`
    - `Death.comes_after()`
    - `Death.label()`
    - `Death.may_create()`
    - `Death.name()`
  - `DerivableEventType`
  - `Divorce`
    - `Divorce.comes_after()`
    - `Divorce.label()`
    - `Divorce.name()`
  - `DivorceAnnouncement`
    - `DivorceAnnouncement.comes_after()`
    - `DivorceAnnouncement.comes_before()`
    - `DivorceAnnouncement.label()`
    - `DivorceAnnouncement.name()`
  - `DuringLifeEventType`
    - `DuringLifeEventType.comes_after()`
    - `DuringLifeEventType.comes_before()`
  - `Emigration`
    - `Emigration.label()`
    - `Emigration.name()`
  - `EndOfLifeEventType`
  - `Engagement`
    - `Engagement.comes_before()`
    - `Engagement.label()`
    - `Engagement.name()`
  - `EventType`
    - `EventType.__new__()`
    - `EventType.comes_after()`
    - `EventType.comes_before()`
    - `EventType.label()`
    - `EventType.name()`
  - `EventTypeProvider`
    - `EventTypeProvider.entity_types`
  - `FinalDispositionEventType`
  - `Funeral`
    - `Funeral.label()`
    - `Funeral.name()`
  - `Immigration`
    - `Immigration.label()`
    - `Immigration.name()`
  - `Marriage`
    - `Marriage.label()`
    - `Marriage.name()`
  - `MarriageAnnouncement`
    - `MarriageAnnouncement.comes_before()`
    - `MarriageAnnouncement.label()`
    - `MarriageAnnouncement.name()`
  - `Missing`
    - `Missing.label()`
    - `Missing.name()`
  - `Occupation`
    - `Occupation.label()`
    - `Occupation.name()`
  - `PostDeathEventType`
    - `PostDeathEventType.comes_after()`
  - `PreBirthEventType`
    - `PreBirthEventType.comes_before()`
  - `Residence`
    - `Residence.label()`
    - `Residence.name()`
  - `Retirement`
    - `Retirement.label()`
    - `Retirement.name()`
  - `StartOfLifeEventType`
  - `UnknownEventType`
    - `UnknownEventType.label()`
    - `UnknownEventType.name()`
  - `Will`
    - `Will.label()`
    - `Will.name()`

## 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.

  Parameters:

    - original_entity (`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`))

    - aliased_entity_id (`str` | `None`)

  __init__(original_entity: betty.model.EntityT, aliased_entity_id: str | None = None)
    Parameters:

      - original_entity (`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`))

      - aliased_entity_id (`str` | `None`)

  property id: str

    The alias entity ID.

  property type: type[Entity]

    The type of the aliased entity.

  unalias() → betty.model.EntityT

    Get the original entity.

    Return type:

      `typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`)

class betty.model.BidirectionalEntityTypeAssociation

  Bases: `Generic`[`OwnerT`, `AssociateT`], `_EntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  __init__(owner_type: type[betty.model.OwnerT], owner_attr_name: str, associate_type_name: str, associate_attr_name: str)
    Parameters:

      - owner_type (`type`[`typing.TypeVar`(`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() → betty.model.BidirectionalEntityTypeAssociation[betty.model.AssociateT, betty.model.OwnerT]

    Get the inverse association.

    Return type:

      `betty.model.BidirectionalEntityTypeAssociation`[`typing.TypeVar`(`AssociateT`), `typing.TypeVar`(`OwnerT`)]

class betty.model.BidirectionalToManyEntityTypeAssociation

  Bases: `Generic`[`OwnerT`, `AssociateT`], `ToManyEntityTypeAssociation`[`OwnerT`, `AssociateT`], `BidirectionalEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional *-to-many entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  initialize(owner: OwnerT & Entity) → None
    Parameters:

      owner (OwnerT & Entity)

    Return type:

      None

class betty.model.BidirectionalToOneEntityTypeAssociation

  Bases: `Generic`[`OwnerT`, `AssociateT`], `ToOneEntityTypeAssociation`[`OwnerT`, `AssociateT`], `BidirectionalEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional *-to-one entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  set(owner: OwnerT & Entity, associate: AssociateT & Entity | None) → None

    Set the associate for the given owner.

    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity | None)

    Return type:

      None

class betty.model.Entity

  Bases: `LinkedDataDumpable`

  An entity is a uniquely identifiable data container.

  Parameters:

    - id (`str` | `None`)

    - args (`typing.Any`)

    - kwargs (`typing.Any`)

  __init__(id: str | None = None, *args: Any, **kwargs: Any)
    Parameters:

      - id (`str` | `None`)

      - args (`typing.Any`)

      - kwargs (`typing.Any`)

  property ancestry_id: tuple[type[Self], str]

    The ancestry ID.

    This MUST be unique per ancestry.

  async dump_linked_data(app: betty.app.App) → dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]]

    Dump this instance to JSON-LD.

    Parameters:

      app (`betty.app.App`)

    Return type:

      `dict`[`str`, `typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[`typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[Dump], `typing.Mapping`[`str`, Dump]]], `typing.Mapping`[`str`, `typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[Dump], `typing.Mapping`[`str`, Dump]]]]]

  classmethod entity_type_label() → betty.locale.Str

    The human-readable entity type label, singular.

    Return type:

      `betty.locale.Str`

  classmethod entity_type_label_plural() → betty.locale.Str

    The human-readable entity type label, plural.

    Return type:

      `betty.locale.Str`

  property id: str

    The entity ID.

    This MUST be unique per entity type, per ancestry.

  property label: Str

    The entity’s human-readable label.

  async classmethod linked_data_schema(app: betty.app.App) → dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]]

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

    Parameters:

      app (`betty.app.App`)

    Return type:

      `dict`[`str`, `typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[`typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[Dump], `typing.Mapping`[`str`, Dump]]], `typing.Mapping`[`str`, `typing.Union`[`bool`, `int`, `float`, `str`, `None`, `typing.Sequence`[Dump], `typing.Mapping`[`str`, Dump]]]]]

  property type: type[Self]

    The entity type.

class betty.model.EntityCollection

  Bases: `Generic`[`TargetT`]

  Provide a collection of entities.

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

    Add the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

  clear() → None

    Clear all entities from the collection.

    Return type:

      `None`

  remove(*entities: TargetT & Entity) → None

    Remove the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

  replace(*entities: TargetT & Entity) → None

    Replace all entities with the given ones.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

  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[betty.model.Entity], owner_id: str, owner_attr_name: str, associate_type: type[betty.model.Entity], associate_id: str) → None

    Add an association between two entities to the graph.

    Parameters:

      - owner_type (`type`[`betty.model.Entity`])

      - owner_id (`str`)

      - owner_attr_name (`str`)

      - associate_type (`type`[`betty.model.Entity`])

      - associate_id (`str`)

    Return type:

      `None`

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

    Add entities to the graph.

    Parameters:

      entities (`typing.Union`[`betty.model.Entity`, `betty.model.AliasedEntity`[`betty.model.Entity`]])

    Return type:

      `None`

class betty.model.EntityTypeAssociationRegistry

  Bases: `object`

  Inspect any known entity type associations.

  classmethod finalize(*owners: betty.model.Entity) → None

    Finalize all associations from the given owners.

    Parameters:

      owners (`betty.model.Entity`)

    Return type:

      `None`

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

    Get all associations for an owner.

    Parameters:

      owner (`type` | `object`)

    Return type:

      `set`[`typing.Union`[`betty.model.ToOneEntityTypeAssociation`[`typing.Any`, `typing.Any`], `betty.model.ToManyEntityTypeAssociation`[`typing.Any`, `typing.Any`]]]

  classmethod get_associates(owner: betty.model.EntityT, association: betty.model.ToOneEntityTypeAssociation[betty.model.EntityT, betty.model.AssociateT] | betty.model.ToManyEntityTypeAssociation[betty.model.EntityT, betty.model.AssociateT]) → Iterable[betty.model.AssociateT]

    Get the associates for a given owner and association.

    Parameters:

      - owner (`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`))

      - association (`typing.Union`[`betty.model.ToOneEntityTypeAssociation`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`), `typing.TypeVar`(`AssociateT`)], `betty.model.ToManyEntityTypeAssociation`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`), `typing.TypeVar`(`AssociateT`)]])

    Return type:

      `typing.Iterable`[`typing.TypeVar`(`AssociateT`)]

  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.

    Parameters:

      - owner (type[OwnerT] | OwnerT & Entity)

      - owner_attr_name (str)

    Return type:

      ToAny[OwnerT, Any]

  classmethod initialize(*owners: betty.model.Entity) → None

    Initialize the given owners’ associations.

    Parameters:

      owners (`betty.model.Entity`)

    Return type:

      `None`

exception betty.model.EntityTypeError

  Bases: `ValueError`

  A error occurred when trying to determine and import an entity type.

exception betty.model.EntityTypeImportError

  Bases: `EntityTypeError`, `ImportError`

  Raised when an alleged entity type cannot be imported.

  Parameters:

    entity_type_name (`str`)

  __init__(entity_type_name: str)
    Parameters:

      entity_type_name (`str`)

exception betty.model.EntityTypeInvalidError

  Bases: `EntityTypeError`, `ImportError`

  Raised for types that are not valid entity types.

  Parameters:

    entity_type (`type`)

  __init__(entity_type: type)
    Parameters:

      entity_type (`type`)

class betty.model.EntityTypeProvider

  Bases: `object`

  Provide additional entity types.

  async entity_types() → set[type[betty.model.Entity]]

    The entity types.

    Return type:

      `set`[`type`[`betty.model.Entity`]]

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)
    Parameters:

      entity_id (`str` | `None`)

class betty.model.ManyToMany

  Bases: `Generic`[`OwnerT`, `AssociateT`], `BidirectionalToManyEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional many-to-many entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

class betty.model.ManyToOne

  Bases: `Generic`[`OwnerT`, `AssociateT`], `BidirectionalToOneEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional many-to-one entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

class betty.model.MultipleTypesEntityCollection

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

  Collect entities of multiple types.

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

    Add the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

  clear() → None

    Clear all entities from the collection.

    Return type:

      `None`

  remove(*entities: TargetT & Entity) → None

    Remove the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

class betty.model.OneToMany

  Bases: `Generic`[`OwnerT`, `AssociateT`], `BidirectionalToManyEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional one-to-many entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

class betty.model.OneToOne

  Bases: `Generic`[`OwnerT`, `AssociateT`], `BidirectionalToOneEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A bidirectional one-to-one entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

class betty.model.SingleTypeEntityCollection

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

  Collect entities of a single type.

  Parameters:

    target_type (`type`[`typing.TypeVar`(`TargetT`)])

  __init__(target_type: type[betty.model.TargetT])
    Parameters:

      target_type (`type`[`typing.TypeVar`(`TargetT`)])

  add(*entities: TargetT & Entity) → None

    Add the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

  clear() → None

    Clear all entities from the collection.

    Return type:

      `None`

  remove(*entities: TargetT & Entity) → None

    Remove the given entities.

    Parameters:

      entities (TargetT & Entity)

    Return type:

      None

class betty.model.ToMany

  Bases: `Generic`[`OwnerT`, `AssociateT`], `ToManyEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A unidirectional to-many entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

  initialize(owner: OwnerT & Entity) → None
    Parameters:

      owner (OwnerT & Entity)

    Return type:

      None

class betty.model.ToManyEntityTypeAssociation

  Bases: `Generic`[`OwnerT`, `AssociateT`], `_EntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A to-many entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

  associate(owner: OwnerT & Entity, associate: AssociateT & Entity) → None
    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity)

    Return type:

      None

  delete(owner: OwnerT & Entity) → None
    Parameters:

      owner (OwnerT & Entity)

    Return type:

      None

  disassociate(owner: OwnerT & Entity, associate: AssociateT & Entity) → None
    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity)

    Return type:

      None

  get(owner: OwnerT & Entity) → EntityCollection[AssociateT & Entity]

    Get the associates from the given owner.

    Parameters:

      owner (OwnerT & Entity)

    Return type:

      EntityCollection[AssociateT & Entity]

  register() → None
    Return type:

      `None`

  set(owner: OwnerT & Entity, entities: Iterable[AssociateT & Entity]) → None

    Set the associates on the given owner.

    Parameters:

      - owner (OwnerT & Entity)

      - entities (Iterable[AssociateT & Entity])

    Return type:

      None

class betty.model.ToOne

  Bases: `Generic`[`OwnerT`, `AssociateT`], `ToOneEntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A unidirectional to-one entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

class betty.model.ToOneEntityTypeAssociation

  Bases: `Generic`[`OwnerT`, `AssociateT`], `_EntityTypeAssociation`[`OwnerT`, `AssociateT`]

  A unidirectional to-one entity type association.

  Parameters:

    - owner_type (`type`[`typing.TypeVar`(`OwnerT`)])

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

  associate(owner: OwnerT & Entity, associate: AssociateT & Entity) → None
    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity)

    Return type:

      None

  delete(owner: OwnerT & Entity) → None
    Parameters:

      owner (OwnerT & Entity)

    Return type:

      None

  disassociate(owner: OwnerT & Entity, associate: AssociateT & Entity) → None
    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity)

    Return type:

      None

  get(owner: OwnerT & Entity) → AssociateT & Entity | None

    Get the associate from the given owner.

    Parameters:

      owner (OwnerT & Entity)

    Return type:

      AssociateT & Entity | None

  initialize(owner: OwnerT & Entity) → None
    Parameters:

      owner (OwnerT & Entity)

    Return type:

      None

  register() → None
    Return type:

      `None`

  set(owner: OwnerT & Entity, associate: AssociateT & Entity | None) → None

    Set the associate for the given owner.

    Parameters:

      - owner (OwnerT & Entity)

      - associate (AssociateT & Entity | None)

    Return type:

      None

class betty.model.UserFacingEntity

  Bases: `object`

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

betty.model.get_entity_type(entity_type_name: str) → type[betty.model.Entity]

  Get the entity type for an entity type name.

  Parameters:

    entity_type_name (`str`)

  Return type:

    `type`[`betty.model.Entity`]

betty.model.get_entity_type_name(entity_type_definition: type[betty.model.Entity] | betty.model.Entity) → str

  Get the entity type name for an entity or entity type.

  Parameters:

    entity_type_definition (`type`[`betty.model.Entity`] | `betty.model.Entity`)

  Return type:

    `str`

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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[betty.model.OwnerT]], type[betty.model.OwnerT]]

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

  Parameters:

    - 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`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

    - associate_attr_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

  Record all entities that are added to a collection.

  Parameters:

    entities (`betty.model.EntityCollection`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`)])

  Return type:

    `typing.Iterator`[`betty.model.MultipleTypesEntityCollection`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`)]]

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

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

  Parameters:

    - owner_attr_name (`str`)

    - associate_type_name (`str`)

  Return type:

    `typing.Callable`[[`type`[`typing.TypeVar`(`OwnerT`)]], `type`[`typing.TypeVar`(`OwnerT`)]]

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

  Unalias a potentially aliased entity.

  Parameters:

    entity (`typing.Union`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`), `betty.model.AliasedEntity`[`typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`)]])

  Return type:

    `typing.TypeVar`(`EntityT`, bound= `betty.model.Entity`)