Reading and writing Python attributes
JS → PY
Axon.Xxx.name in JS is not a plain property access — it is a cross-process read. So reads need await, writes do not wait.
Python side: just an attribute
python
# controller.py
from axon import AxonController
@AxonController("MainView")
class DemoController:
counter: int = 0 # class or instance attribute, both work
def get_counter(self) -> int:
return self.counterJS side: await the read, assign the write
js
import { Axon, AxonInit } from "axon-gui";
await AxonInit();
// read: one round trip, so it must be awaited
const before = await Axon.DemoController.counter; // 0
// write: send and forget, no waiting for Python
Axon.DemoController.counter = 42;
// read again after a moment to confirm Python really changed
const after = await Axon.DemoController.get_counter(); // 42Why reading is asynchronous
Axon.DemoController.counter gives you a "value will arrive later" object in JS: the framework has to send the request to Python and wait for the current value.
console.log(Axon.DemoController.counter)shows an object, not the value;await Axon.DemoController.countergives you the actual number.
When a write takes effect
A write returns as soon as it is sent. It reaches Python in the same order as any later calls, so the usual pattern is:
js
Axon.DemoController.counter = 42;
const now = await Axon.DemoController.get_counter(); // always 42If you need proof the write succeeded (say Python might reject it), call an explicit method and treat its return value as the receipt.
Key points
- The attribute must exist: reading a name that Python does not have fails.
- JSON types only: numbers, strings, booleans,
None, arrays, objects. - Do not do heavy work in attributes:
@propertyruns on a worker thread; slow logic belongs in a method (ideallyasync). - Attributes are for state; when you need parameters or a structured return, a method is clearer.