betty.model package

Submodules

Module contents

Provide Betty’s data model API.

class betty.model.AliasedEntity(original_entity, aliased_entity_id=None)[source]

Bases: Generic[EntityT]

Parameters:
original_entity

aliased_entity_id=None

property id : str
property type : type[Entity]
unalias()[source]
Return type:

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

class betty.model.BidirectionalEntityTypeAssociation(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

property associate_attr_name : str
inverse()[source]
Return type:

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

class betty.model.BidirectionalToManyEntityTypeAssociation(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

initialize(owner)[source]
Parameters:
owner

Return type:

None

class betty.model.BidirectionalToOneEntityTypeAssociation(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

set(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

class betty.model.Entity(id=None, *args, **kwargs)[source]

Bases: LinkedDataDumpable

Parameters:
id=None

*args

**kwargs

property ancestry_id : tuple[type[Self], str]
async dump_linked_data(app)[source]

Dump this instance to JSON-LD.

Parameters:
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()[source]
Return type:

betty.locale.Str

classmethod entity_type_label_plural()[source]
Return type:

betty.locale.Str

property id : str
property label : Str
async classmethod linked_data_schema(app)[source]

Define the JSON Schema for self.dump_linked_data().

Parameters:
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]
class betty.model.EntityCollection[source]

Bases: Generic[TargetT]

add(*entities)[source]
Parameters:
*entities

Return type:

None

clear()[source]
Return type:

None

remove(*entities)[source]
Parameters:
*entities

Return type:

None

replace(*entities)[source]
Parameters:
*entities

Return type:

None

property view : list[TargetT & Entity]
class betty.model.EntityGraphBuilder[source]

Bases: _EntityGraphBuilder

add_association(owner_type, owner_id, owner_attr_name, associate_type, associate_id)[source]
Parameters:
owner_type

owner_id

owner_attr_name

associate_type

associate_id

Return type:

None

add_entity(*entities)[source]
Parameters:
*entities

Return type:

None

class betty.model.EntityTypeAssociationRegistry[source]

Bases: object

classmethod finalize(*owners)[source]
Parameters:
*owners

Return type:

None

classmethod get_all_associations(owner)[source]
Parameters:
owner

Return type:

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

classmethod get_associates(owner, association)[source]
Parameters:
owner

association

Return type:

typing.Iterable[typing.TypeVar(AssociateT)]

classmethod get_association(owner, owner_attr_name)[source]
Parameters:
owner

owner_attr_name

Return type:

ToAny[OwnerT, Any]

classmethod initialize(*owners)[source]
Parameters:
*owners

Return type:

None

exception betty.model.EntityTypeError[source]

Bases: ValueError

exception betty.model.EntityTypeImportError(entity_type_name)[source]

Bases: EntityTypeError, ImportError

Raised when an alleged entity type cannot be imported.

Parameters:
entity_type_name

exception betty.model.EntityTypeInvalidError(entity_type)[source]

Bases: EntityTypeError, ImportError

Raised for types that are not valid entity types.

Parameters:
entity_type

class betty.model.EntityTypeProvider[source]

Bases: object

async entity_types()[source]
Return type:

set[type[betty.model.Entity]]

class betty.model.GeneratedEntityId(entity_id: str | None = None)[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(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

class betty.model.ManyToOne(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

class betty.model.MultipleTypesEntityCollection[source]

Bases: Generic[TargetT], EntityCollection[TargetT]

add(*entities)[source]
Parameters:
*entities

Return type:

None

clear()[source]
Return type:

None

remove(*entities)[source]
Parameters:
*entities

Return type:

None

class betty.model.OneToMany(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

class betty.model.OneToOne(owner_type, owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate_attr_name

class betty.model.SingleTypeEntityCollection(target_type)[source]

Bases: Generic[TargetT], EntityCollection[TargetT]

Parameters:
target_type

add(*entities)[source]
Parameters:
*entities

Return type:

None

clear()[source]
Return type:

None

remove(*entities)[source]
Parameters:
*entities

Return type:

None

class betty.model.ToMany(owner_type, owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

initialize(owner)[source]
Parameters:
owner

Return type:

None

class betty.model.ToManyEntityTypeAssociation(owner_type, owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

delete(owner)[source]
Parameters:
owner

Return type:

None

disassociate(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

get(owner)[source]
Parameters:
owner

Return type:

EntityCollection[AssociateT & Entity]

register()[source]
Return type:

None

set(owner, entities)[source]
Parameters:
owner

entities

Return type:

None

class betty.model.ToOne(owner_type, owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

class betty.model.ToOneEntityTypeAssociation(owner_type, owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_type

owner_attr_name

associate_type_name

associate(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

delete(owner)[source]
Parameters:
owner

Return type:

None

disassociate(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

get(owner)[source]
Parameters:
owner

Return type:

AssociateT & Entity | None

initialize(owner)[source]
Parameters:
owner

Return type:

None

register()[source]
Return type:

None

set(owner, associate)[source]
Parameters:
owner

associate

Return type:

None

class betty.model.UserFacingEntity[source]

Bases: object

betty.model.get_entity_type(entity_type_name)[source]

Get the entity type for an entity type name.

Parameters:
entity_type_name

Return type:

type[betty.model.Entity]

betty.model.get_entity_type_name(entity_type_definition)[source]

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

Parameters:
entity_type_definition

Return type:

str

betty.model.many_to_many(owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

associate_attr_name

Return type:

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

betty.model.many_to_one(owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

associate_attr_name

Return type:

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

betty.model.many_to_one_to_many(left_associate_type_name, left_associate_attr_name, left_owner_attr_name, right_owner_attr_name, right_associate_type_name, right_associate_attr_name)[source]

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

Parameters:
left_associate_type_name

left_associate_attr_name

left_owner_attr_name

right_owner_attr_name

right_associate_type_name

right_associate_attr_name

Return type:

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

betty.model.one_to_many(owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

associate_attr_name

Return type:

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

betty.model.one_to_one(owner_attr_name, associate_type_name, associate_attr_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

associate_attr_name

Return type:

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

betty.model.record_added(entities)[source]

Record all entities that are added to a collection.

Parameters:
entities

Return type:

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

betty.model.to_many(owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

Return type:

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

betty.model.to_one(owner_attr_name, associate_type_name)[source]

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

Parameters:
owner_attr_name

associate_type_name

Return type:

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

betty.model.unalias(entity)[source]

Unalias a potentially aliased entity.

Parameters:
entity

Return type:

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