Package
wybthon (package)¶
wybthon
¶
Wybthon: SolidJS for Python, running in the browser on Pyodide.
Wybthon brings SolidJS 2.0's signals-first reactive model to Python.
Component bodies run once at mount and return markup written as a
t-string template, html(t"..."). Wybthon's compiler
does what Solid's does for JSX: every dynamic expression in the markup
({count() * 2}, {title}) becomes a getter that updates only
the text node or attribute that reads it, and each literal's static
markup becomes a native template the kernel clones. A virtual DOM
batches every mutation into a single crossing of the Python-to-JavaScript
bridge.
Highlights of the reactive model:
- Compiled templates and components. The compiler runs when a
module is imported (
import wybthoninstalls it), inwyb buildandwyb dev, and under pytest; seewybthon.compiler. It also makes the content ofShow,Loading, and the other flow controls lazy, as JSX children are. - Automatic batching. Signal writes are staged and applied on the
next flush (a microtask, and after each event handler). There is no
batch(); everything batches. Callflushto settle now. - Typed accessors.
create_signalreturns(Accessor[T], Setter[T]); call the accessor to read (tracked),.peek()to read without subscribing. - Parameters are props. A component declares its inputs as
ordinary parameters (
def Card(title: str, body: str = "")). The compiler turns every read of one in the body into a tracked read of the parent's current value, as reading Solid's props is, and pyright and mypy check every call against the function's own signature without a plugin. - Async-first, with transitions. A memo whose body is
async def(or an async generator) is an async computation:Loadingboundaries show fallbacks until it first resolves. A later recompute opens a transition: the UI that depends on the changed input holds its previous, consistent state until the new value lands, so a new id never shows next to old data.is_pending/latestobserve the in-flight state;refreshandresolvedrive it imperatively. - Actions are transactions.
actionholds a transition open while a mutation runs, so its writes land together;create_optimisticandcreate_optimistic_storeshow temporary values immediately and revert when it settles;affectsanduntildescribe what the action changes and wait for it to land. - Draft-first stores.
create_storewraps a dataclass, a dict, or a list and is typed as that same type; its setter takes a function that mutates a draft with plain Python. - Server rendering.
wybthon.serverrenders the same components to HTML in CPython, including async data and out-of-order streaming;hydrateadopts that HTML in the browser instead of rebuilding it. - Server functions.
server_functionmakes anasync defrun on the server wherever it's called, as Solid 2.0's"use server"does;wybthon.router'squeryandform_actionbuild the data layer on it, andwybthon.asgiserves the whole app. - Dev diagnostics. Writes inside a tracking scope raise
WriteInScopeError; reading a reactive value at the top level of a component body warns.
Everything is importable outside a browser (CPython), so unit tests and tooling run anywhere; the DOM is only touched when rendering.
Example
A minimal counter component:
from wybthon import component, create_signal, html, render, untrack
@component
def Counter(initial: int = 0):
count, set_count = create_signal(untrack(lambda: initial))
def increment():
set_count(lambda n: n + 1)
return html(t"<div><p>Count: {count()}</p><button onclick={increment}>+1</button></div>")
render(Counter(initial=5), "#app")
Modules:
| Name | Description |
|---|---|
asgi |
Serve a Wybthon app from Python: pages rendered per request, server functions, and assets. |
assets |
Explicit lazy application chunks produced by |
build |
Deterministic static app bundles, prerendered pages, and a production preview server. |
compiler |
The Wybthon compiler: Solid's compile step, done on Python's syntax tree. |
component |
The |
context |
Context: pass values down the tree without threading props. |
dev |
The |
diagnostics |
Opt-in runtime counters and JSON-ready ownership graph inspection. |
dom |
Lightweight DOM wrapper utilities for Pyodide/browser environments. |
error_boundary |
|
events |
Delegated event handling for the batched renderer. |
flow |
Control flow: |
forms |
Form state, validation helpers, and accessibility attribute utilities. |
kernel |
Batched DOM command buffer and rendering backends. |
lazy |
Lazy-loaded components integrated with |
loading |
|
portal |
Portal component for rendering children into a different DOM container. |
reactivity |
Wybthon's reactive system. |
reconciler |
Reconciliation engine: mounting, patching, and unmounting VNode trees. |
request |
The request being server-rendered, and the response head the render declares. |
router |
Routing and the data layer, as in Solid Router 2.0. |
scheduling |
Cooperative CPU work that gives the browser opportunities to paint. |
server |
Render components to HTML on the server, for hydration in the browser. |
server_functions |
Server functions: Python that runs on the server, called from the browser like any |
store |
Reactive stores: nested state you read like plain data and edit through drafts. |
templates |
HTML templates written as t-strings, compiled once per literal. |
testing |
Render components in plain CPython and query them like a user would. |
virtual |
Fixed-height list virtualization built on owned virtual DOM list regions. |
vnode |
Virtual node data structure and tree-building helpers. |
Type Aliases:
| Name | Description |
|---|---|
Children |
What a component's |
Classes:
| Name | Description |
|---|---|
WybthonWarning |
A development-mode diagnostic: a frozen reactive read, a static list, and the like. |
Component |
A run-once component produced by |
Context |
A context token that also acts as its provider component. |
ContextNotFoundError |
Raised by |
Element |
Thin wrapper around a DOM node with convenience methods. |
Ref |
Mutable container holding a reference to a mounted |
DomEvent |
The event object Wybthon passes to delegated handlers. |
EventHandler |
A handler with native listener options, constructed with |
Match |
A branch of a |
LazyModule |
A cached import that starts on demand; returned by |
Accessor |
A zero-argument callable that returns a reactive value. |
Action |
A wrapped mutation returned by |
ChildrenAccessor |
The resolved children returned by |
Memo |
Read-only derived value; what |
NotReadyError |
Raised when reading an async computation that has no value yet. |
ServerError |
An async memo failed on the server; raised again on the client while hydrating. |
Setter |
The write half of |
Signal |
Mutable reactive container; the accessor half of |
WriteInScopeError |
Raised (in dev mode) when a signal is written inside a tracking scope. |
Root |
A mounted application root returned by |
RequestEvent |
One request being rendered on the server. |
ResponseHead |
The status and headers a server render declares. |
TemplateError |
Raised when a template's markup is malformed or would be rewritten by the HTML parser. |
Node |
Anything that renders: what |
FormData |
A form's fields in submission order; a name may appear more than once. |
UploadedFile |
A file submitted with a form. |
ServerFunction |
A function that runs on the server; returned by |
DraftExpiredError |
A draft was used after its setter or deriving function finished. |
Store |
The read-only reactive view of a dict store. |
StoreList |
The read-only reactive view of a list store. Entity proxies survive reorders. |
StoreObject |
The read-only reactive view of a dataclass store. |
StoreSetter |
Apply an atomic draft edit. Exceptions discard all changes from the call. |
Functions:
| Name | Description |
|---|---|
is_dev_mode |
Return whether development mode is currently active. |
set_dev_mode |
Enable or disable development mode diagnostics globally. |
create_context |
Create a |
use_context |
Read the nearest provided value for |
Errored |
Catch errors raised while rendering |
event |
Configure a native listener. Ordinary handlers use batched delegation. |
For |
Render a list with a stable subtree per row. |
Hydration |
Mark a subtree for hydration; a passthrough in Wybthon. |
NoHydration |
Render |
Repeat |
Render |
Show |
Render |
Switch |
Render the first |
client_only |
Render |
dynamic |
Turn an accessor for a component (or tag) into a component you can call. |
is_hydrating |
Whether the browser is adopting server-rendered DOM right now. |
on_hydration_end |
Run |
lazy_module |
A cached, on-demand import of a module that isn't a component. |
Loading |
Show a fallback while async reads under the boundary aren't ready. |
Reveal |
Coordinate the reveal order of multiple |
Portal |
Render children into a different DOM container. |
action |
Wrap a mutation in a transaction. |
affects |
Declare, inside an action, which values the action is going to change. |
create_deferred |
Create an async memo that may lag, but never holds the rest of the UI. |
create_effect |
Create a side effect that re-runs when its tracked sources change. |
create_memo |
Create a derived value that recomputes when its sources change. |
create_optimistic |
Create a value whose writes are optimistic. |
create_render_effect |
Create a split effect that runs in the render phase, before the DOM commit. |
create_root |
Run |
create_signal |
Create a reactive signal and return its |
create_tracked_effect |
Run a tracked callback after DOM commit, disposing its scope before each run. |
create_unique_id |
Return a unique id string (for |
flatten |
Resolve a children value to the list it renders. |
flush |
Apply staged writes, run every dirty effect, and commit the DOM now. |
from_source |
Adapt a push-based source into the stream an async memo consumes. |
get_owner |
Return the active ownership scope, or |
is_disposed |
Return whether |
is_equal |
Wybthon's default equality: identity, then |
is_pending |
Return True while a change is in flight for the value |
is_server |
Return True while a server render is in progress. |
is_static |
Whether the parent passed a prop as a plain value rather than an expression. |
latest |
Evaluate |
merge |
Merge prop sources into one reactive view; later sources win. |
omit |
Return a reactive view of |
on_cleanup |
Register |
on_flush |
Run |
on_settled |
Run |
prop |
A parameter default that's created once per component instance, like |
refresh |
Recompute a derived read quietly and return an awaitable for its settled value. |
resolve |
Return an awaitable for the next settled value of |
resolve_children |
Resolve a component's children once, so it can inspect or reuse them. |
run_with_owner |
Run |
until |
Return an awaitable for the settled, truthy value of |
untrack |
Read reactive values without tracking them, in |
hydrate |
Adopt server-rendered HTML under |
render |
Render a tree into a container element. |
get_request_event |
Return the request being handled on the server, or |
http_header |
Declare a response header while the calling scope is alive (server only). |
http_status |
Declare the response status while the calling scope is alive (server only). |
set_cookie |
Set a cookie on the response being handled (server only). |
html |
Render a t-string template to a node. |
redirect |
A redirect, for a server function, query, or form action to raise or return. |
reload |
Revalidate queries on the current page without navigating. |
respond |
Return |
server_function |
Make an |
create_optimistic_store |
Layer optimistic draft edits over a reactive authoritative source. |
create_projection |
Create a read-only derived store with memo readiness and refresh semantics. |
create_store |
Create a reactive store and its atomic draft setter. |
deep |
Return a detached snapshot, tracking changes only within this subtree. |
reconcile |
Prepare replacement data, preserving matched list entity identities. |
snapshot |
Return a detached, untracked copy of the currently visible state. |
Children
¶
Children = Any
What a component's children parameter holds: nodes, text, a list of either, or a function returning them.
Annotate the parameter children: Children = None. Content arrives as a
component tag's markup, the children keyword, or item syntax
(Card(title="Hi")[html(t"<p>Body</p>")]).
WybthonWarning
¶
Bases: UserWarning
A development-mode diagnostic: a frozen reactive read, a static list, and the like.
Turn them into errors in tests with -W error::wybthon.WybthonWarning,
or assert on one with pytest.warns(WybthonWarning).
Component
¶
Context
¶
A context token that also acts as its provider component.
Created by create_context. Calling the
context with a value and children returns a provider VNode:
Attributes:
| Name | Type | Description |
|---|---|---|
default |
Value returned by |
|
name |
Optional label for diagnostics. |
ContextNotFoundError
¶
Bases: LookupError
Raised by use_context when no provider is found and no default exists.
Element
¶
Element(tag: str | None = None, existing: bool = False, node: Any = None, node_id: int | None = None)
Thin wrapper around a DOM node with convenience methods.
Element can be constructed in four ways:
- With a tag name to create a brand-new node
(
Element("div")). - With a CSS selector and
existing=Trueto wrap an existing node (Element("#root", existing=True)). - With an opaque
nodevalue to wrap a node returned by another API. - With a kernel
node_id(used internally by the renderer for refs and event targets); the raw node is materialized lazily on first access.
The wrapper proxies common form-input properties (value,
checked, files) so handlers can read state from
e.target.value exactly as in React or SolidJS.
Create a new element, wrap an existing one, or wrap a node handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str | None
|
Tag name ( |
None
|
existing
|
bool
|
If |
False
|
node
|
Any
|
Raw underlying DOM node to wrap. When provided,
|
None
|
node_id
|
int | None
|
Kernel node id to wrap. The raw node is fetched
on first |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Methods:
| Name | Description |
|---|---|
set_text |
Replace the text content of this element. |
append_to |
Append this element to |
append |
Append an |
remove |
Detach this element from its parent (no-op if already detached). |
load_html |
Fetch HTML from |
set_html |
Replace this element's content with the provided HTML string. |
set_attr |
Set an attribute on this element, with text-node fallbacks. |
get_attr |
Return the attribute value for |
remove_attr |
Remove an attribute from this element. |
set_style |
Set CSS properties using a dict and/or keyword arguments. |
add_class |
Add one or more CSS classes to this element. |
remove_class |
Remove one or more CSS classes from this element. |
toggle_class |
Toggle a CSS class, optionally forcing on/off. |
has_class |
Return |
query |
Query a single element by CSS selector. |
query_all |
Query all matching elements by CSS selector. |
find |
Return the first matching descendant |
find_all |
Return all matching descendant elements as a list. |
attach_ref |
Store this element on |
Attributes:
| Name | Type | Description |
|---|---|---|
element |
Any
|
The raw underlying DOM node, materialized on first access. |
node_id |
int
|
This element's kernel node id, registering the raw node if needed. |
value |
Any
|
Current value of an |
checked |
bool
|
Checked state of a checkbox or radio input. |
files |
Any
|
|
element
property
¶
element: Any
The raw underlying DOM node, materialized on first access.
For id-backed elements this commits pending batched DOM ops first, so the node exists and reflects every queued mutation.
load_html
async
¶
load_html(url: str) -> None
Fetch HTML from url and assign it to innerHTML.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to fetch via the browser's |
required |
set_html
¶
set_html(html: str) -> None
Replace this element's content with the provided HTML string.
Caution
This bypasses the renderer's diffing and does not sanitize input. Avoid passing untrusted HTML.
set_attr
¶
get_attr
¶
Return the attribute value for name, or None when absent.
set_style
¶
remove_class
¶
remove_class(*class_names: str) -> None
Remove one or more CSS classes from this element.
toggle_class
¶
has_class
¶
Return True if the element currently has the given class.
query
classmethod
¶
Query a single element by CSS selector.
Commits pending batched DOM ops first so nodes created earlier in the same update are visible to the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
str
|
CSS selector string. |
required |
within
|
Element | None
|
Optional parent |
None
|
Returns:
| Type | Description |
|---|---|
Element | None
|
The first matching |
query_all
classmethod
¶
Query all matching elements by CSS selector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
str
|
CSS selector string. |
required |
within
|
Element | None
|
Optional parent |
None
|
Returns:
| Type | Description |
|---|---|
list[Element]
|
A list of wrapped |
find_all
¶
Return all matching descendant elements as a list.
Ref
¶
Mutable container holding a reference to a mounted Element.
Pass a Ref to an element's ref= prop. After mount ref.current
is the wrapped element; after unmount it's reset to None. The ref
prop also accepts a callback ref(el) or a list mixing both, so a
component can forward a parent's ref and keep its own:
@component
def FancyInput(ref: Ref | Callable[[Element], Any] | None = None):
local = Ref()
on_settled(lambda: local.current.element.focus())
return html(t'<input type="text" ref={[local, ref]}>')
Refs are assigned during mount, so read them in
on_settled or an effect, not at the top of
the component body.
DomEvent
¶
The event object Wybthon passes to delegated handlers.
Built from the kernel's dispatch payload rather than a JsProxy,
so reading it is free of bridge crossings. Use
raw to reach the native event object for
anything not covered by the payload.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Event type string (e.g., |
|
target |
Payload-backed view of the original event target,
exposing |
|
current_target |
The element whose handler is currently running
(an id-backed |
|
key |
|
|
code |
|
|
alt_key |
Whether Alt was held. |
|
ctrl_key |
Whether Ctrl was held. |
|
meta_key |
Whether Meta/Cmd was held. |
|
shift_key |
Whether Shift was held. |
|
button |
|
|
client_x |
Pointer x position, when applicable. |
|
client_y |
Pointer y position, when applicable. |
Build an event from a dispatch payload dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Parsed dispatch payload from the kernel. |
required |
current_target
|
Any | None
|
The |
None
|
Methods:
| Name | Description |
|---|---|
prevent_default |
Prevent the default browser action for this event. |
stop_propagation |
Stop the delegated dispatch from walking further up the tree. |
EventHandler
dataclass
¶
EventHandler(callback: Callable[..., Any], capture: bool = False, passive: bool = False, once: bool = False)
A handler with native listener options, constructed with event.
Match
¶
LazyModule
¶
A cached import that starts on demand; returned by lazy_module.
Call it (or preload) to start the
import; both return the same awaitable. peek
returns the module once it has loaded, else None.
Methods:
| Name | Description |
|---|---|
preload |
Start the import now; the same awaitable as calling the loader. |
peek |
The loaded module, or |
Accessor
¶
A zero-argument callable that returns a reactive value.
Calling an accessor inside a tracking scope (a memo, an effect's
compute stage, or a reactive hole) subscribes that scope to the
value. peek reads without subscribing.
Every reactive read in Wybthon goes through an Accessor:
create_signal getters are
Signals, create_memo
returns a Memo. Embedding an accessor in a
template or VNode tree creates a reactive hole. Type it as Accessor[T] in signatures
when you accept any of them.
Methods:
| Name | Description |
|---|---|
peek |
Return the current value without subscribing anything. |
Action
¶
A wrapped mutation returned by action.
Calling it invokes the wrapped function inside a transaction. The
pending accessor is True while any invocation is in flight; it
reveals immediately, so it's the right thing to bind a disabled
button or a spinner to.
Attributes:
| Name | Type | Description |
|---|---|---|
pending |
Accessor[bool]
|
Tracked accessor: |
pending
instance-attribute
¶
pending: Accessor[bool] = _core.run_with_owner(None, lambda: Memo(lambda: count() > 0))
Tracked accessor: True while an invocation is in flight.
ChildrenAccessor
¶
The resolved children returned by resolve_children.
Calling it returns the single resolved child, or a list when there
are several (or none); to_array
always returns a list.
Methods:
| Name | Description |
|---|---|
to_array |
Return the resolved children as a list (tracked). |
Memo
¶
Memo(fn: Callable[..., T], *, equals: Any = _DEFAULT_EQUALS, lazy: bool = False, unobserved: Callable[[], Any] | None = None, name: str | None = None, loading_value: Any = _MISSING, ssr_source: str = 'server')
Bases: Computation, Accessor[T]
Read-only derived value; what create_memo returns.
A Memo is both a Computation
(it tracks sources and recomputes lazily) and an
Accessor (call it to read). Recomputation
happens on read after a source changed, and observers are notified
only when the recomputed value differs under the memo's equals
policy.
Async bodies (async def, or an async generator) make the memo an
async computation; see create_memo.
Methods:
| Name | Description |
|---|---|
peek |
Return the (up-to-date) value without subscribing; |
NotReadyError
¶
Bases: Exception
Raised when reading an async computation that has no value yet.
Propagates "not ready" through the graph: a memo whose body reads a
pending async memo becomes pending itself, and a reactive hole that
hits NotReadyError keeps its previous content while the nearest
Loading boundary shows its fallback.
Application code rarely raises or catches this directly; use
is_pending and latest
to observe pending state without suspending.
ServerError
¶
Bases: RuntimeError
An async memo failed on the server; raised again on the client while hydrating.
The original exception doesn't survive serialization, so the client
sees its type name and message. An Errored
boundary shows the same fallback on both sides; resetting the
boundary runs the computation again in the browser.
Setter
¶
Bases: Protocol
The write half of create_signal.
Call it with a new value, or with an updater (current) -> new for a
functional update. Returns the value that was staged.
Signal
¶
Signal(value: T, *, equals: Any = _DEFAULT_EQUALS, unobserved: Callable[[], Any] | None = None, name: str | None = None)
Bases: Accessor[T]
Mutable reactive container; the accessor half of create_signal.
Reading a Signal (calling it) returns the committed value and
subscribes the active tracking scope. set
stages a write that becomes visible at the next flush.
While a transition holds the signal (its last write is waiting for async work to land), reads from outside the graph, such as event handlers, keep returning the value the UI shows; reads inside memos, effects, and holes see the new value.
Most code destructures create_signal into (getter, setter);
Signal is public so it can appear in type hints and so
self-contained reactive fields (as in
Field) can carry their own setter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The initial value. |
required |
equals
|
Any
|
Equality policy; see |
_DEFAULT_EQUALS
|
unobserved
|
Callable[[], Any] | None
|
Optional callback invoked when the signal loses its last subscriber (resource cleanup). |
None
|
name
|
str | None
|
Optional label used in dev-mode diagnostics. |
None
|
Methods:
| Name | Description |
|---|---|
peek |
Return the committed value without subscribing. |
set |
Stage a write; the new value is visible after the next flush. |
set
¶
set(value: T | Callable[[T], T]) -> T
Stage a write; the new value is visible after the next flush.
Supports functional updates: when value is callable it
receives the latest value (including any write staged earlier
in the same batch) and its result is stored, so two
set(lambda n: n + 1) calls in one handler add two. To store a
callable as the value, return it from an updater:
set(lambda _: my_fn).
In dev mode, writing from inside a tracking scope raises
WriteInScopeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T | Callable[[T], T]
|
The new value, or an updater |
required |
Returns:
| Type | Description |
|---|---|
T
|
The value that was staged. |
WriteInScopeError
¶
Bases: RuntimeError
Raised (in dev mode) when a signal is written inside a tracking scope.
Writing a signal from a memo body, a single-function effect, or a
reactive hole is almost always a bug: derive the value with
create_memo instead, or move the write
into the untracked apply stage of a split
create_effect, an event handler, or an
action.
Root
¶
RequestEvent
dataclass
¶
RequestEvent(url: str = '/', request: Any = None, locals: dict[str, Any] = dict(), response: ResponseHead = ResponseHead(), method: str = 'GET', headers: dict[str, str] = dict())
One request being rendered on the server.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The request path and query, read by the router. |
request |
Any
|
The framework's request object, passed through as is. |
locals |
dict[str, Any]
|
Per-request values for the application (the signed-in user, a database session, and so on). |
response |
ResponseHead
|
The response head the render declares. |
method |
str
|
The HTTP method. |
headers |
dict[str, str]
|
Request headers by lowercase name. |
ResponseHead
dataclass
¶
ResponseHead(status: int = 200, status_text: str | None = None, headers: dict[str, list[str]] = dict(), committed: bool = False, _statuses: list[tuple[object, int, str | None]] = list(), _headers: list[tuple[object, str, str, bool]] = list(), _base: tuple[int, str | None, dict[str, list[str]]] | None = None)
The status and headers a server render declares.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
int
|
The HTTP status code. |
status_text |
str | None
|
An optional reason phrase. |
headers |
dict[str, list[str]]
|
Header values by lowercase name, in declaration order. |
committed |
bool
|
Set once the head can no longer change (the render finished, or a stream sent its shell). |
Methods:
| Name | Description |
|---|---|
header_items |
Return |
TemplateError
¶
Bases: ValueError
Raised when a template's markup is malformed or would be rewritten by the HTML parser.
Node
¶
Anything that renders: what html(), h(), and a component call give you.
Annotate component functions and node-holding variables with Node.
Item syntax sets a component call's children:
Card(title="Hi")[html(t"<p>Body</p>")].
FormData
¶
FormData(items: Any = None)
A form's fields in submission order; a name may appear more than once.
Read it like a mapping (form["title"], form.get("title"),
"done" in form) for the last value of a field, and with
get_all for every value. A text field's
value is a str, a file input's an UploadedFile.
@form_action
@server_function
async def add_todo(form: FormData) -> None:
await db.todos.add(title=form["title"], done="done" in form)
Methods:
| Name | Description |
|---|---|
get |
The last value of field |
get_all |
Every value of field |
keys |
The field names, each once, in submission order. |
items |
Every |
append |
Add a value for |
to_dict |
Each field's last value. |
encode |
|
parse |
Parse a URL-encoded or multipart request body. |
get
¶
get(name: str) -> str | UploadedFile | None
get(name: str, default: D) -> str | UploadedFile | D
The last value of field name, or default.
get_all
¶
get_all(name: str) -> list[str | UploadedFile]
Every value of field name, in submission order.
UploadedFile
dataclass
¶
ServerFunction
¶
A function that runs on the server; returned by server_function.
Call it like the function it wraps: await save(todo).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The function's id, |
|
method |
Method
|
|
DraftExpiredError
¶
Bases: RuntimeError
A draft was used after its setter or deriving function finished.
Store
¶
Bases: _Proxy, Mapping[Any, Any]
The read-only reactive view of a dict store.
Read it like a dict: store["key"], store.get("key"), in, len,
and iteration are all tracked. Missing keys raise KeyError.
Methods:
| Name | Description |
|---|---|
get |
Return the value for |
StoreList
¶
Bases: _Proxy, Sequence[T]
The read-only reactive view of a list store. Entity proxies survive reorders.
StoreObject
¶
Bases: _Proxy
The read-only reactive view of a dataclass store.
Fields read as tracked attributes. Methods and properties of the
dataclass work too, reading through the view, and isinstance sees
the dataclass, so a store typed as your class behaves like one.
StoreSetter
¶
set_dev_mode
¶
set_dev_mode(enabled: bool) -> None
Enable or disable development mode diagnostics globally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
When |
required |
create_context
¶
Create a Context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Any
|
Optional value returned by |
_MISSING
|
name
|
str | None
|
Optional label for diagnostics. |
None
|
Returns:
| Type | Description |
|---|---|
Context[Any]
|
A new |
use_context
¶
use_context(ctx: Context[T]) -> T
Read the nearest provided value for ctx.
Walks up the ownership tree from the active scope and returns the value exactly as the provider received it: a signal or accessor stays a signal or accessor (call it where you need the value), a static value is returned directly.
Raises:
| Type | Description |
|---|---|
ContextNotFoundError
|
No provider is above the caller and the context has no default. |
Errored
¶
Errored(children: Any = None, *, fallback: Any = None, on_error: Callable[[BaseException], Any] | None = None, reset_on: Any = None) -> VNode
Catch errors raised while rendering children and show a fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Any
|
Content rendered while no error is active: a VNode, a zero-arg callable, or a list of either. |
None
|
fallback
|
Any
|
A VNode, a string, or a callable
|
None
|
on_error
|
Callable[[BaseException], Any] | None
|
Optional callback invoked with the caught exception. |
None
|
reset_on
|
Any
|
An accessor (or plain value) whose change clears the current error automatically, for example the current route. |
None
|
Returns:
| Type | Description |
|---|---|
VNode
|
A component |
VNode
|
whenever a descendant raises. |
event
¶
event(handler: Callable[..., Any], *, capture: bool = False, passive: bool = False, once: bool = False) -> EventHandler
Configure a native listener. Ordinary handlers use batched delegation.
For
¶
For(each: _Each[T], children: Callable[[T, Accessor[int]], object], fallback: Any = None, *, keyed: Literal[True] = True) -> VNode
For(each: _Each[T], children: Callable[[T], object], fallback: Any = None, *, keyed: Literal[True] = True) -> VNode
For(each: _Each[T], children: Callable[[Accessor[T], int], object], fallback: Any = None, *, keyed: Literal[False]) -> VNode
For(each: _Each[T], children: Callable[[Accessor[T]], object], fallback: Any = None, *, keyed: Literal[False]) -> VNode
Render a list with a stable subtree per row.
The mapping callback runs once per row; when the list changes, existing rows keep their DOM and are only moved, never re-diffed. A row's reactive scope is disposed when it leaves the list.
keyed selects how rows are matched, and with it the callback
shape:
True(default): match by identity (scalars by value).children(item, index)receives the raw item and anAccessor[int]index; a callback that takes one parameter gets the item alone.False: match by position.children(item, index)receives anAccessorfor the item at that position and anintindex.- a callable
key(item): match by key, updating the row in place when a new object has the same key.children(item, index)receives accessors for both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
each
|
Any
|
List accessor (or a plain list, which renders once). |
required |
children
|
Any
|
The row callback. |
required |
fallback
|
Any
|
Rendered when the list is empty. |
None
|
keyed
|
Any
|
Matching strategy. |
True
|
Hydration
¶
Mark a subtree for hydration; a passthrough in Wybthon.
Solid 2.0 uses <Hydration> to re-enable hydration for an island
inside <NoHydration>. Wybthon keeps a NoHydration region static
as a whole while hydrating, so this renders its children unchanged.
It's provided so code shared with Solid's model reads the same.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*children
|
Any
|
The content. |
()
|
id
|
str | None
|
Accepted for parity; unused. |
None
|
NoHydration
¶
Render children on the server as static HTML the browser won't hydrate.
While the browser hydrates, the region's server-rendered DOM is kept as is and nothing inside it is mounted, so it costs no Python work and never updates. In a page that wasn't server-rendered, the children render normally. Use it for content that never changes after the first paint: article bodies, footers, legal text.
Matches Solid 2.0's <NoHydration>.
Repeat
¶
Repeat(count: int | Callable[[], int], children: Callable[[int], object], fallback: Any = None, *, start: int | Callable[[], int] = 0) -> VNode
Render children(i) for i in range(start, start + count) with no diffing.
Rendering is driven purely by the count: growing mounts new tail slots, shrinking disposes them, and nothing else is touched. Use it for pagination dots, ratings, skeletons, and other count-driven UI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int | Callable[[], int]
|
Count accessor or plain integer. |
required |
children
|
Callable[[int], object]
|
|
required |
fallback
|
Any
|
Rendered when the count is zero. |
None
|
start
|
int | Callable[[], int]
|
First index (accessor or int). |
0
|
Show
¶
Show(when: Callable[[], T | None], children: Callable[[Accessor[T]], object], fallback: Any = None, *, keyed: Literal[False] = False) -> VNode
Show(when: Callable[[], T | None], children: Callable[[T], object], fallback: Any = None, *, keyed: Literal[True]) -> VNode
Show(when: T | None, children: Callable[[Accessor[T]], object], fallback: Any = None, *, keyed: Literal[False] = False) -> VNode
Render children while when is truthy, else fallback.
Only the truthiness of when decides the branch: the branch
re-renders when the condition flips, not on every value change. A
callable children may accept one argument, an
Accessor for the (truthy) value, so inner
holes can read it reactively.
With keyed=True, children re-renders whenever the value itself
changes and receives the raw value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
when
|
Any
|
Condition accessor or plain value. |
required |
children
|
Any
|
A node, a zero-arg callable, or |
None
|
fallback
|
Any
|
Rendered when |
None
|
keyed
|
bool
|
Re-create the branch on every value change. |
False
|
Switch
¶
Render the first Match whose condition is truthy.
Conditions are evaluated in order; only a change in which branch
matches re-renders, so unrelated value changes are ignored (unless a
branch is keyed).
client_only
¶
Render children only in the browser, after hydration.
During a server render, and while the browser hydrates that render,
fallback shows instead; the children replace it as soon as
hydration has committed. In a page that wasn't server-rendered,
the children render immediately. Use it for widgets that need
browser APIs or whose output depends on the browser (a map, a chart
measured from the viewport, the user's local time).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Any
|
A node or a zero-arg callable returning the content. |
required |
fallback
|
Any
|
What the server renders, and what shows until hydration finishes. |
None
|
dynamic
¶
Turn an accessor for a component (or tag) into a component you can call.
The returned callable behaves like any component: call it with
children and props to get a VNode. Each instance re-mounts when
source resolves to a different component; while source is an
async computation with no value yet, the instance keeps its current
content and the nearest Loading shows its
fallback. Passing None renders nothing.
This is the counterpart of SolidJS 2.0's dynamic(). For a one-off
use, call the result inline: dynamic(lambda: views[kind()])(title="Hi").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
An accessor returning a component, a tag name, or
|
required |
is_hydrating
¶
is_hydrating() -> bool
Whether the browser is adopting server-rendered DOM right now.
True only during the synchronous mount of hydrate:
render what the server rendered, then switch to client-only values
from on_settled. Always false on the server and in pages that
weren't server-rendered.
on_hydration_end
¶
Run callback once the browser has finished hydrating the page.
Registered while hydrate mounts, it runs after
the hydrated page has committed. Registered anywhere else (a page
that wasn't server-rendered, or after hydration), it runs on the
next tick. It doesn't say hydration succeeded, only that it's over.
During a server render it does nothing. Matches Solid 2.0's
onHydrationEnd.
lazy_module
¶
lazy_module(loader: Callable[[], Any], *, chunk: str | None = None) -> LazyModule
A cached, on-demand import of a module that isn't a component.
The counterpart of Solid 2.0's lazyModule; lazy
is the component-shaped sibling. The loader returns a module, a
module path, or an awaitable of either, and runs once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loader
|
Callable[[], Any]
|
Zero-arg callable, sync or async. |
required |
chunk
|
str | None
|
Optional named build chunk to fetch before invoking the loader. |
None
|
Loading
¶
Show a fallback while async reads under the boundary aren't ready.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Any
|
Content rendered when nothing is loading: a VNode, a
zero-arg callable, or a list of either. Async computations
read anywhere in this subtree self-register with the
boundary when a read raises
|
None
|
fallback
|
Any
|
VNode, string, or callable returning one of those, shown while any registered async computation has no value. |
None
|
on
|
Any
|
An accessor, or list of accessors, naming the boundary's
inputs. The boundary waits for them initially even if the
children never read them, and when one of them changes
while data under the boundary is pending, the fallback
shows again instead of the old content being held. Use it
for "new record, fresh boundary" (a route's |
None
|
Returns:
| Type | Description |
|---|---|
VNode
|
A component |
VNode
|
fallback and children. |
Reveal
¶
Reveal(children: Any = None, *, order: RevealOrder = 'sequential', collapsed: bool = False) -> VNode
Coordinate the reveal order of multiple Loading boundaries.
Each Loading boundary mounted underneath (that isn't nested
inside another boundary) registers with the Reveal in mount
order, and the Reveal decides when each may show its content and
whether it shows its fallback. A Reveal nested inside another is
one composite slot in the parent's order: its boundaries stay on
their fallbacks until the parent releases the slot, then follow the
inner order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Any
|
Content containing one or more |
None
|
order
|
RevealOrder
|
|
'sequential'
|
collapsed
|
bool
|
Only consulted with |
False
|
Returns:
| Type | Description |
|---|---|
VNode
|
A component |
Example
Note
Every boundary's content mounts immediately (parked
off-document while pending), so all of them load in parallel;
order only controls when each is revealed.
Portal
¶
Render children into a different DOM container.
Matches SolidJS's <Portal mount={...}>. The children mount into
mount (by default document.body) while remaining linked to the
surrounding component's reactive scope, so signals, context, and
lifecycle hooks still apply, and they're removed when the portal
unmounts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
children
|
Any
|
A VNode, a list of VNodes, or a zero-arg callable (rendered as a reactive hole). |
None
|
mount
|
Any
|
The target container: an |
'body'
|
Returns:
| Type | Description |
|---|---|
VNode
|
A component |
Note
A portal renders nothing during a server render. Its children mount in the browser once the page has hydrated.
action
¶
Wrap a mutation in a transaction.
Calling the returned Action invokes fn and
holds a transition open until it settles. Inside:
- Plain writes stage into the transaction. Signals and stores
written by the action (before or after an
await) commit to the graph but reveal together when the action settles, as does the landing of any memo itrefreshes. Reads inside the action see the staged values. - Optimistic writes reveal now. Values written through
create_optimisticorcreate_optimistic_storeshow immediately and revert when the action settles. action.pending()isTruefrom the call until it settles;affectsmarks other values as pending, anduntilwaits for a condition on the authoritative view.
Independent actions settle separately. Nested actions and actions that write shared reactive state join and publish together.
Errors route to the nearest Errored boundary
captured at call time and re-raise to the awaiter, so
await my_action(...) behaves like a normal call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
The mutation; sync or |
required |
Returns:
| Type | Description |
|---|---|
Action
|
A callable |
Example
todos, set_todos = create_store({"items": []})
shown, set_shown = create_optimistic_store(lambda: deep(todos)["items"], [])
@action
async def add_todo(title):
set_shown(lambda s: s.append({"title": title, "saving": True}))
saved = await api_create(title)
set_todos(lambda s: s["items"].append(saved))
affects
¶
affects(*targets: Any) -> None
Declare, inside an action, which values the action is going to change.
Until the action settles, is_pending reports
True for expressions that read any of targets, even before the
action has written anything. Use it when the pending state should
show on the data being changed rather than on the action itself,
for example to dim a record while a save is in flight.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*targets
|
Any
|
Signals, memos, or stores (a store proxy marks the selected subtree). |
()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside an action's synchronous segment. |
TypeError
|
For a target that isn't a reactive node or store. |
create_deferred
¶
create_deferred(fn: Callable[..., Any], *, equals: Any = _DEFAULT_EQUALS, name: str | None = None, loading_value: Any = _MISSING, ssr_source: SsrSource = 'server') -> Memo[T]
Create an async memo that may lag, but never holds the rest of the UI.
Before its first value it's an ordinary async memo: readers suspend
to the nearest Loading. After it, a refetch opens
no transition: readers keep the last value until the new one lands,
and everything else on the screen updates without waiting for it.
is_pending reports the refetch. Use it for
independent widgets (dashboards, feeds, search results), where the
previous answer with a "refreshing" hint beats waiting with
everything else. Matches Solid 2.0's createDeferred.
Takes the same options as create_memo;
combine it with loading_value for a widget that never suspends.
create_effect
¶
create_effect(compute: Callable[..., Any], apply: Callable[..., Any], *, defer: bool = False, error: Callable[[BaseException], Any] | None = None) -> Computation
Create a side effect that re-runs when its tracked sources change.
Effects run after the DOM has been committed, so they observe the updated document; the first run happens on the next flush (right after the component that created it has mounted), not at creation. Inside a component they're disposed on unmount.
Split effect: compute runs tracked and returns a
value; apply runs untracked with (value, prev) and performs
the side effect. Incidental reads inside apply never
over-subscribe the effect, and signal writes belong there. apply
may return a cleanup callable that runs before the next apply and
on disposal.
Use create_tracked_effect when one
callback should combine tracking and side effects. Split effects keep
committed resources alive while replacement data is held.
If compute accepts a positional parameter it receives its previous
return value (None on the first run). compute may be
async def; awaits suspend the effect without blocking and reads
after an await are still tracked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compute
|
Callable[..., Any]
|
The tracked stage. |
required |
apply
|
Callable[..., Any]
|
Untracked side-effect stage receiving
|
required |
defer
|
bool
|
When |
False
|
error
|
Callable[[BaseException], Any] | None
|
Optional handler receiving exceptions raised by
|
None
|
Returns:
| Type | Description |
|---|---|
Computation
|
The underlying computation; call |
Example
Note
Effects don't run during a server render; see
is_server.
create_memo
¶
create_memo(fn: Callable[..., AsyncIterator[T]], *, equals: Any = ..., lazy: bool = ..., unobserved: Callable[[], Any] | None = ..., name: str | None = ..., loading_value: T = ..., ssr_source: SsrSource = ...) -> Memo[T]
create_memo(fn: Callable[..., Any], *, equals: Any = _DEFAULT_EQUALS, lazy: bool = False, unobserved: Callable[[], Any] | None = None, name: str | None = None, loading_value: Any = _MISSING, ssr_source: SsrSource = 'server') -> Memo[Any]
Create a derived value that recomputes when its sources change.
Memos evaluate once at creation unless lazy=True. Updates are
pull-based: the body runs when the memo is read after
a tracked source changed, and observers are notified only when the
new value differs under equals. If fn accepts a positional
parameter it receives the previous value (None on the first run).
Async memos. When fn is an async def (or returns an
awaitable), the memo becomes an async computation: reading it
before the first value raises
NotReadyError, which the nearest
Loading boundary turns into fallback UI. Once
it has a value, a recompute caused by an input change opens a
transition: readers keep the previous value and the parts of
the UI that depend on the changed input stay as they are until the
new value lands, so the screen never shows a new input next to
old data. Use is_pending to show a refresh
hint and latest to read the new state early.
Reads after an await are tracked exactly like reads before it.
Async generators. An async def body containing yield
streams: each yielded value becomes the memo's new value. Use it
to adapt sockets, subscriptions, or any async iterable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
Zero- or one-arg callable producing the value (sync, async, or an async generator). |
required |
equals
|
Any
|
Equality policy; see |
_DEFAULT_EQUALS
|
lazy
|
bool
|
When |
False
|
unobserved
|
Callable[[], Any] | None
|
Optional callback fired when the memo loses its last
subscriber; pair it with |
None
|
name
|
str | None
|
Optional label used in dev-mode diagnostics. |
None
|
loading_value
|
Any
|
For async memos, a value to serve while the first
run is in flight instead of raising |
_MISSING
|
ssr_source
|
SsrSource
|
Where an async memo resolves when the page is
server-rendered. |
'server'
|
Returns:
| Type | Description |
|---|---|
Memo[Any]
|
A |
create_optimistic
¶
Create a value whose writes are optimistic.
Reads return the override while one is active, else the source
value. Writes reveal immediately, even inside an
action whose other writes are held, and the
override reverts when the transaction it was written in settles.
While an override is active, is_pending
reports True for expressions that read it, and
until sees through it to the source.
Use it both for optimistic data (the like count you expect the server to confirm) and for process state that must show during an action (a "saving" flag).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
A zero-arg accessor to shadow, or a plain initial value. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Accessor[Any], Setter[Any]]
|
A |
create_render_effect
¶
create_render_effect(compute: Callable[..., Any], apply: Callable[..., Any], *, defer: bool = False, error: Callable[[BaseException], Any] | None = None) -> Computation
Create a split effect that runs in the render phase, before the DOM commit.
Wybthon's reactive holes and prop bindings are render effects, so a
render effect observes the DOM in the same state the framework's own
bindings do (updates emitted, not yet committed). Prefer
create_effect unless you're building a
rendering primitive.
Like Solid 2.0's createRenderEffect, it always takes a tracked
compute stage and an untracked apply stage, with the same
arguments as create_effect.
create_root
¶
Run fn inside a root owned by the current scope unless explicitly detached.
Use it for explicitly disposable reactive work. Pass detached=True
for global stores or subscriptions that outlive the surrounding component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[Callable[[], None]], T]
|
Receives a |
required |
detached
|
bool
|
Create an independent lifetime instead of joining the current owner. |
False
|
Returns:
| Type | Description |
|---|---|
T
|
Whatever |
create_signal
¶
create_signal(value: T | Callable[[], T], *, equals: Any = _DEFAULT_EQUALS, name: str | None = None, owned_write: bool = False) -> tuple[Accessor[T], Setter[T]]
Create a reactive signal and return its (getter, setter) pair.
Writes are staged: the setter records the new value and every
read keeps returning the committed value until the next flush (a
browser microtask, the end of an event handler, or an explicit
flush). There is no batch(); everything
batches.
The setter supports functional updates: pass lambda n: n + 1
and it receives the latest staged value, so repeated updates in one
handler compose. To store a callable as the value, return it from an
updater: set_fn(lambda _: my_callable).
Function form. When value is a zero-argument callable, the
result is a writable derived signal: the getter tracks whatever
the function reads and recomputes when those sources change, while
the setter overrides the value until the next source change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T | Callable[[], T]
|
The initial value, or a zero-arg function for the derived form. |
required |
equals
|
Any
|
Equality policy deciding when subscribers are notified:
|
_DEFAULT_EQUALS
|
name
|
str | None
|
Optional label used in dev-mode diagnostics. |
None
|
owned_write
|
bool
|
Allow writes from inside an owned scope (a memo,
an effect's compute stage, or a reactive hole) without
raising |
False
|
Returns:
| Type | Description |
|---|---|
Accessor[T]
|
A |
Setter[T]
|
|
tuple[Accessor[T], Setter[T]]
|
read untracked); the setter is a |
create_tracked_effect
¶
create_tracked_effect(fn: Callable[..., Any], *, error: Callable[[BaseException], Any] | None = None) -> Computation
Run a tracked callback after DOM commit, disposing its scope before each run.
Prefer split effects for external resources: a tracked callback can run while async work is pending. Reads subscribe; put writes in a split effect's apply stage. Doesn't run during a server render.
create_unique_id
¶
create_unique_id() -> str
Return a unique id string (for for/id attribute pairs).
Ids created while a server render or a hydration mounts are derived
from the component's position in the tree (wyb-h followed by a
short hash), so the server and the hydrating browser agree on them.
flatten
¶
Resolve a children value to the list it renders.
Nested lists are flattened, accessors and zero-argument functions are
called (tracked) and their results resolved, and None and booleans
are dropped. The unmemoized form of resolve_children;
matches Solid 2.0's flatten.
flush
¶
flush(fn: Callable[[], T] | None = None) -> T | None
Apply staged writes, run every dirty effect, and commit the DOM now.
Writes become visible to reads only when the graph flushes. In the
browser that happens automatically on a microtask and after every
event handler; call flush() when you need the settled state
now, for example right after a write in synchronous test code.
If the flush opens a transition (a write made an async computation that already had a value recompute), the affected parts of the UI stay on their previous state until that work lands; everything else reveals as usual.
Safe to call at any time; a no-op when nothing is pending, and a no-op inside an effect (the running flush finishes the work).
With fn, runs it first and then flushes, returning its result:
flush(lambda: set_count(1)) applies the write synchronously.
from_source
¶
from_source(source: Any) -> AsyncIterator[T]
Adapt a push-based source into the stream an async memo consumes.
Solid 2.0's from. Return it from a memo's body, and the memo
holds the source's latest value:
source is one of:
- a subscribe function,
subscribe(next, error, complete), that returns an unsubscribe callable (orNone); - an observable: an object with a
subscribe(next, error, complete)method returning an unsubscribe callable or an object withunsubscribe()ordispose()(RxPY's shape); - an async iterable.
Only the latest value is kept: values pushed faster than the memo reads them are dropped, never queued. The source is closed when the memo re-runs or its owner is disposed. During a server render the memo serializes the first value, and the browser subscribes again after hydration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
The push-based source. |
required |
Returns:
| Type | Description |
|---|---|
AsyncIterator[T]
|
An async iterator of the source's values. |
get_owner
¶
get_owner() -> Owner | None
Return the active ownership scope, or None outside any scope.
Capture it before an await and restore it with
run_with_owner when you need to create
primitives after the boundary.
is_equal
¶
Wybthon's default equality: identity, then == (a raising == counts as different).
The policy signals, memos, and stores use unless given equals=.
Matches Solid 2.0's isEqual, with Python equality in place of ===.
is_pending
¶
Return True while a change is in flight for the value fn reads.
Evaluates fn in probe mode and reports whether any value it read
is waiting on a transition:
- a signal or memo whose new value is held (the batch that
changed it is waiting for async work to land, or the write was
made inside an
actionthat hasn't settled); - an async computation whose recompute is in flight (a quiet
refreshis silent); - a value an in-flight action declared with
affects; - an optimistic value with an active override.
A first load isn't a change in flight: while an async value has never
resolved, reading it raises NotReadyError
and the nearest Loading boundary shows its
fallback, and is_pending is False, as in Solid 2.0.
The reads are tracked like any other, so a hole using is_pending
updates as the state changes, but they don't make the hole wait for
the transition: an indicator has to show during the hold.
is_static
¶
Whether the parent passed a prop as a plain value rather than an expression.
The counterpart of Solid 2.0's isStatic. A component library can
take a cheaper path for a prop that can't change: in a compiled
template, <{Button} kind="primary"> passes a value, while
<{Button} kind={variant()}> passes a getter. Accessors count as
expressions; a prop the parent didn't pass is static. Nothing is
read or tracked.
Inside a component, pass the parameter itself: the compiler turns
is_static(name) into a question about the prop, not its value.
is_static(view, "key") asks the same of a key of a merge or
omit view (or a **rest parameter).
latest
¶
latest(fn: Callable[[], T]) -> T | None
Evaluate fn against the newest state, without ever suspending.
Two things differ from a plain read:
- Not-ready async reads return their most recent value (or
Noneif they never resolved) instead of raisingNotReadyError. - Values a transition holds return the new value being computed rather than the one the UI still shows. Use it when a piece of UI should update ahead of the rest (a header that shows the newly selected id while the detail pane keeps the old record).
merge
¶
Merge prop sources into one reactive view; later sources win.
Each source may be a component's **rest parameter, a plain dict
(values may be accessors or static), a zero-argument function returning a dict, or
another merged or omitted view. Reads resolve right to left at access
time, so tracking flows through to whichever source supplied the key.
A key present with the value None overrides earlier sources, as an
explicit undefined does in Solid 2.0.
Read a key as an attribute (view.title), or spread the view onto an
element to bind every key.
omit
¶
Return a reactive view of source without some keys.
Pass key names, or a single predicate that returns True for each
key to drop. A component's **rest parameter is already the view of
the props it doesn't declare; omit narrows a view further:
on_cleanup
¶
Register fn to run when the active scope is disposed or re-runs.
- Inside an effect body: runs before each re-run and on disposal.
- Inside a component body: runs when the component unmounts.
- Inside a reactive hole or
Forrow: runs when that region is re-evaluated or torn down.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside any reactive scope. |
on_flush
¶
Run fn once, right after the pending flush has committed to the DOM.
Solid 2.0's onFlush. fn runs after the next (or the running)
flush, before the browser paints, and never waits for async work: a
flush held by a transition still runs it. A write it makes is an
update of its own, so another update's transition doesn't hold it.
Use it for imperative work that needs the committed DOM right away
(measuring, focusing); for work that should wait until async data
under a component has settled, use on_settled.
Register it from an event handler or other code outside the reactive graph. In a component body or a computation it would run once, after whichever flush comes next, rather than per run; dev mode warns. Doesn't run during a server render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[], Any]
|
Zero-arg callback. |
required |
on_settled
¶
Run fn once the current render has settled and committed to the DOM.
The replacement for on_mount: inside a component body, fn runs
after the flush that mounted the component has finished, so refs
are assigned and the DOM is live. fn may return a cleanup callable,
which runs when the owning scope is disposed (on unmount).
Doesn't run during a server render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[], Any]
|
Zero-arg callback. May return a cleanup callable. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside any reactive scope. |
prop
¶
prop(*, default_factory: Callable[[], T]) -> T
A parameter default that's created once per component instance, like dataclasses.field's.
An ordinary default (step: int = 1) needs no prop(). Use it for a
mutable default, which would otherwise be one object shared by every
instance:
refresh
¶
Recompute a derived read quietly and return an awaitable for its settled value.
"Quiet" means no pending state is reported while the run is in
flight: is_pending stays False and
readers keep the previous value. Use it after a server write to
re-ask for data derived from the source of truth.
Called inside an action, the refreshed value
lands into the action's transaction and reveals together with the
action's other writes when it settles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Any
|
A |
required |
Returns:
| Type | Description |
|---|---|
Awaitable[Any]
|
An awaitable resolving with the target's next settled value. |
Awaitable[Any]
|
Safe to ignore for fire-and-forget use. |
resolve
¶
Return an awaitable for the next settled value of fn().
Tracks every dependency of fn, including cached memos, and waits
for pending or quiet async recomputations. Streams become ready at
their first fresh yield. Rejects when the expression raises; cancellation
removes the temporary subscriptions.
resolve_children
¶
resolve_children(fn: Callable[[], Any]) -> ChildrenAccessor
Resolve a component's children once, so it can inspect or reuse them.
Wraps a getter that returns children (typically a children parameter)
and returns a memoized accessor. Nested lists are flattened,
reactive children (accessors and zero-argument functions) are called
and their results resolved, and None and booleans are dropped.
This matches Solid 2.0's children helper.
run_with_owner
¶
Run fn under owner (pass None for no ownership) and return its result.
until
¶
Return an awaitable for the settled, truthy value of pred().
pred is evaluated reactively against the authoritative view:
optimistic overrides are invisible, so the condition observes real
data only. Inside an action, reads see the action's own staged
writes. A read that raises NotReadyError
simply waits for the value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Callable[[], T]
|
Zero-arg predicate. |
required |
timeout
|
float | None
|
Optional seconds after which the awaitable rejects with
|
None
|
untrack
¶
untrack(fn: Callable[[], T]) -> T
Read reactive values without tracking them, in fn or in a with block.
Use it to read a signal inside an effect without depending on it,
or to seed local state from a prop during component setup without
subscribing (the dev-mode top-level-read warning is silenced inside
untrack; Accessor.peek is the shorter
form for a single read).
count, set_count = create_signal(untrack(lambda: initial))
with untrack():
first, increment = start, step
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[], Any] | None
|
Zero-arg callable to invoke with tracking suppressed. Without
it, |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Whatever |
hydrate
¶
Adopt server-rendered HTML under container and make it interactive.
The counterpart of render for pages rendered by
wybthon.server. The tree mounts exactly as
render would mount it, except that each node claims the matching
node the server already put in the document instead of creating a
new one. Async values the server resolved come from the page's
data-wyb-state script, so they're neither fetched again nor shown
as loading. Input recorded by the production bootstrap before
hydration is replayed afterward.
Mismatches never break the page: a node that doesn't match is created in place, server nodes nobody claimed are removed, and dev mode logs a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vnode
|
Any
|
The same root view the server rendered. |
required |
container
|
Element | str | int
|
The element holding the server-rendered markup: an
|
required |
Returns:
| Type | Description |
|---|---|
Root
|
A |
render
¶
Render a tree into a container element.
Mounts vnode under container, commits every buffered DOM op in
one bridge crossing, and registers the container as an event
delegation root. Rendering into the same container again patches the
existing tree in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vnode
|
Any
|
The root VNode (or a component call, string, list, or reactive expression; anything a component may return). |
required |
container
|
Element | str | int
|
An |
required |
Returns:
| Type | Description |
|---|---|
Root
|
A |
get_request_event
¶
get_request_event() -> RequestEvent | None
Return the request being handled on the server, or None in the browser.
That's the request a server render is for, or the one a server function call came in with.
http_header
¶
Declare a response header while the calling scope is alive (server only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The header name (case-insensitive). |
required |
value
|
str
|
The header value. |
required |
append
|
bool
|
Add another value instead of replacing existing ones
(for |
False
|
http_status
¶
Declare the response status while the calling scope is alive (server only).
The most recent live declaration wins. When the declaring scope is disposed before the head is committed, its declaration is removed and the status falls back to the latest one still alive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
int
|
The HTTP status code. |
required |
text
|
str | None
|
An optional reason phrase. |
None
|
set_cookie
¶
set_cookie(name: str, value: str, *, max_age: int | None = None, path: str = '/', domain: str | None = None, secure: bool = True, http_only: bool = True, same_site: Literal['lax', 'strict', 'none'] = 'lax') -> None
Set a cookie on the response being handled (server only).
Call it from a server function, or while a page renders on the
server. Pass max_age=0 to delete a cookie. In the browser it does
nothing.
html
¶
Render a t-string template to a node.
The template is HTML with interpolations. Each literal is compiled once (see the module docs); later calls only supply values.
Interpolation positions:
- Child (
<p>{value}</p>): text, a node, a list,None, or a reactive expression (an accessor or zero-argument function), which becomes a hole. - Attribute (
<a href={url}>): a value applied once, or a reactive expression bound to that attribute. - Part of an attribute (
class="card card-{kind}"): the parts form one string, re-rendered together when any reactive part changes. - Event (
onclick={handler},onClick, oron:click): a delegated handler, taking the event or no arguments. - Spread (
<input {attrs}>): a mapping of props. - Component tag (
<{Card} title="Hi">...</{Card}>or<{Card} />): calls the component with the attributes as keyword props and the content aschildren.
Attribute names are HTML names (class, for, aria-label). Text
follows JSX's whitespace rules: text spanning lines is trimmed line by
line and joined with spaces, and whitespace-only text containing a
newline is dropped. Several top-level nodes make a fragment.
The compiler replaces every html(t"...") call in a compiled module
with an instance of the literal's precompiled entry, so this function
only runs for templates that weren't compiled (a REPL, exec).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template
|
Template
|
A t-string. |
required |
Returns:
| Type | Description |
|---|---|
VNode
|
A node to place in the tree or return from a component. |
Raises:
| Type | Description |
|---|---|
TemplateError
|
The markup is malformed, or the HTML parser would
rewrite it (for example |
redirect
¶
redirect(url: str, status: int = 302, *, revalidate: str | list[str] | None = None, headers: dict[str, str] | None = None) -> Redirect
A redirect, for a server function, query, or form action to raise or return.
In the browser, the router navigates to url (replacing the history
entry); a JavaScript-free form post gets a 303 to it. Raised from a
query while a page renders on the server, it becomes the page's
response. revalidate names the queries to refetch first; by default
a redirect from a mutation revalidates everything the next page reads.
reload
¶
reload(*, revalidate: str | list[str] | None = None, headers: dict[str, str] | None = None) -> Reload
Revalidate queries on the current page without navigating.
revalidate names query keys (or key prefixes); omit it to
revalidate every query on the page.
respond
¶
server_function
¶
server_function(fn: Callable[P, Awaitable[R]]) -> ServerFunction[P, R]
server_function(*, method: Method = 'POST') -> Callable[[Callable[P, Awaitable[R]]], ServerFunction[P, R]]
Make an async def run on the server, wherever it's called from.
Use it bare (@server_function) for a mutation, called with POST, or
with method="GET" for a read. See
wybthon.server_functions for the whole
contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Any
|
The |
None
|
method
|
Method
|
|
'POST'
|
Returns:
| Type | Description |
|---|---|
Any
|
A |
Any
|
signature. |
create_optimistic_store
¶
Layer optimistic draft edits over a reactive authoritative source.
Active edits replay in submission order when the source changes. They are removed when their submitting action settles; other actions keep their edits. Draft callbacks must be deterministic: replay mustn't perform network or other side effects.
create_store
¶
create_store(initial: Callable[[T], object], seed: T, *, shallow: bool = False) -> tuple[T, StoreSetter[T]]
create_store(initial: Callable[[], object], seed: None = None, *, shallow: bool = False) -> tuple[Any, StoreSetter[Any]]
create_store(initial: T, seed: None = None, *, shallow: bool = False) -> tuple[T, StoreSetter[T]]
create_store(initial: Any, seed: Any = None, *, shallow: bool = False) -> tuple[Any, StoreSetter[Any]]
Create a reactive store and its atomic draft setter.
initial is a dict, a list, or a dataclass instance; the store takes
ownership of it, so don't keep mutating it yourself. The returned view
is typed as initial's own type: create_store(State(...)) gives a
State whose fields are tracked attributes, and the setter takes
Callable[[State], object].
With a function, the store is derived: the function either mutates
the draft it's given or returns new data (reconciled by "id"),
synchronously or asynchronously. Its reads are tracked and its
writes are staged together. seed is the starting data.
With shallow=True, only the top level is reactive: nested values
are stored and returned as they are, and replacing one is the only
way to change it.
reconcile
¶
Prepare replacement data, preserving matched list entity identities.
key names the field that identifies list entities ("id" by
default), or is a function computing the identity from an entity.
key=None replaces list entities positionally. Duplicate keys are
matched in occurrence order, without assigning the same entity to
multiple rows.
snapshot
¶
Return a detached, untracked copy of the currently visible state.
Public API by area¶
Everything below is importable with from wybthon import .... Module
pages linked in the left column carry the details.
| Area | Names |
|---|---|
| Templates | html, TemplateError, Node |
| Components | component, Component, Children, prop, merge, omit, is_static, resolve_children, flatten, ChildrenAccessor |
| Reactivity | Accessor, Setter, Signal, Memo, create_signal, create_memo, create_deferred, create_effect, create_tracked_effect, create_render_effect, create_root, is_disposed, is_equal, create_unique_id, flush, on_settled, on_flush, on_cleanup, untrack, get_owner, run_with_owner, WriteInScopeError |
| Async | NotReadyError, ServerError, is_pending, latest, refresh, resolve, from_source, action, Action, affects, until, create_optimistic |
| Stores | Store, StoreList, StoreObject, StoreSetter, DraftExpiredError, create_store, create_projection, create_optimistic_store, reconcile, snapshot, deep |
| Flow control | Show, For, Repeat, Switch, Match, dynamic, client_only |
| Boundaries | Loading, Reveal, Errored, Portal, lazy, lazy_module, LazyModule |
| Context | Context, ContextNotFoundError, create_context, use_context |
| DOM and events | Element, Ref, DomEvent, EventHandler, event |
| Rendering | render, hydrate, Root, is_server, is_hydrating, on_hydration_end, NoHydration, Hydration |
| Server requests | RequestEvent, ResponseHead, get_request_event, http_status, http_header, set_cookie |
| Server functions | server_function, ServerFunction, redirect, reload, respond, FormData, UploadedFile |
| Dev mode | is_dev_mode, set_dev_mode, WybthonWarning |
Other modules are imported by name and aren't re-exported:
| Module | Contents |
|---|---|
wybthon.router |
create_router, Router, Route, PreloadArgs, Outlet, navigate, url, use_location, Location, use_params, Params, use_search_params, SearchParamsView, SearchParams, use_route_matches, use_link_state, LinkState, preload_route, file_routes, match_route, RouteSpec; the data layer: query, revalidate, form_action, use_submissions |
wybthon.asgi |
create_app, which serves pages, server functions, and form actions per request |
wybthon.forms |
form_state, FormState, Field, the bind_* helpers, validators, and ARIA helpers |
wybthon.server |
render_to_string, render_to_stream, RenderStream |
wybthon.testing |
render, Screen, fire, cleanup, raise_unhandled, and the in-memory DOM |
wybthon.compiler |
The template compiler: install, uninstall, compile_source, transform |
wybthon.virtual, wybthon.scheduling |
Virtual lists and cooperative scheduling |
wybthon.vnode |
The node layer for markup built by code: h, hole, VNode, Fragment |
wybthon.reactivity |
The reactive core, async, and props names above, plus Owner, get_observer, create_reaction, map_array, repeat, is_accessor, Computation, and Transition |
from wybthon import component, create_signal, html, render, untrack
@component
def Counter(initial: int = 0):
count, set_count = create_signal(untrack(lambda: initial))
def increment():
set_count(lambda n: n + 1)
return html(t"<div><p>Count: {count()}</p><button onclick={increment}>+1</button></div>")
root = render(Counter(initial=5), "#app")
# later: root.dispose()
Browser versus CPython
Reactivity (including async memos, actions, and flush), stores,
forms, context, flow control, and VDOM construction (VNode, h,
Fragment, templates) all run in plain CPython, which is how
the unit tests work. Touching a real DOM (render into a page,
Element queries, navigate with history) needs Pyodide, or the
in-memory DOM of wybthon.testing.