Server-Side Events
PyWire allows you to handle standard browser events (like clicks, inputs, and form submissions) directly in Python.
Basic Event Handling
Section titled “Basic Event Handling”Use the @ prefix followed by the event name to bind a Python function to a browser event.
---count = wire(0)
def handle_click(): count.value += 1---<button @click={handle_click}> Clicked {count} times</button>Passing Data
Section titled “Passing Data”You can pass data from the browser to your Python handlers.
---items = wire([{"id": 1, "name": "Item 1"}, {"id": 2, "name": "Item 2"}])
def delete_item(item_id): items.value = [i for i in items if i['id'] != item_id]---<ul> <li $for={item in items}> {item['name']} <button @click={delete_item(item['id'])}>Delete</button> </li></ul>Input Events
Section titled “Input Events”For input fields, you can use @input or @change.
---search_query = wire("")
def on_search(value): search_query.value = value print(f"Searching for: {value}")---<input type="text" placeholder="Search..." @input={on_search(event.value)}>PyWire automatically provides the event context variable (alias $event) in inline handlers. Alternatively, if you bind the function directly (e.g., @input={on_search}), PyWire will inspect your function signature and automatically pass arguments named value, event, id, etc.
We’ll cover more advanced event features in the Event Modifiers section.