Jython is coming to the rescue. Since September 26th 2009, Jython2.5.1 has been released and can be use to create servlet that runs inside apache tomcat application server. Jython allows you to write python that is running on java VM (100%) and let you use lot of python pure libraries and let you use all java packages with a python synthax.
If you try it, you might have issues like:
- How can I create a simple jython2.5.1 servlet? (not deprecated jython2.2.1 that doesn't allow you to use most pure python libs)
- Why do I get ImportError when I use standard python package? How can I fix it?
- Where should I put jython2.5.1.jar?
- Where should I put my python code?
- Where can I get a basic example that is working?
- Where should I put my pure python libraries?
Here are the steps you should follow:
- get tomcat http://tomcat.apache.org/ (I used 5.5.28)
- get jython2.5.1 http://sourceforge.net/projects/jython/files/jython/jython_installer-2.5.1.jar
- cp ~/jython2.5.1/Lib tomcat5.5.28/share/lib (required to used std python libs)
- cp ~/jython2.5.1/jython.jar tomcat5.5.28/share/
- download example: wget http://mlboost.svn.sourceforge.net/viewvc/mlboost/jython/HelloWorld/HelloWorld.war
- cp HelloWorld.war tomcat/webapps
- download java jdk
- export JAVA_HOME=sun-jdk-1.6.0_02
- try it: http://localhost:8080/HelloWorld/HelloWorld.py
PS: a war file is a zipped file, you can unzip it in tomcat/webapps for testing so you don't need to rezip it and restart the server. When you are done, simply do a jar cvf HelloWorld.war * in the tomcat/webapps folder and ship that single file to the client tomcat server (make sure jython is installed). If you want to add pure python libraries, you can simply add them into your war file, it will work.
Here is the time comparison of the same service:
- python: wsgi httpserver
- jython: wsgi httpserver
- tomcat: java servlet jython2.5.1