Jython on Google AppEngine: Why bother?
Why on earth would you want to run jython applications on Google Appengine?
First off, I must apologise for the flippant nature of the attention grabbing title. I’m a jython committer, and a jython user, so I believe that there are very good reasons for running jython on Google AppEngine. (You can read how to do so on the modjy wiki: how to run jython applications on Google AppEngine).
The title is essentially a paraphrase of a statement made by a Google AppEngine Evangelist, at a talk about AppEngine that I attended here in Dublin. The speaker was of the opinion that there was no valid reason for running jython on AppEngine, a statement which I couldn’t let pass.
I think that the core of his reasoning for making that statement was a simple misunderstanding, but a misunderstanding that is common among users who are familiar with python, or users of cpython, but who are not familiar with jython’s use as a JVM scripting language. The misunderstanding is that the only reason for running jython is so that one can run python applications on the JVM, using python’s wealth of "batteries included" APIs. If that is the case, then why bother running jython, when one can simply use the cpython support on AppEngine directly?
To explain, when writing a cpython application that processes email, for example, one can make use of the python’s email module, which provides a wealth of features for dealing with the many complexities of parsing, processing and generating email messages, MIME, etc. Users of jython can also use the python email modules, since those modules are written in pure python. But since jython runs on the Java Virtual Machine(JVM) and permits seamless integration of java and python code, jython users writing email processing also have the option of using the excellent JavaMail APIs, which are just as robust as the pure python modules, and arguably more efficient. So jython users have the best of both worlds: they can use either python APIs or java APIs, with equal ease.
Processing email is perhaps too straightforward an example, in that both python and java have excellent email processing support. But due to the more widespread use of java in the development community in general, java generally has far more support for any given technology need, since there are often multiple options available. A good example of this is cryptography: there is a wealth of java cryptography libraries available, including the excellent Bouncy Castle, Cryptix, Flexiprovider, etc. The choice of crypto libraries in python is generally narrower, supports less functionality, and is sometimes abandon-ware.
So if one’s understanding of jython is simply that it is a way to run pure python modules on the JVM, then the above mentioned mis-understanding is forgivable. But it is simply not the case that the primary usage of jython is to run pure python modules: Jython excels as a dynamic/scripting language for the JVM, and permits the use of java APIs, without having to write java code.
In discussion with the Google engineer after the talk, he conceded that there was one possible use case for running jython on AppEngine, namely that of prototyping java applications. In this scenario, applications would
- Be developed in jython, taking advantage of the enormous productivity increases gained by developing in python
- Be translated to java once the functionality of the application is complete
My reply to this is: “Why bother with step 2″?
If you’ve got a running application that is fully functional and written in jython, then you don’t need to translate it to java. You should only consider translating it, or parts of it, into java if you really have to. For example, after profiling your jython application, you may find one or two core pieces that are performance bottlenecks: these are prime candidates for translation to java, to improve performance. But there’s no reason to translate the rest of the application: maintainability and productivity is best served by simply leaving the jython code exactly as is.
I suppose a part of the reason why this mis-perception of jython has come about is because python is such an excellent language that it is in the unique position of having two completely independent implementations of the language that run on Google AppEngine. But just because both cpython and jython run on AppEngine doesn’t mean that their usages should be identical. Jython’s place in the AppEngine ecosystem is primarily as a JVM dynamic language.
So, in summary, jython is more than just a mechanism for running pure python code on the JVM: it is an excellent JVM development platform in it’s own right.
I hope I’ve given you some good reasons to consider developing your next Google AppEngine project on jython.
[...] First Tweet: 6 minutes ago xhaus Alan Kennedy New blog post: Jython on Google AppEngine: Why bother retweet [...]
Twitter Trackbacks for Jython on Google AppEngine: Why bother? at Jython Journeys [xhaus.com] on Topsy.com
30 Nov 09 at 2:47 pm
Hi Alan,
I think you’re misconstruing my comments at the event. While I can’t recall how I phrased it exactly, the gist of what I intended to say was that while it was possible to run Jython on App Engine, I couldn’t think why you’d want to. I didn’t mean to imply that I was certain it wasn’t ever useful.
The use-case I described after the talk was one I’d encountered where a user wanted to port his Python app to Java (or vice-versa) progressively, without interrupting service – not a case of prototyping, but rather migration.
I also think your example of cryptography libraries for library support is perhaps not the best one: It’s especially important in cryptography not to have a profusion of libraries, but rather to have at least one really good one. KeyCzar (http://www.keyczar.org/) is, in my opinion at least, an example of such a library – and it’s available natively for both Python and Java.
Please don’t take these corrections as criticism of the concept of Jython on App Engine, though. I love to see novel uses of App Engine and of programming languages in general. I’m sure an article on how to write a basic webapp in Jython on App Engine would be very well received – as would further practical examples of using the two together.
Nick Johnson
30 Nov 09 at 3:26 pm
[Nick]
> I’m sure an article on how to write a basic webapp in Jython
> on App Engine would be very well received – as would further
> practical examples of using the two together.
Challenge accepted: See my latest post, which explains how jython can do something on Google AppEngine that cpython cannot do: XSLT transforms.
Transforming with XSLT on Google AppEngine and jython.
http://jython.xhaus.com/transforming-with-xslt-on-google-appengine-and-jython/
I’m looking forward to seeing anyone doing the same with cpython on AppEngine
alan.kennedy
1 Dec 09 at 6:57 pm
I came across this post as I was searching about jython on appengine. The reason I was looking is that I have come across a Clojure bot for google wave (http://markfayngersh.com/post/333326632/clojure-bot-is-a-google-wave-robot-that-evaluates) hosted in appengine. And as far as I can see, this is not possible in CPython but it would probably be possible in Jython.
In short, any cases which need a sandbox would prefer jython.
Muhammad Alkarouri
14 Jan 10 at 3:23 pm