Skip to content

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 wybthon installs it), in wyb build and wyb dev, and under pytest; see wybthon.compiler. It also makes the content of Show, 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. Call flush to settle now.
  • Typed accessors. create_signal returns (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: Loading boundaries 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 / latest observe the in-flight state; refresh and resolve drive it imperatively.
  • Actions are transactions. action holds a transition open while a mutation runs, so its writes land together; create_optimistic and create_optimistic_store show temporary values immediately and revert when it settles; affects and until describe what the action changes and wait for it to land.
  • Draft-first stores. create_store wraps 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.server renders the same components to HTML in CPython, including async data and out-of-order streaming; hydrate adopts that HTML in the browser instead of rebuilding it.
  • Server functions. server_function makes an async def run on the server wherever it's called, as Solid 2.0's "use server" does; wybthon.router's query and form_action build the data layer on it, and wybthon.asgi serves 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")
See Also

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 wyb build.

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 @component decorator and the Component type it produces.

context

Context: pass values down the tree without threading props.

dev

The wyb command: develop, build, and preview Wybthon projects.

diagnostics

Opt-in runtime counters and JSON-ready ownership graph inspection.

dom

Lightweight DOM wrapper utilities for Pyodide/browser environments.

error_boundary

Errored: catch render and effect errors in a subtree.

events

Delegated event handling for the batched renderer.

flow

Control flow: Show, For, Repeat, Switch/Match, dynamic, and client_only.

forms

Form state, validation helpers, and accessibility attribute utilities.

kernel

Batched DOM command buffer and rendering backends.

lazy

Lazy-loaded components integrated with Loading boundaries.

loading

Loading and Reveal: fallback UI for async computations.

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 async def.

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 children parameter holds: nodes, text, a list of either, or a function returning them.

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 component.

Context

A context token that also acts as its provider component.

ContextNotFoundError

Raised by use_context when no provider is found and no default exists.

Element

Thin wrapper around a DOM node with convenience methods.

Ref

Mutable container holding a reference to a mounted Element.

DomEvent

The event object Wybthon passes to delegated handlers.

EventHandler

A handler with native listener options, constructed with event.

Match

A branch of a Switch.

LazyModule

A cached import that starts on demand; returned by lazy_module.

Accessor

A zero-argument callable that returns a reactive value.

Action

A wrapped mutation returned by action.

ChildrenAccessor

The resolved children returned by resolve_children.

Memo

Read-only derived value; what create_memo returns.

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 create_signal.

Signal

Mutable reactive container; the accessor half of create_signal.

WriteInScopeError

Raised (in dev mode) when a signal is written inside a tracking scope.

Root

A mounted application root returned by render.

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 html(), h(), and a component call give you.

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 server_function.

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 Context.

use_context

Read the nearest provided value for ctx.

Errored

Catch errors raised while rendering children and show a fallback.

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 children on the server as static HTML the browser won't hydrate.

Repeat

Render children(i) for i in range(start, start + count) with no diffing.

Show

Render children while when is truthy, else fallback.

Switch

Render the first Match whose condition is truthy.

client_only

Render children only in the browser, after hydration.

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 callback once the browser has finished hydrating the page.

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 Loading boundaries.

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 fn inside a root owned by the current scope unless explicitly detached.

create_signal

Create a reactive signal and return its (getter, setter) pair.

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 for/id attribute pairs).

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 None outside any scope.

is_disposed

Return whether owner has been disposed.

is_equal

Wybthon's default equality: identity, then == (a raising == counts as different).

is_pending

Return True while a change is in flight for the value fn reads.

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 fn against the newest state, without ever suspending.

merge

Merge prop sources into one reactive view; later sources win.

omit

Return a reactive view of source without some keys.

on_cleanup

Register fn to run when the active scope is disposed or re-runs.

on_flush

Run fn once, right after the pending flush has committed to the DOM.

on_settled

Run fn once the current render has settled and committed to the DOM.

prop

A parameter default that's created once per component instance, like dataclasses.field's.

refresh

Recompute a derived read quietly and return an awaitable for its settled value.

resolve

Return an awaitable for the next settled value of fn().

resolve_children

Resolve a component's children once, so it can inspect or reuse them.

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().

untrack

Read reactive values without tracking them, in fn or in a with block.

hydrate

Adopt server-rendered HTML under container and make it interactive.

render

Render a tree into a container element.

get_request_event

Return the request being handled on the server, or None in the browser.

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 value with a status, headers, or the query keys this call changed.

server_function

Make an async def run on the server, wherever it's called from.

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

Component(fn: Callable[..., Any])

A run-once component produced by component.

Calling it returns a VNode; the reconciler runs the component's body once per mount.

Context

Context(default: Any = _MISSING, name: str | None = None)

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:

Theme(value, *children)
Theme("dark", App())
Theme(lambda: theme(), App())     # reactive value

Attributes:

Name Type Description
default

Value returned by use_context when no provider is found, if one was declared.

name

Optional label for diagnostics.

has_default property

has_default: bool

Whether the context was created with a default value.

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=True to wrap an existing node (Element("#root", existing=True)).
  • With an opaque node value 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 ("div") or, when existing=True, a CSS selector identifying the node to wrap.

None
existing bool

If True, query the document for tag instead of creating a new element.

False
node Any

Raw underlying DOM node to wrap. When provided, tag and existing are ignored.

None
node_id int | None

Kernel node id to wrap. The raw node is fetched on first element access.

None

Raises:

Type Description
ValueError

If neither node, node_id, nor a usable tag is provided.

Methods:

Name Description
set_text

Replace the text content of this element.

append_to

Append this element to parent.

append

Append an Element or a text string as a child node.

remove

Detach this element from its parent (no-op if already detached).

load_html

Fetch HTML from url and assign it to innerHTML.

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 name, or None when absent.

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 True if the element currently has the given class.

query

Query a single element by CSS selector.

query_all

Query all matching elements by CSS selector.

find

Return the first matching descendant Element, or None.

find_all

Return all matching descendant elements as a list.

attach_ref

Store this element on ref.current.

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 <input>, <textarea>, or <select>.

checked bool

Checked state of a checkbox or radio input.

files Any

FileList for file inputs (<input type="file">), or None.

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.

node_id property

node_id: int

This element's kernel node id, registering the raw node if needed.

value property writable

value: Any

Current value of an <input>, <textarea>, or <select>.

checked property writable

checked: bool

Checked state of a checkbox or radio input.

files property

files: Any

FileList for file inputs (<input type="file">), or None.

set_text

set_text(text: str) -> None

Replace the text content of this element.

append_to

append_to(parent: Element) -> None

Append this element to parent.

append

append(child: Element | str) -> None

Append an Element or a text string as a child node.

remove

remove() -> None

Detach this element from its parent (no-op if already detached).

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 fetch API.

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

set_attr(name: str, value: str | int | float | bool) -> None

Set an attribute on this element, with text-node fallbacks.

Parameters:

Name Type Description Default
name str

Attribute name (or nodeValue/text for text nodes).

required
value str | int | float | bool

Attribute value; coerced to str.

required

get_attr

get_attr(name: str) -> str | None

Return the attribute value for name, or None when absent.

remove_attr

remove_attr(name: str) -> None

Remove an attribute from this element.

set_style

set_style(styles: dict[str, str | int] | None = None, **style_kwargs: str | int) -> None

Set CSS properties using a dict and/or keyword arguments.

Parameters:

Name Type Description Default
styles dict[str, str | int] | None

Optional mapping of CSS property name to value.

None
**style_kwargs str | int

Additional CSS properties (last write wins if a key appears in both).

{}

add_class

add_class(*class_names: str) -> None

Add one or more CSS classes to this element.

remove_class

remove_class(*class_names: str) -> None

Remove one or more CSS classes from this element.

toggle_class

toggle_class(class_name: str, force: bool | None = None) -> None

Toggle a CSS class, optionally forcing on/off.

Parameters:

Name Type Description Default
class_name str

Class to toggle.

required
force bool | None

Pass True to ensure the class is added, False to ensure it's removed; None toggles based on the current state.

None

has_class

has_class(class_name: str) -> bool

Return True if the element currently has the given class.

query classmethod

query(selector: str, within: Element | None = None) -> Element | None

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 Element to scope the query to. Defaults to document.

None

Returns:

Type Description
Element | None

The first matching Element, or None if no node matches.

query_all classmethod

query_all(selector: str, within: Element | None = None) -> list[Element]

Query all matching elements by CSS selector.

Parameters:

Name Type Description Default
selector str

CSS selector string.

required
within Element | None

Optional parent Element to scope the query to. Defaults to document.

None

Returns:

Type Description
list[Element]

A list of wrapped Element instances (possibly empty).

find

find(selector: str) -> Element | None

Return the first matching descendant Element, or None.

find_all

find_all(selector: str) -> list[Element]

Return all matching descendant elements as a list.

attach_ref

attach_ref(ref: Ref) -> None

Store this element on ref.current.

Ref

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

DomEvent(payload: dict[str, Any], current_target: Any | None = None)

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., "click").

target

Payload-backed view of the original event target, exposing value, checked, files, and element.

current_target

The element whose handler is currently running (an id-backed Element).

key

KeyboardEvent.key, or None for non-keyboard events.

code

KeyboardEvent.code, or None.

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

MouseEvent.button (0 for primary).

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 Element whose handler is being invoked.

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.

raw property

raw: Any

The native browser event object (escape hatch).

Only valid synchronously during dispatch; returns None afterwards.

prevent_default

prevent_default() -> None

Prevent the default browser action for this event.

stop_propagation

stop_propagation() -> None

Stop the delegated dispatch from walking further up the tree.

Also stops native propagation so other JS listeners above don't fire.

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

Match(when: Any, children: Any = None, *, keyed: bool = False)

A branch of a Switch.

Parameters:

Name Type Description Default
when Any

Condition accessor or plain value.

required
children Any

A node, zero-arg callable, or (value) -> node receiving an Accessor (or the raw value with keyed=True).

None
keyed bool

Re-create the branch on every value change.

False

LazyModule

LazyModule(loader: Callable[[], Any], chunk: str | None)

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 None while it hasn't landed.

preload

preload() -> Any

Start the import now; the same awaitable as calling the loader.

peek

peek() -> Any

The loaded module, or None while it hasn't landed.

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.

peek

peek() -> T

Return the current value without subscribing anything.

Action

Action(fn: Callable[P, Any])

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: True while an invocation is in flight.

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

ChildrenAccessor(memo: Memo[list[Any]])

Bases: Accessor[Any]

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).

to_array

to_array() -> list[Any]

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; None while not ready.

peek

peek() -> T

Return the (up-to-date) value without subscribing; None while not ready.

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

ServerError(message: str, type_name: str = 'Exception')

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 create_signal.

_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.

peek

peek() -> T

Return the committed value without subscribing.

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 (current) -> new.

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

Root(container: Element, vnode: VNode, owner: Owner)

A mounted application root returned by render.

Attributes:

Name Type Description
container

The container Element.

vnode

The currently rendered root VNode.

Methods:

Name Description
dispose

Unmount the tree, dispose every reactive scope, and stop event delegation.

node_id property

node_id: int

Kernel node id of the container.

dispose

dispose() -> None

Unmount the tree, dispose every reactive scope, and stop event delegation.

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.

cookies property

cookies: dict[str, str]

The request's cookies by 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 (name, value) pairs, one per value, for an HTTP response.

header_items

header_items() -> list[tuple[str, str]]

Return (name, value) pairs, one per value, for an HTTP response.

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 name, or default.

get_all

Every value of field name, in submission order.

keys

The field names, each once, in submission order.

items

Every (name, value) pair, in submission order.

append

Add a value for name.

to_dict

Each field's last value.

encode

(content type, body) for sending these fields in a request.

parse

Parse a URL-encoded or multipart request body.

get

get(name: str) -> str | UploadedFile | None
get(name: str, default: D) -> str | UploadedFile | D
get(name: str, default: Any = None) -> Any

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.

keys

keys() -> list[str]

The field names, each once, in submission order.

items

items() -> list[tuple[str, str | UploadedFile]]

Every (name, value) pair, in submission order.

append

append(name: str, value: str | UploadedFile) -> None

Add a value for name.

to_dict

to_dict() -> dict[str, str | UploadedFile]

Each field's last value.

encode

encode() -> tuple[str, bytes]

(content type, body) for sending these fields in a request.

parse classmethod

parse(content_type: str, body: bytes) -> FormData

Parse a URL-encoded or multipart request body.

UploadedFile dataclass

UploadedFile(filename: str, content_type: str, data: bytes)

A file submitted with a form.

Attributes:

Name Type Description
filename str

The name the browser sent.

content_type str

The file's media type.

data bytes

The file's bytes.

size property

size: int

The file's size in bytes.

ServerFunction

ServerFunction(fn: Callable[P, Awaitable[R]], method: Method)

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, module:qualname.

method Method

"POST" (a mutation, the default) or "GET" (a read).

url property

url: str

The URL the browser calls, under the app's base path.

DraftExpiredError

Bases: RuntimeError

A draft was used after its setter or deriving function finished.

Store

Store(node: _Node, session: _Session | None = None)

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 key, or default when absent (tracked either way).

get

get(key: Any, default: Any = None) -> Any

Return the value for key, or default when absent (tracked either way).

A tracked read of an absent key subscribes to it, so a computation reading store.get(row_id) re-runs when that key appears.

StoreList

StoreList(node: _Node, session: _Session | None = None)

Bases: _Proxy, Sequence[T]

The read-only reactive view of a list store. Entity proxies survive reorders.

StoreObject

StoreObject(node: _Node, session: _Session | None = None)

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

StoreSetter(node: _Node)

Apply an atomic draft edit. Exceptions discard all changes from the call.

Methods:

Name Description
edit

Edit the store in a with block: the draft's changes stage together when it ends.

edit

edit() -> Iterator[T]

Edit the store in a with block: the draft's changes stage together when it ends.

The block is the setter's callback written inline, so it's atomic in the same way: an exception discards every change it made.

with set_state.edit() as draft:
    draft.todos[0].title = title
    draft.todos[0].done = False

is_dev_mode

is_dev_mode() -> bool

Return whether development mode is currently active.

set_dev_mode

set_dev_mode(enabled: bool) -> None

Enable or disable development mode diagnostics globally.

Parameters:

Name Type Description Default
enabled bool

When False, warn and warn_once become no-ops, WriteInScopeError is not raised, and tracebacks are suppressed in log_error.

required

create_context

create_context(default: T, *, name: str | None = None) -> Context[T]
create_context(*, name: str | None = None) -> Context[T]
create_context(default: Any = _MISSING, *, name: str | None = None) -> Context[Any]

Create a Context.

Parameters:

Name Type Description Default
default Any

Optional value returned by use_context when no provider is above the reader. Without one, reading outside a provider raises ContextNotFoundError.

_MISSING
name str | None

Optional label for diagnostics.

None

Returns:

Type Description
Context[Any]

A new Context; call it to provide, pass it to use_context to read.

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 (err, reset) -> VNode (or (err) -> VNode). err is an accessor for the caught exception; reset() clears the error and re-renders the children.

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 that swaps to the fallback

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
For(each: _Each[T], children: Callable[[Accessor[T], Accessor[int]], object], fallback: Any = None, *, keyed: Callable[[T], object]) -> VNode
For(each: _Each[T], children: Callable[[Accessor[T]], object], fallback: Any = None, *, keyed: Callable[[T], object]) -> VNode
For(each: Any, children: Any, fallback: Any = None, *, keyed: Any = True) -> 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 an Accessor[int] index; a callback that takes one parameter gets the item alone.
  • False: match by position. children(item, index) receives an Accessor for the item at that position and an int index.
  • 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
Example
# With a key function both arguments are accessors.
For(todos, lambda todo, i: html(t"<li>{todo()['title']}</li>"), keyed=lambda t: t["id"])

Hydration

Hydration(*children: Any, id: str | None = None) -> VNode

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

NoHydration(*children: Any) -> VNode

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]

(index: int) -> node, rendered once per slot.

required
fallback Any

Rendered when the count is zero.

None
start int | Callable[[], int]

First index (accessor or int).

0
Example
Repeat(rating, lambda i: html(t"<span>*</span>"))

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
Show(when: T | None, children: Callable[[T], object], fallback: Any = None, *, keyed: Literal[True]) -> VNode
Show(when: object, children: Callable[[], object] | VNode | Props | str | list[Any] | None = None, fallback: Any = None, *, keyed: bool = False) -> VNode
Show(when: Any, children: Any = None, fallback: Any = None, *, keyed: bool = 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 (value) -> node.

None
fallback Any

Rendered when when is falsy.

None
keyed bool

Re-create the branch on every value change.

False
Example
Show(user, lambda u: html(t"<p>Hello, {u().name}</p>"), fallback=html(t"<p>Sign in</p>"))

Switch

Switch(*matches: Match, fallback: Any = None) -> VNode

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).

Switch(
    Match(lambda: status() == "loading", html(t"<p>Loading...</p>")),
    Match(lambda: status() == "ready", html(t"<p>Ready</p>")),
    fallback=html(t"<p>Unknown</p>"),
)

client_only

client_only(children: Any, *, fallback: Any = None) -> VNode

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
Example
client_only(lambda: Chart(data=data), fallback=html(t"<p>Loading chart...</p>"))

dynamic

dynamic(source: Any) -> Callable[..., VNode]

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 None; a plain component or tag is accepted too.

required
Example
Editor = dynamic(lambda: RichEditor if rich_mode() else PlainEditor)

@component
def Page():
    return html(t"<div>{Editor(value=draft, on_change=set_draft)}</div>")

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

on_hydration_end(callback: Callable[[], Any]) -> None

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
Example
admin = lazy_module(lambda: "app.admin.routes", chunk="admin")

async def open_admin():
    routes = await admin()
    ...

admin.peek()  # the module, or None until it has loaded

Loading

Loading(children: Any = None, *, fallback: Any = None, on: Any = None) -> VNode

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 NotReadyError.

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 id), not for refreshes.

None

Returns:

Type Description
VNode

A component VNode that toggles between

VNode

fallback and children.

Example
Loading(
    lambda: Fragment(Header(), Body()),
    fallback=Spinner(),
    on=user_id,
)

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 Loading boundaries.

None
order RevealOrder

"sequential" (default; contents reveal in DOM order, each waiting for the ones before it), "together" (the whole group reveals at once when every boundary has loaded), or "natural" (each boundary reveals on its own data; useful for a nested group that should count as one slot in the parent without coordinating internally).

'sequential'
collapsed bool

Only consulted with order="sequential". When True, boundaries past the current frontier render nothing instead of their own fallback, so only one fallback shows.

False

Returns:

Type Description
VNode

A component VNode.

Example
html(t'''
  <{Reveal} collapsed>
    {Loading(PanelA(), fallback=html(t"<p>Loading A...</p>"))}
    {Loading(PanelB(), fallback=html(t"<p>Loading B...</p>"))}
  </{Reveal}>
''')
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

Portal(children: Any = None, *, mount: Any = 'body') -> VNode

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 Element instance, a CSS selector string, or a kernel node id. Defaults to "body".

'body'

Returns:

Type Description
VNode

A component VNode whose children render inside mount.

Note

A portal renders nothing during a server render. Its children mount in the browser once the page has hydrated.

Example
modal = html(t'<div class="modal"><p>Modal content</p></div>')
html(t"<main>{Show(show_modal(), Portal(modal, mount='#modal-root'))}</main>")

action

action(fn: Callable[P, Awaitable[R]]) -> Action[P, Future[R]]
action(fn: Callable[P, R]) -> Action[P, R]
action(fn: Callable[..., Any]) -> 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 it refreshes. Reads inside the action see the staged values.
  • Optimistic writes reveal now. Values written through create_optimistic or create_optimistic_store show immediately and revert when the action settles.
  • action.pending() is True from the call until it settles; affects marks other values as pending, and until waits 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 async def.

required

Returns:

Type Description
Action

A callable Action with a tracked .pending accessor.

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.

Example
@action
async def rename(user_id, name):
    affects(users)
    await api_rename(user_id, name)
    refresh(users)

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.

Example
async def load_rows():
    return await fetch_rows(period())

rows = create_deferred(load_rows)

html(t'<section class={"stale" if is_pending(rows) else ""}>{For(rows, row)}</section>')

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 (value, prev) (or just (value,) if it declares one parameter). May return a cleanup callable.

required
defer bool

When True, skip the first apply (tracking still starts immediately).

False
error Callable[[BaseException], Any] | None

Optional handler receiving exceptions raised by compute (sync or async) instead of routing them to the nearest Errored boundary.

None

Returns:

Type Description
Computation

The underlying computation; call .dispose() to stop it.

Example
create_effect(count, lambda value, prev: print(prev, "->", value))

create_effect(
    lambda: name(),
    lambda value: (timer := start_timer(value), lambda: stop_timer(timer))[1],
    defer=True,
)
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[..., Awaitable[T]], *, equals: Any = ..., lazy: bool = ..., unobserved: Callable[[], Any] | None = ..., name: str | None = ..., loading_value: T = ..., ssr_source: SsrSource = ...) -> Memo[T]
create_memo(fn: Callable[..., 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 create_signal.

_DEFAULT_EQUALS
lazy bool

When True, the memo suspends once it loses its last subscriber (and recomputes fresh if read again later). Non-lazy memos live for their owner's lifetime.

False
unobserved Callable[[], Any] | None

Optional callback fired when the memo loses its last subscriber; pair it with lazy=True for resource cleanup.

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 NotReadyError. The memo is then never "not ready": it doesn't register with Loading, doesn't report pending for its first run, and never holds a transition on mount. Use it for nice-to-have data (a recommendation panel, a badge count).

_MISSING
ssr_source SsrSource

Where an async memo resolves when the page is server-rendered. "server" (the default) resolves it on the server and hydrates the browser with that value; "hybrid" does the same, then always re-runs it quietly in the browser; "client" never runs it on the server, so it loads after hydration. See Server rendering.

'server'

Returns:

Type Description
Memo[Any]

A Memo accessor.

Example
doubled = create_memo(lambda: count() * 2)

async def load_user():
    uid = user_id()          # tracked: refetches when it changes
    return await fetch_json(f"/api/users/{uid}")

user = create_memo(load_user)
suggestions = create_memo(load_suggestions, loading_value=[])

create_optimistic

create_optimistic(source: Accessor[T]) -> tuple[Accessor[T], Setter[T]]
create_optimistic(source: Callable[[], T]) -> tuple[Accessor[T], Setter[T]]
create_optimistic(source: T) -> tuple[Accessor[T], Setter[T]]
create_optimistic(source: Any) -> tuple[Accessor[Any], Setter[Any]]

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 (getter, setter) pair like create_signal.

Example
likes = create_memo(fetch_like_count)          # async source
shown, set_shown = create_optimistic(likes)     # shadows it

@action
async def like():
    set_shown(lambda n: (n or 0) + 1)   # instant UI
    await api_like()
    await refresh(likes)                # real data lands; the override reverts

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

create_root(fn: Callable[[Callable[[], None]], T], *, detached: bool = False) -> T

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 dispose callable that tears the root down.

required
detached bool

Create an independent lifetime instead of joining the current owner.

False

Returns:

Type Description
T

Whatever fn returns.

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: identity fast path, then ==. Re-setting an equal value is a no-op.
  • False: always notify, even for equal values.
  • a callable (old, new) -> bool: skip notification when it returns True. Pass lambda a, b: a is b for identity-only semantics.
_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 WriteInScopeError. Reserve it for state that's genuinely local to that scope, such as a measurement a memo caches for itself.

False

Returns:

Type Description
Accessor[T]

A (getter, setter) tuple. The getter is an

Setter[T]

Accessor (call it to read, .peek() to

tuple[Accessor[T], Setter[T]]

read untracked); the setter is a Setter.

Example
count, set_count = create_signal(0)
set_count(5)
count()                     # 0: staged, not yet visible
flush()
count()                     # 5
set_count(lambda n: n + 1)  # functional update
count.peek()                # 5 (untracked read of the committed value)

doubled, _ = create_signal(lambda: count() * 2)   # derived form

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

flatten(children: Any) -> list[Any]

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.

Example
count, set_count = create_signal(0)
set_count(1)
count()   # 0: the write is staged
flush()
count()   # 1

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:

position = create_memo(lambda: from_source(watch_position))

source is one of:

  • a subscribe function, subscribe(next, error, complete), that returns an unsubscribe callable (or None);
  • an observable: an object with a subscribe(next, error, complete) method returning an unsubscribe callable or an object with unsubscribe() or dispose() (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_disposed

is_disposed(owner: Owner) -> bool

Return whether owner has been disposed.

is_equal

is_equal(a: Any, b: Any) -> bool

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

is_pending(fn: Callable[[], Any]) -> bool

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 action that hasn't settled);
  • an async computation whose recompute is in flight (a quiet refresh is 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.

html(t"<span>{'Refreshing...' if is_pending(user) else ''}</span>")
html(t"<button disabled={is_pending(lambda: state.todos)}>Save</button>")

is_server

is_server() -> bool

Return True while a server render is in progress.

Use it to choose a data source, or to skip browser-only work, in code that also runs in the browser:

async def load_user():
    if is_server():
        return database.users.get(user_id())
    return await fetch_json(f"/api/users/{user_id()}")

is_static

is_static(source: Any, key: str | None = None) -> bool

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).

@component
def Icon(name: str):
    if is_static(name):
        return html(t"<i class={untrack(lambda: name)}></i>")
    return html(t"<i class={name}></i>")

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 None if they never resolved) instead of raising NotReadyError.
  • 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(*sources: Any) -> Any

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.

Example
@component
def SaveButton(**rest: Any):
    attrs = merge({"type": "button"}, rest)
    return html(t"<button {attrs}>Save</button>")

omit

omit(source: Any, *keys: str | Callable[[str], bool]) -> Any

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:

@component
def Field(label: str, **rest: Any):
    attrs = omit(rest, lambda key: key.startswith("on_"))
    return html(t"<label>{label}<input {attrs}></label>")

on_cleanup

on_cleanup(fn: Callable[[], Any]) -> None

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 For row: runs when that region is re-evaluated or torn down.

Raises:

Type Description
RuntimeError

If called outside any reactive scope.

on_flush

on_flush(fn: Callable[[], Any]) -> None

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

on_settled(fn: Callable[[], Any]) -> None

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.

Example
@component
def Chart(data: list[float]):
    canvas = Ref()

    def start():
        handle = draw(canvas.current, data)
        return lambda: handle.destroy()

    on_settled(start)
    return html(t"<canvas ref={canvas}></canvas>")

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:

@component
def TagList(tags: list[str] = prop(default_factory=list)):
    ...

refresh

refresh(target: Any) -> Awaitable[Any]

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 Memo (including async memos and function-form signals) or a derived store / projection.

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

resolve(fn: Callable[[], T]) -> Awaitable[T]

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.

user = create_memo(fetch_user)
data = await resolve(user)

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.

from wybthon import resolve_children


@component
def Tabs(children: Children = None):
    tabs = resolve_children(lambda: children)
    return html(t"<nav>{[html(t'<li>{tab}</li>') for tab in tabs.to_array()]}</nav>")

run_with_owner

run_with_owner(owner: Owner | None, fn: Callable[[], T]) -> T

Run fn under owner (pass None for no ownership) and return its result.

until

until(pred: Callable[[], T], *, timeout: float | None = None) -> _Settle[T]

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 TimeoutError.

None
Example
@action
async def checkout(cart_id):
    order_id = await api_checkout(cart_id)
    refresh(orders)
    await until(lambda: any(o["id"] == order_id for o in orders()))
    navigate(f"/orders/{order_id}")

untrack

untrack(fn: Callable[[], T]) -> T
untrack() -> _Untracked
untrack(fn: Callable[[], Any] | None = None) -> Any

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, untrack() returns a context manager.

None

Returns:

Type Description
Any

Whatever fn returns.

hydrate

hydrate(vnode: Any, container: Element | str | int) -> Root

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 Element, a CSS selector, or a kernel node id.

required

Returns:

Type Description
Root

A Root, as from render.

Example
from wybthon import hydrate

hydrate(App(), "#app")

render

render(vnode: Any, container: Element | str | int) -> Root

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 Element, a CSS selector for an existing DOM node, or a kernel node id.

required

Returns:

Type Description
Root

A Root; call .dispose() to tear the app down.

Example
from wybthon import html, render

root = render(html(t"<h1>Hello, world!</h1>"), "#app")

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

http_header(name: str, value: str, *, append: bool = False) -> None

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 set-cookie, say).

False

http_status

http_status(code: int, text: str | None = None) -> None

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(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

html(template: Template) -> VNode

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, or on: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 as children.

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 <tr> directly inside <table>).

Example
html(t'<li class={"done" if done() else ""}>{title}</li>')

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.

@form_action
@server_function
async def log_in(form: FormData) -> None:
    user = await authenticate(form["email"], form["password"])
    set_cookie("session", user.session_token)
    raise redirect("/dashboard")

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

respond(value: Any = None, *, status: int = 200, headers: dict[str, str] | None = None, revalidate: str | list[str] | None = None) -> Respond

Return value with a status, headers, or the query keys this call changed.

revalidate="" (or []) marks a POST call that changed nothing, so the page's queries aren't refetched:

@server_function
async def log_search(term: str) -> None:
    analytics.record(term)
    return respond(revalidate="")

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]]
server_function(fn: Any = None, /, *, method: Method = 'POST') -> Any

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 async def to run on the server. It must be defined at a module's top level, so the browser and the server name it the same way.

None
method Method

"POST" (the default; a mutation that revalidates the page's queries when it completes) or "GET" (a read).

'POST'

Returns:

Type Description
Any

A ServerFunction with the same

Any

signature.

create_optimistic_store

create_optimistic_store(source: Callable[[], T], initial: Any = None) -> tuple[T, Callable[[Callable[[T], object] | T], None]]
create_optimistic_store(source: T, initial: None = None) -> tuple[T, Callable[[Callable[[T], object] | T], None]]
create_optimistic_store(source: Any, initial: Any = None) -> tuple[Any, Callable[[Any], None]]

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_projection

create_projection(fn: Callable[[T], object], initial: T) -> T
create_projection(fn: Callable[[], object], initial: None = None) -> Any
create_projection(fn: Callable[[], object], initial: T) -> T
create_projection(fn: Callable[..., Any], initial: Any = None) -> Any

Create a read-only derived store with memo readiness and refresh semantics.

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.

deep

deep(value: T) -> T

Return a detached snapshot, tracking changes only within this subtree.

reconcile

reconcile(data: T, key: str | Callable[[Any], Any] | None = 'id') -> _Reconcile[T]

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

snapshot(value: T) -> T

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.

See also