Due to the inevitable holiday season, I’ve spent some time burning the world’s electricity (using Cursor) to elaborate a pattern to use a LiveView implementation in Python: pyview. It uses the LiveView protocol for server-side and mixed web UIs I’ve mentioned before.
After elaborating the python library on a departures monitor I thought - why not demonstrate a live view for a Monty experiment - to not need any external services and also be able to control everything about the UI. One of the main ideas: no JS-side polling, complex single-page apps needed. Most logic is server-side python. Here’s a small screencast:

Do not mind the actual contents of the view - this could be anything, even specific to the experiment being run. One could even think of throwing just the HTML template and the python LiveView class for other experiments with some preparation. The intent is to pave the way to work around limitations with the learnings from Erlang/Elixir.
Additionally to the live view, several other patterns are tried, e.g. single shot scripts to set up/run stuff like the experiment itself or quality checks, supported by some dedicated python libraries and tools and custom wrappers. Also, since pyview required Python 3.11+, it had to be put into a separate process, thus the architecture.
I’ve put it into the ongoing WIP pull request just as a reference. I don’t think this should be merged as is. Alternatively, I can open a merge request on my fork. WIP: live web view for an experiment by d-led · Pull Request #677 · thousandbrainsproject/tbp.monty · GitHub
The learnings are: there’s more code to be written in Python than elixir for that task, and the safeties are not given, thus one has to implement them oneself.
This time I haven’t written the code myself but let the “code genie” do it for me, although, constraining it with a process and quality check scripts. Thus, pardon the uncanny quality. The demonstration is hopefully what is worth picking up, and, perhaps, a sketch of a message-driven architecture. As a next challenge I’ll try to see if I can reproduce that particular experiment with Elixir - likewise to check what could have come out of it.
A sketch of the approach:
flowchart LR
subgraph Users[" "]
User1("fa:fa-user User 1")
User2("fa:fa-user User 2")
end
subgraph LiveViewServer["`Live View (py 3.11)`"]
StateManager@{ shape: das, label: "ExperimentStateManager\n(ZMQ SUB)" }
LiveView1[LiveView 1] -- subscribed to --> StateManager
LiveView2[LiveView 2] -- subscribed to --> StateManager
end
subgraph MontyExperiment["Monty Experiment (py 3.8)"]
%% Sensors[Sensors] -- publishes via --> ZmqBroadcaster
%% LearningModules[Learning Modules] -- publishes via --> ZmqBroadcaster
%% ProgressLoggers[Progress Loggers] -- publishes via --> ZmqBroadcaster
Experiment[MontyExperimentWithLiveView] -- uses --> ZmqBroadcaster
ZmqBroadcaster@{ shape: das, label: "ZmqBroadcaster\n(ZMQ PUB)" }
end
ZmqBroadcaster -. ZMQ messages .-> StateManager
LiveView1 -- serves to --> User1
LiveView2 -- serves to --> User2
pyview has a python-internal pub/sub implementation, while the inter-process communication is done via zeromq. This is the approach I’ve seen work in many places, and have implemented various flavors of it.
Unless, broken (hopefully not), if the monty conda environment is set up, running scripts/setup.sh and scripts/run.sh in the contrib experiment repo should start the experiment and the live view which is accessible at port 8000.
The up to date description will be in README.md




