Server & App API

ww.serve()

ww.serve(host="0.0.0.0", port=6502, **kwargs)

Start the webwrench development server. This is a blocking call.

host : str
Bind address. Default "0.0.0.0".
port : int
Port number. Default 6502.
Protocol: webwrench uses the bwserve protocol — SSE (Server-Sent Events) for server-to-browser messages, HTTP POST for browser-to-server callbacks. No WebSocket required.

ww.App()

app = ww.App(transport="sse")

Create a multi-page application.

transport : str
Transport protocol. Default "sse".

app.page(path)

Decorator to register a page handler.

@app.page("/")
def home(ctx):
    ctx.title("Home")

app.serve()

app.serve(host="0.0.0.0", port=6502)

Start the app server. Same parameters as ww.serve().

PageContext

The ctx object passed to page handlers. Provides the same API as module-level functions:

CategoryMethods
Displaytitle, heading, text, markdown, code, image, divider, table, metric, json, progress
Widgetsbutton, input, slider, select, checkbox
Chartschart, plot
Actionsredirect, set_theme, screenshot, remove, patch
Statestate (attribute), compute, recompute

ctx.state

Per-session state object with attribute-style access:

ctx.state.counter = 0
ctx.state.counter += 1

ctx.redirect(url)

Navigate to a different page:

ctx.redirect("/dashboard")

ctx.compute(key, func) / ctx.recompute(key, func)

Memoized computation. compute caches; recompute forces recalculation.