Python in the Browser: Pyjs
Today I’m taking a look at the first contender: Pyjs.
What is it, exactly
From the Pyjs website:
Recent pyjs releases are 0.8.1a (May 2012) and 0.8 (June 2011). Activity on github has been basically falling off since then, so it seems that it may be reaching the end of its life.
Pyjs is licenced under the Apache Licence v2.0, which is a free software licence compatible with the GPL v3.
I like to use my system package manager to install software. Pyjs isn’t available there, and pyjs recommends installing via pip. Installation should be easy – the instructions make it appear that way – but I haven’t tried that yet. I balked at a few other things in pyjs first.
The examples are not compelling.
My first complaint is that the page loads, and then there is a pause (of a few seconds!) before content is rendered. That’s completely unacceptable in 2015. How slow would it be on a mobile device? The answer, using my phone, is: about the same. Once things get going, response is OK though.
My next complaint is that the “Controls” example doesn’t work properly on my phone, and the “Canvas Processing” example fails on both mobile and desktop with an error message.
The pyjs examples I looked at are also ugly. That’s probably because the CSS hasn’t been set up to make it attractive, but I’m not sure.
The main fail I give to pyjs though, is that every program is an AJAX program – i.e. it requires round-trips to the server. This is not what I want. Programs should be self-contained on the client’s browser as much as possible, to improve responsiveness and decrease server load.
Pyjs is going to take some learning due to the fact that it provides its own widget toolkit That said, the “hello world” is not that fearsome.
from pyjamas import Window from pyjamas.ui import RootPanel, Button def greet(sender): Window.alert("Hello, AJAX!") class Hello: def onModuleLoad(self): b = Button("Click me", greet) RootPanel().add(b)
This is actually easier than gtk or Qt.
Coverage of the Python standard library
Pyjs claims almost complete coverage of Python 2.5/2.6. It’s important to notice that this covers the Python language, and not the Python standard library. I have found no indication that any of the standard library is included at all.
Nothing in the pyjs examples inspires much confidence in the ability to do graphics required for simple games. Minesweeper comes closest though. Asteroids might be able to show something, if it actually worked at all.
Pyjs appears to be a poor fit for my requirements. It absolutely requires AJAX interactions between browser and server, doesn’t appear to support the Python standard library, and the examples are ugly and sometimes broken.
Posted Monday, February 23, 2015