API reference¶
The Python surface of spaday. The component classes themselves (WaButton, Stack, LightweightChart,
…) are generated and not listed here — see Author a component tree and
Generate typed classes.
Action DSL¶
Behavior attached to a component with Component.on; see Add behavior and reactivity.
Actions¶
- class spaday.SetProp(target: Ref, prop: str, value: Any)[source]¶
Bases:
ActionSet
propontargettovalue(anExpror a plain literal).
- class spaday.Toggle(target: Ref, prop: str)[source]¶
Bases:
ActionFlip a boolean
propontarget(e.g.hidden,checked,open).
- class spaday.Emit(event: str, detail: Any = None)[source]¶
Bases:
ActionDispatch a (bubbling) custom DOM event named
eventwith an optionaldetailexpression.
- class spaday.SendPatch(model: str, field: str, value: Any)[source]¶
Bases:
ActionSet
fieldtovalueon a host-routedmodel(e.g. a transports model).The runtime surfaces this as a patch intent (a bubbling
spaday:patchDOM event carrying{model, field, value}); the app routes it to the actual wire. This is how a control edit is authored declaratively instead of with a hand-written transports listener.
- class spaday.If(cond: Any, then: Action, els: Action | None = None)[source]¶
Bases:
ActionRun
thenifcondis truthy, elseels(if given) — branch on live state, e.g.If(prop(by_id("sw"), "checked"), SetProp(...), SetProp(...)).
Expressions and references¶
- spaday.event_value() Expr[source]¶
The triggering event’s value — a control’s
checked(booleans) elsevalueelsedetail.
- spaday.prop(target: Ref, name: str) Expr[source]¶
The current value of a
nameprop ontarget— reads live element state, e.g.prop(by_id("sw"), "checked")for use as a condition.
- spaday.field(name: str) Expr[source]¶
The current value of a reactive state field — for a computed binding (
Component.compute), evaluated against the signal store in the browser, e.g.not_(field("enabled")).
Binding helper¶
spaday.bind is a one-way event-driven convenience (control change → set a target prop). For reactive
state bindings prefer Component.bind / Component.compute (above).
- spaday.bind(source: Any, target: Ref, target_prop: str, *, transform: Any = None) Any[source]¶
One-way reactive binding: when
source(a control component) changes, settarget_propontarget(aRef, e.g.by_id("panel")) to the source’s value — optionally passed throughtransform(e.g.not_()). Returnssourceso it composes in a tree:bind(WaSwitch().text("Show"), by_id("panel"), "hidden", transform=not_)
Event-driven (sugar over
SetPropon the source’schange); the signal-graph reactive engine and two-way binding are future work.
Validation¶
- spaday.validate(tree: Component | dict) None[source]¶
Raise
ValidationErrorif anyby_id(...)reference in the tree’s actions is unresolved.Pass a
Component(or its serialized node dict). ReturnsNoneon success.
- exception spaday.ValidationError[source]¶
Bases:
ValueErrorRaised by
validate()when a component tree has unresolved references.
CEM binding generator¶
- spaday.parse_cem(manifest)¶
Parse a custom-elements.json manifest into the JSON-encoded list of component schemas.
- spaday.generate(manifest_path: str, out_path: str | None = None, *, source: str | None = None) str[source]¶
Render a manifest’s components into a Python module; write it to
out_pathif given.
- spaday.classes(manifest_path: str) Dict[str, Type[Component]][source]¶
- spaday.classes(manifest_path: str, name: str) Type[Component]
Build
Componentsubclasses from a manifest at runtime.The dynamic counterpart to
generate(): build classes without emitting a file. Withname, returns just that one class (MyClass = spaday.classes(manifest, "MyClass")); otherwise returns{class_name: class}for the whole manifest. Handy for binding an arbitrary or one-off manifest on the fly. Unlike the committed, generated catalog (e.g.spaday.components.webawesome), these classes are not statically typed — the type checker can’t see their per-attribute signatures — though they still validate keyword names at call time. Reach forgenerate()(committed codegen) when you want typing.
Notebook host¶
Core diff / apply¶
The low-level component-tree engine (JSON wire form), shared byte-for-byte with the browser runtime.
- spaday.diff(old, new)¶
Diff two JSON-encoded component trees, returning the JSON-encoded patch.
Thin wrapper over the shared core (spaday::diff_json); the same code runs in the wasm binding.
- spaday.apply(root, patch)¶
Apply a JSON-encoded patch to a JSON-encoded tree, returning the JSON-encoded result.