Like GWT, Pyjamas translates a Python application and libraries (including UI widgets and DOM classes) into a Javascript application and libraries, and packages it all up:
.html
and .js
files that can be served up by a Web server.The omnipresent hello world example, let's call it 'Hello Pyjamas':
from pyjamas.ui.RootPanel import RootPanel from pyjamas.ui.Label import Label l = Label('Hello Pyjamas') RootPanel().add(l)
Now run pyjsbuild hello.py
to generate a plain Javascript
application: pyjs creates an ./output
folder containing all files
you need to move to your webspace later. Of course you can test locally,
too.
Add 3 additional lines in total and your application can run with both Pyjamas (i.e. plain Javascript) and Pyjamas Desktop:
import pyjd # this is dummy in pyjs from pyjamas.ui.RootPanel import RootPanel from pyjamas.ui.Label import Label pyjd.setup('public/hello.html') l = Label('Hello Pyjamas') RootPanel().add(l) pyjd.run()
Execute pyjd hello.py
, or python hello.py
, to run
the very same application native on Python, giving you a Python stack trace on
errors. Pyjamas Desktop gives you much more control making testing and debugging
a piece of a cake. No more web development pain – hooray!
Note the hello.html
file referenced above: this is a container
for your application generated by Pyjamas (pyjs) that you can adjust to your
needs.
Ready for more? Let's get started!