Script Mode
Script mode is the simplest way to build a webwrench app. Write a flat Python script, call module-level functions, and serve.
How It Works
When you call ww.title(), ww.text(), or any display function, webwrench appends elements to a default page. When you call ww.serve(), that page is served to the browser.
import webwrench as ww
ww.title("My App")
ww.text("Hello from script mode!")
ww.serve()
Adding Display Elements
Elements are rendered in the order you add them:
import webwrench as ww
ww.title("Report")
ww.heading("Section 1", level=2)
ww.text("Some content here.")
ww.divider()
ww.markdown("**Bold** and *italic* text")
ww.code("print('hello')", lang="python")
ww.serve()
Widgets and Callbacks
Widgets return a WidgetHandle. Use .on_change to register a callback:
import webwrench as ww
ww.title("Counter")
display = ww.text("Count: 0")
btn = ww.button("Increment")
count = 0
@btn.on_click
def clicked():
global count
count += 1
display.update(f"Count: {count}")
ww.serve()
Tip: Widget handles have a
.value property that holds the current value. Use .update(new_value) to change a display element.
Charts with Interactivity
import webwrench as ww
data = [10, 20, 30, 40]
chart = ww.chart(data, type="bar", labels=["Q1", "Q2", "Q3", "Q4"])
slider = ww.slider("Multiply", min=1, max=5, value=1)
@slider.on_change
def scale(value):
chart.update([d * value for d in data])
ww.serve()
When to Use Script Mode
- Quick prototypes and demos
- Single-page dashboards
- Static reports (with
ww.export()) - Teaching and tutorials
For multi-page apps with routing and per-session state, see App Mode.