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.association module
  - `Association`
    - `Association.__init__()`
    - `Association.associate()`
    - `Association.associate_type`
    - `Association.disassociate()`
    - `Association.owner_attr_name`
    - `Association.owner_type`
  - `AssociationRegistry`
    - `AssociationRegistry.get_all_associations()`
    - `AssociationRegistry.get_associates()`
    - `AssociationRegistry.get_association()`
  - `ManyToMany`
  - `ManyToOne`
  - `OneToMany`
  - `OneToOne`
  - `ToMany`
    - `ToMany.new_attr()`
  - `ToManyAssociation`
    - `ToManyAssociation.associate()`
    - `ToManyAssociation.del_attr()`
    - `ToManyAssociation.disassociate()`
    - `ToManyAssociation.set_attr()`
  - `ToOne`
  - `ToOneAssociation`
    - `ToOneAssociation.associate()`
    - `ToOneAssociation.del_attr()`
    - `ToOneAssociation.disassociate()`
    - `ToOneAssociation.new_attr()`
    - `ToOneAssociation.set_attr()`
- betty.model.collections module
  - `EntityCollection`
    - `EntityCollection.__init__()`
    - `EntityCollection.add()`
    - `EntityCollection.clear()`
    - `EntityCollection.remove()`
    - `EntityCollection.replace()`
    - `EntityCollection.view`
  - `MultipleTypesEntityCollection`
    - `MultipleTypesEntityCollection.__init__()`
    - `MultipleTypesEntityCollection.add()`
    - `MultipleTypesEntityCollection.clear()`
    - `MultipleTypesEntityCollection.remove()`
  - `SingleTypeEntityCollection`
    - `SingleTypeEntityCollection.__init__()`
    - `SingleTypeEntityCollection.add()`
    - `SingleTypeEntityCollection.clear()`
    - `SingleTypeEntityCollection.remove()`
  - `record_added()`
- betty.model.graph module
  - `EntityGraphBuilder`
    - `EntityGraphBuilder.add_association()`
    - `EntityGraphBuilder.add_entity()`

## 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.graph.EntityGraphBuilder` which 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.

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`[`Object`], `Plugin`

  An entity is a uniquely identifiable data container.

  Read more about Entity type plugins.

  To test your own subclasses, use `betty.test_utils.model.EntityTestBase`.

  __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) → Object

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

  Bases: `Array`

  A schema for a collection of references to other entity resources.

  __init__(entity_type: type[Entity], *, title: str | None = None)

class betty.model.EntityReferenceSchema

  Bases: `String`

  A schema for a reference to another entity resource.

  __init__(entity_type: type[Entity], *, title: str | None = None)

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

  Bases: `object`

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

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

  Unalias a potentially aliased entity.