[Baypiggies] The skinny on Pyjamas

Glen Jarvis glen at glenjarvis.com
Fri Aug 13 18:58:28 CEST 2010

As posted by James, here's the quick skinny on pyjamas if you never heard of it.

As a pyjamas user, I thought I'd chime in. I have been using pyjamas for about a year and a half. It is a breath of fresh air for developing web front ends. My front ends tend to be very application-like, with lots of data-driven widgets. The widget set in pyjamas is very basic, but it is very easy to create new widgets that do exactly what the application needs. This is IMHO where pyjamas particularly shines; if you need a UI widget that is not provided, you just create it. In python.

Additionally, if you need some code that works identically on the front end and the back end, it is just a matter of importing it (in python) on both sides. For example, I wanted rc4 encryption for an app (don't ask!). It was a quick hack from the Wikipedia pseudocode to make a module in python. Then, I imported that module into my pyjamas code, and I imported exactly the same module into my back-end code. It worked flawlessly.

I would be remiss if I did not mention that PureMVC also works in pyjamas. While there is some effort needed to get through the jargon, the event system and component code separation you get with PureMVC are worth the effort if you are doing anything complex.

The minimum back end for a data-driven app in pyjamas only needs to serve static files (your compiled pyjamas app), together with a JSON-RPC listener, which can be in any language, and can be installed in most frameworks. A JSON-RPC call in pyjamas (once set up) looks a lot like a function call. You have to use an async methodology, but that has its blessings as well.

I see that you worry that pyjamas is not ready for prime-time yet. It is true that pyjamas has a rather small following, and an even smaller advertising budget. There is no big corporation backing pyjamas. However, Luke Leighton is managing the project probably as well as an open source project can be. Test coverage is very good, particularly for the python-to-javascript translator. The python implementation is fairly complete; do you really need "eval" and "exec"? Actually, those may be available down the pike. In general, if you write something that does not work, it will be a flaw in your code, not the framework. Fortunately, you can recompile with a "debug" flag, and it will give you a good hint of where you went wrong. If that is not good enough, the mailing list is quite responsive, if you do not expect too much hand-holding.

Pyjamas compiles separate code for each of the major web browsers; it started as a python port of GWT in (fluffy) java. The GWT documentation still applies in most cases, though in practice I tend to keep a gedit window open with several pyjamas UI modules for reference. The source for any widget tends to be small and readable.

Widget styling uses CSS, which alleviates one major headache in UI design. You can addStyleName or removeStylename for any widget anytime you want, and the web browser just obeys.

The generated javascript files are pretty big, but if you enable compression in the web server, load time can be acceptable even on dial-up. Since pyjamas will make you think in a data-driven way, popular pages could easily be done with standard templates from your back end framework, and you could reserve your pyjamas pages for your users that need a truly interactive experience. It is not an either-or decision here. With CSS, this can be seamless.

I have only touched on the major things I love about pyjamas. There is more. The main advice is: don't be afraid to try pyjamas; you'll be happy you did. Use the version in the svn/git repository; it is the most up-to-date (small crowd: not very frequent releases). You already know python. Dive into the source at pyjamas/library/pyjamas/ui for the widgets. Play with and build the examples at pyjamas/examples. It's more mature than you think. 
Posted by James Washington
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100813/26dce340/attachment.html>

More information about the Baypiggies mailing list