Skip to content

erdantic.examples.dataclasses

Example data model classes using standard library's dataclasses module.

Adventurer dataclass

A person often late for dinner but with a tale or two to tell.

Attributes:

Name Type Description
name str

Name of this adventurer

profession str

Profession of this adventurer

alignment Alignment

Alignment of this adventurer

level int

Level of this adventurer

Source code in erdantic/examples/dataclasses.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@dataclass
class Adventurer:
    """A person often late for dinner but with a tale or two to tell.

    Attributes:
        name (str): Name of this adventurer
        profession (str): Profession of this adventurer
        alignment (Alignment): Alignment of this adventurer
        level (int): Level of this adventurer
    """

    name: str
    profession: str
    alignment: Alignment
    level: int = 1

Party dataclass

A group of adventurers finding themselves doing and saying things altogether unexpected.

Attributes:

Name Type Description
name str

Name that party is known by

formed_datetime datetime

Timestamp of when the party was formed

members List[Adventurer]

Adventurers that belong to this party

active_quest Optional[Quest]

Current quest that party is actively tackling

Source code in erdantic/examples/dataclasses.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@dataclass
class Party:
    """A group of adventurers finding themselves doing and saying things altogether unexpected.

    Attributes:
        name (str): Name that party is known by
        formed_datetime (datetime): Timestamp of when the party was formed
        members (List[Adventurer]): Adventurers that belong to this party
        active_quest (Optional[Quest]): Current quest that party is actively tackling
    """

    name: str
    formed_datetime: datetime
    members: List[Adventurer] = field(default_factory=list)
    active_quest: Optional[Quest] = None

Quest dataclass

A task to complete, with some monetary reward.

Attributes:

Name Type Description
name str

Name by which this quest is referred to

giver QuestGiver

Person who offered the quest

reward_gold int

Amount of gold to be rewarded for quest completion

Source code in erdantic/examples/dataclasses.py
54
55
56
57
58
59
60
61
62
63
64
65
66
@dataclass
class Quest:
    """A task to complete, with some monetary reward.

    Attributes:
        name (str): Name by which this quest is referred to
        giver (QuestGiver): Person who offered the quest
        reward_gold (int): Amount of gold to be rewarded for quest completion
    """

    name: str
    giver: QuestGiver
    reward_gold: int = 100

QuestGiver dataclass

A person who offers a task that needs completing.

Attributes:

Name Type Description
name str

Name of this quest giver

faction str

Faction that this quest giver belongs to

location str

Location this quest giver can be found

Source code in erdantic/examples/dataclasses.py
39
40
41
42
43
44
45
46
47
48
49
50
51
@dataclass
class QuestGiver:
    """A person who offers a task that needs completing.

    Attributes:
        name (str): Name of this quest giver
        faction (str): Faction that this quest giver belongs to
        location (str): Location this quest giver can be found
    """

    name: str
    faction: Optional[str] = None
    location: str = "Adventurer's Guild"