betty.model package¶
Submodules¶
- betty.model.ancestry module
Ancestry
Citation
Dated
Described
Enclosure
Event
File
HasCitations
HasFiles
HasLinks
HasLinksEntity
HasMediaType
HasNotes
HasPrivacy
Link
Note
Person
PersonName
Place
PlaceName
Presence
Privacy
Source
is_private()
is_public()
merge_privacies()
ref_link()
ref_link_collection()
ref_media_type()
resolve_privacy()
- betty.model.event_type module
Adoption
Baptism
Birth
Burial
Conference
Confirmation
Correspondence
CreatableDerivableEventType
Cremation
Death
DerivableEventType
Divorce
DivorceAnnouncement
DuringLifeEventType
ENTITY_TYPE_REPOSITORY
Emigration
EndOfLifeEventType
Engagement
EventType
FinalDispositionEventType
Funeral
Immigration
Marriage
MarriageAnnouncement
Missing
Occupation
PostDeathEventType
PreBirthEventType
Residence
Retirement
StartOfLifeEventType
UnknownEventType
Will
- betty.model.presence_role module
Module contents¶
Provide Betty’s data model API.
- class betty.model.AliasedEntity[source]¶
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
))
- __init__(original_entity: betty.model._EntityT, aliased_entity_id: str | None = None)[source]¶
- Parameters:
original_entity (
typing.TypeVar
(_EntityT
, bound=betty.model.Entity
))
- unalias() betty.model._EntityT [source]¶
Get the original entity.
- Return type:
typing.TypeVar
(_EntityT
, bound=betty.model.Entity
)
- class betty.model.BidirectionalEntityTypeAssociation[source]¶
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)[source]¶
- Parameters:
owner_type (
type
[typing.TypeVar
(_OwnerT
)])owner_attr_name (
str
)associate_type_name (
str
)associate_attr_name (
str
)
- inverse() betty.model.BidirectionalEntityTypeAssociation[betty.model._AssociateT, betty.model._OwnerT] [source]¶
Get the inverse association.
- Return type:
betty.model.BidirectionalEntityTypeAssociation
[typing.TypeVar
(_AssociateT
),typing.TypeVar
(_OwnerT
)]
- class betty.model.BidirectionalToManyEntityTypeAssociation[source]¶
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
)
- class betty.model.BidirectionalToOneEntityTypeAssociation[source]¶
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
)
- betty.model.ENTITY_TYPE_REPOSITORY: PluginRepository[Entity] = <betty.plugin.entry_point.EntryPointPluginRepository object>¶
The entity type plugin repository.
- class betty.model.Entity[source]¶
Bases:
LinkedDataDumpable
,Plugin
An entity is a uniquely identifiable data container.
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- __init__(id: str | None = None, *args: Any, **kwargs: Any)[source]¶
- Parameters:
args (
typing.Any
)kwargs (
typing.Any
)
- async dump_linked_data(project: betty.project.Project) 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]]] [source]¶
Dump this instance to JSON-LD.
- Parameters:
project (
betty.project.Project
)- 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 label: Localizable¶
The entity’s human-readable label.
- async classmethod linked_data_schema(project: betty.project.Project) 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]]] [source]¶
Define the JSON Schema for
betty.json.linked_data.LinkedDataDumpable.dump_linked_data()
.- Parameters:
project (
betty.project.Project
)- 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]]]]]
- abstract classmethod plugin_label_plural() betty.locale.localizable.Localizable [source]¶
The human-readable entity type label, plural.
- Return type:
- class betty.model.EntityCollection[source]¶
-
Provide a collection of entities.
- abstract add(*entities: _TargetT & Entity) None [source]¶
Add the given entities.
- Parameters:
entities (_TargetT & Entity)
- Return type:
None
- abstract remove(*entities: _TargetT & Entity) None [source]¶
Remove the given entities.
- Parameters:
entities (_TargetT & Entity)
- Return type:
None
- replace(*entities: _TargetT & Entity) None [source]¶
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[source]¶
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 [source]¶
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:
- add_entity(*entities: betty.model.Entity | betty.model.AliasedEntity[betty.model.Entity]) None [source]¶
Add entities to the graph.
- Parameters:
entities (
typing.Union
[betty.model.Entity
,betty.model.AliasedEntity
[betty.model.Entity
]])- Return type:
- class betty.model.EntityTypeAssociationRegistry[source]¶
Bases:
object
Inspect any known entity type associations.
- classmethod finalize(*owners: betty.model.Entity) None [source]¶
Finalize all associations from the given owners.
- Parameters:
owners (
betty.model.Entity
)- Return type:
- classmethod get_all_associations(owner: type | object) set[betty.model.ToOneEntityTypeAssociation[Any, Any] | betty.model.ToManyEntityTypeAssociation[Any, Any]] [source]¶
Get all associations for an owner.
- Parameters:
- 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] [source]¶
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] [source]¶
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 [source]¶
Initialize the given owners’ associations.
- Parameters:
owners (
betty.model.Entity
)- Return type:
- class betty.model.GeneratedEntityId[source]¶
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.
- class betty.model.ManyToMany[source]¶
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[source]¶
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[source]¶
Bases:
Generic
[_TargetT
],EntityCollection
[_TargetT
]Collect entities of multiple types.
- class betty.model.OneToMany[source]¶
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[source]¶
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[source]¶
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])[source]¶
- Parameters:
target_type (
type
[typing.TypeVar
(_TargetT
)])
- class betty.model.ToMany[source]¶
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
)
- class betty.model.ToManyEntityTypeAssociation[source]¶
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 [source]¶
- Parameters:
owner (_OwnerT & Entity)
associate (_AssociateT & Entity)
- Return type:
None
- delete(owner: _OwnerT & Entity) None [source]¶
- Parameters:
owner (_OwnerT & Entity)
- Return type:
None
- disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None [source]¶
- Parameters:
owner (_OwnerT & Entity)
associate (_AssociateT & Entity)
- Return type:
None
- get(owner: _OwnerT & Entity) EntityCollection[_AssociateT & Entity] [source]¶
Get the associates from the given owner.
- Parameters:
owner (_OwnerT & Entity)
- Return type:
EntityCollection[_AssociateT & Entity]
- class betty.model.ToOne[source]¶
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[source]¶
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 [source]¶
- Parameters:
owner (_OwnerT & Entity)
associate (_AssociateT & Entity)
- Return type:
None
- delete(owner: _OwnerT & Entity) None [source]¶
- Parameters:
owner (_OwnerT & Entity)
- Return type:
None
- disassociate(owner: _OwnerT & Entity, associate: _AssociateT & Entity) None [source]¶
- Parameters:
owner (_OwnerT & Entity)
associate (_AssociateT & Entity)
- Return type:
None
- get(owner: _OwnerT & Entity) _AssociateT & Entity | None [source]¶
Get the associate from the given owner.
- Parameters:
owner (_OwnerT & Entity)
- Return type:
_AssociateT & Entity | None
- initialize(owner: _OwnerT & Entity) None [source]¶
- Parameters:
owner (_OwnerT & Entity)
- Return type:
None
- class betty.model.UserFacingEntity[source]¶
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[betty.model._OwnerT]], type[betty.model._OwnerT]] [source]¶
Add a bidirectional many-to-many association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
Add a bidirectional many-to-one association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
Add a bidirectional many-to-one-to-many association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
Add a bidirectional one-to-many association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
Add a bidirectional one-to-one association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
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]] [source]¶
Add a unidirectional to-many association to an entity or entity mixin.
- Parameters:
- 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]] [source]¶
Add a unidirectional to-one association to an entity or entity mixin.
- Parameters:
- 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 [source]¶
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
)