On this page

Frames as dict classification๏ƒ

๐ŸŸข Beginner ยท Lesson 25

Spellframes are CATEGORIES. Organize one world's spells by the resolution ideas your app already has - "repositories", "notifiers" - and (category, name) becomes the full address. The addressing FEELS like a two-level dict, but frames are NOT dicts: they are grouping and contract keys. A string frame groups; a Protocol frame also VALIDATES what binds under it (intermediate tier). Seed for later: when a category needs its own OWNER and its own resolution conditions, the category graduates into a whole CONDUIT - that story is intermediate lesson 26.

Before you run๏ƒ

Use the Beginner guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/01_beginner/25_frames_as_dict_classification.py
py -3.14t UX_and_AIX_experiences/01_beginner/25_frames_as_dict_classification.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

spellframe + binding_name as a category address space

Code๏ƒ

 1"""
 2TIER: beginner (25)
 3GOAL: Spellframes are CATEGORIES. Organize one world's spells by the
 4      resolution ideas your app already has - "repositories",
 5      "notifiers" - and (category, name) becomes the full address.
 6      The addressing FEELS like a two-level dict, but frames are NOT
 7      dicts: they are grouping and contract keys. A string frame
 8      groups; a Protocol frame also VALIDATES what binds under it
 9      (intermediate tier).
10      Seed for later: when a category needs its own OWNER and its own
11      resolution conditions, the category graduates into a whole
12      CONDUIT - that story is intermediate lesson 26.
13SURFACE EXERCISED: spellframe + binding_name as a category address space
14"""
15import melder as md
16
17
18class UsersRepo:
19    pass
20
21
22class OrdersRepo:
23    pass
24
25
26class SlackNotifier:
27    pass
28
29
30class EmailNotifier:
31    pass
32
33
34WORLD = {
35    "repositories": {"users": UsersRepo, "orders": OrdersRepo},
36    "notifiers": {"slack": SlackNotifier, "email": EmailNotifier},
37}
38
39
40def main() -> None:
41    book = md.Spellbook()
42    for frame, members in WORLD.items():
43        for name, cls in members.items():
44            book.bind(spell=cls, existence="unique",
45                      spellframe=frame, binding_name=name)
46    conduit = book.conjure()
47
48    # melding = looking up a category member by its full address
49    users = conduit.meld(spell=UsersRepo, spellframe="repositories",
50                         binding_name="users")
51    email = conduit.meld(spell=EmailNotifier, spellframe="notifiers",
52                         binding_name="email")
53    assert isinstance(users, UsersRepo) and isinstance(email, EmailNotifier)
54    print("categories addressed as [category][name]: repositories, notifiers")
55
56
57if __name__ == "__main__":
58    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More beginner examples ยท Level guide