On this page
Fluent registration and module scanning๏
Start with the Beginner rhythm: registration still ends
with one conjure. SpellBinder gives each registration a fluent sentence. A
sentence chooses the object, lifetime, permissions, category, and name, then
finalize() applies it to the book. The binder can be reused for another sentence.
The full-chain lesson registers an HTTP client under network / payments-api
and a policy with a separate instance per conduit. Its assertions check the
client's configured values and the root/child policy identity difference.
Bind options and constructor inputs๏
with_kwargs(...) supplies registration parameters. In the lesson it supplies
the disposal vocabulary. The client's base_url and timeout are supplied through
meld(override=...). Keeping these channels distinct prevents configuration from
being attached to a registration while the constructor still receives its defaults.
Register where the code lives๏
Use Declarative binding by module for scan_bind and
book.scan(...). Scanning and explicit binding can populate the same book before
conjure. The collection download preserves the local modules needed by the lessons.
The workflow in code๏
These are the core steps from the saved example. Use its complete linked script for all class definitions and setup.
1def main() -> None:
2 book = md.Spellbook()
3 binder = md.SpellBinder(book)
4
5 # one full sentence: frame + name + kwargs + lifecycle + permissions
6 binder.bind(HttpClient) \
7 .with_existence(md.Existence.unique) \
8 .with_permissions("create") \
9 .under_spellframe("network") \
10 .named("payments-api") \
11 .with_kwargs(disposal_method_names=["close"]) \
12 .finalize()
13
14 # binder resets after finalize - next sentence starts clean
15 binder.bind(RetryPolicy).as_unique_per_conduit().under_spellframe(
16 "network").finalize()
17
18 conduit = book.conjure()
19 client = conduit.meld(
20 spell=HttpClient, spellframe="network", binding_name="payments-api",
21 override={"base_url": "https://pay.example", "timeout": 30},
22 )
23 assert client.base_url == "https://pay.example" and client.timeout == 30
24 print("ctor config via override:", client.base_url)
25 # NOTE: with_kwargs passes BIND parameters (here: disposal list);
26 # Constructor arguments ride override= at meld time.
27
28 child = conduit.create_lesser_conduit()
29 policy_root = conduit.meld(spell=RetryPolicy, spellframe="network")
30 policy_child = child.meld(spell=RetryPolicy, spellframe="network")
31 assert policy_root is not policy_child
32 print("per-conduit policy under a spellframe: one per scope")
Runnable examples๏
Spellbinder full chain โ Intermediate 02
Spellbinder fluent basics โ Intermediate 10
Spell metadata kwargs โ Intermediate 06
Bind lambda spells โ Intermediate 12
Spell ids and lookup โ Intermediate 13
Introspect the book โ Intermediate 14
All intermediate examples ยท Level contents ยท Full contents