client-side, "AJAX"-style interactivity is rather difficult. The
needed to make an application work consistently across multiple browsers,
all of which must be wrapped up inside HTML, makes for a jumble of issues
for the application developer. Pyjamas is
meant to ease that development, by allowing client-side applications to be
Pyjamas is a port of
the Google Web Toolkit (GWT), which
pioneered the technique, but GWT uses Java instead of Python.
For developers who prefer
provides an environment that almost completely insulates them from the
code that actually runs in the user's browser. As described on the home page:
You can write web applications in python - a readable programming language
unreadable for even medium-sized applications. Your application's design
can benefit from encapsulating high level concepts into classes and modules
(instead of trying to fit as much HTML as you can stand into one page); you
can reuse - and import - classes and modules.
Also, the AJAX library takes care of all the browser interoperability
issues on your behalf, leaving you free to focus on application development
instead of learning all the "usual" browser incompatibilities.
Essentially, a developer uses the pyjamas-supplied libraries that provide
user interface widgets and Document Object Model (DOM) control from Python.
This code is then combined with a library that implements various
HTML that can be loaded into a browser. The pyjs program
But, using pyjamas is not at all like "normal" web programming. As the
web site and FAQ are quick to point
framework, it is more akin to writing a desktop program that is translated
into web application. In fact, Pyjamas-Desktop allows the same
code that is developed for the web application to be run, unmodified, on the
desktop. The same Python source that gets fed into the translator can,
instead, be run, and, more importantly, debugged, on the developer's desktop.
The tool is best suited to writing one-page web applications that rely
entirely on AJAX techniques to do their job—things like Gmail,
Mozilla's Bespin, and many others. Each page load in a pyjamas application
includes code generated from the application as well as pyjamas libraries,
so, ideally, that would only be done once. That is quite a contrast from
the traditional, multi-page-oriented web application, but is certainly
in keeping with the direction of web interaction.
The key to understanding pyjamas is to note that, unlike AJAX frameworks,
it is not meant to add a bit of interactivity, or some desktop-like
features, to an existing web application. Instead, the entire application
is written in Python, likely debugged on the desktop, and then turned into
application code will look very familiar to Python GUI developers. For
World" program—which does a bit more than Kernighan and
Ritchie's original C program—looks like:
import pyjd # this is dummy in pyjs.
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Button import Button
from pyjamas.ui.HTML import HTML
from pyjamas.ui.Label import Label
from pyjamas import Window
print "greet button"
if __name__ == '__main__':
b = Button("Click me", greet, StyleName='teststyle')
h = HTML("<b>Hello World</b> (html)", StyleName='teststyle')
l = Label("Hello World (label)", StyleName='teststyle')
base = HTML("Hello from %s" % pygwt.getModuleBaseURL(),
Running the build.sh script on that example, as described on the
"getting started" page,
creates output and public directories that hold the
generated code. There is a tiny bit of HTML and CSS, along with roughly
likely boilerplate code to implement pyjamas itself. A
better example might be something like TimeSheet,
which implements a more realistic application, and weighs in around 23,500
There are numerous examples on
the pyjamas web page, many of which were ported from GWT. Both the source
code and the running application are available, so one can get a sense for
how much code it takes to create the examples—as well as use them as
templates for other applications. There is quite a bit of documentation,
though the FAQ would indicate that there have been complaints about that, on
the site as well, including the in-progress Pyjamas Book (which
is implemented as a pyjamas book reader application).
The project has just released
version 0.6 of the tool, with many new features outlined in the CHANGELOG. There are some 140
changes from the version 0.5, including a rework of pyjs to make
more Python features available (multiple inheritance and superclasses are
specifically mentioned) and bringing Pyjamas-Desktop into the standard
distribution. The pace of development is relatively quick; 0.5 was
released in March, and 0.6 adds quite a bit of functionality on top of that.
Pyjamas is definitely worth a look for anyone considering building a
new-style web application, and who would rather use Python than Java.
Because GWT was released as free software, Pyjamas could leverage much of
that work to give developers another language choice. Writing—and
any tools that make that easier should be quite welcome. Those that just want a
bit more interactivity in their existing web applications, though, might
find the Pyjamas (and GWT) approach to be too heavy-handed for their needs.
to post comments)