Jython on Django
-
Upload
fwierzbicki -
Category
Documents
-
view
3.117 -
download
2
description
Transcript of Jython on Django
![Page 1: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/1.jpg)
Django on JythonFrank Wierzbicki
![Page 2: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/2.jpg)
Who am I?
• Frank Wierzbicki
• Project lead for Jython
• I work at Sun (Oracle?) on Jython fulltime
![Page 3: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/3.jpg)
What is Jython?
• Python that runs on the JVM
• Compiled to Java bytecodes instead of Python bytecodes
• Call Java code seamlessly from Python code
![Page 4: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/4.jpg)
Jython Status
• Current prod version 2.2 is not useful for Django
• Jython 2.5 beta4 is out
• First RC as early as this Friday
• So production release real-soon-now
![Page 5: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/5.jpg)
Modjy
• Modjy implements WSGI for Jython
• Acts as a bridge to Java Servlets
• integrated into Jython’s core
• This is a big part of how we get Django working.
![Page 6: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/6.jpg)
zxJDBC
• zxJDBC implements DB-API
• integrated into Jython’s core
• Another crucial piece to get Django working.
![Page 7: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/7.jpg)
Jython on Django Status
• Works well with Django 1.0.3 and postgresql
• Other databases in progress: MySQL, Oracle, SQLite, MS SqlServer
• Django 1.1 has some refactorings that Jython will need to catch up on...
![Page 8: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/8.jpg)
Why Jython?
• Massive amounts of Java code out there
• Some really useful Java libs
• Great JVM ecosystem
• Internal Java apps that are not yet exposed to the web
![Page 9: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/9.jpg)
What can I use?
• setuptools
• ez_install
• virtualenv
• pip
• many more pure Python tools
![Page 10: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/10.jpg)
What can’t I use yet?
• c-extensions
• PIL
• ctypes (but we’re working on this one!)
• iPython (working on this too!)
![Page 11: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/11.jpg)
Configure Jython
• Get ez_setup.py
• run “jython ez_setup.py”
• In Jython’s bin directory will be an ez_install that runs from Jython
![Page 12: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/12.jpg)
Installing Django on Jython
• Get 1.0.3+ Django - run “jython setup.py install”
• From http://django-jython.googlecode.com get django-jython-1.0b1.tar.gz, untar it and run “jython setup.py install”
• see the django-jython project on googlecode.com for more detail
![Page 13: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/13.jpg)
Java Platform
• Now takes advantage of Java 5 libraries
• Java 5 concurrency libs: No GIL!
• Use a choice of Java garbage collectors
• Use Java native threads
• -J flag namespace for JVM config
![Page 14: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/14.jpg)
Java Integration
• Jython integrates well with Java
• Java classes and interfaces can be subclassed from Jython
• These subclasses are now “new style” classes.
![Page 15: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/15.jpg)
Example: The Java lib poi can read Excel
![Page 16: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/16.jpg)
![Page 17: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/17.jpg)
Deployment
• run “jython manage.py war --include-java-libs=jdbcdriver.jar”
• This will produce a “war file”
• Copy this war file to the auto-deploy directory for most application servers (like GlassFish)
![Page 18: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/18.jpg)
war format for doj
|-- WEB-INF| |-- lib| `-- lib-python| |-- Lib| |-- django| |-- doj| `-- mysite`-- media
![Page 19: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/19.jpg)
Why Django on Jython?
• Lots of ops departments out there that want to deploy to Java App Servers - “give us a war file”
• They have lots of tools for monitoring, etc
• Jython has a good story for threading and performance - and it’s getting better.
![Page 20: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/20.jpg)
Da Vinci Machine
• JVM gets friendlier to dynamic languages
• On the project plan for JDK 7 -- some of it has already there in a hidden state for JDK6
• Method Handles, Invokedynamic, etc
• Hotspot is one of the world’s best tuned VMs - about to be tuned better for us!
![Page 21: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/21.jpg)
Jython Book due in 2009 from Apress
• Josh Juneau
• Jim Baker
• Leo Soto
• Victor NG
• Frank Wierzbicki
![Page 22: Jython on Django](https://reader036.fdocuments.net/reader036/viewer/2022062513/55632b04d8b42a5c7b8b47c2/html5/thumbnails/22.jpg)
Where to Find Out More
• http://www.jython.org
• http://wiki.python.org/jython
• http://fwierzbicki.blogspot.com
• Twitter: fwierzbicki
• http://www.netbeans.org/features/python/
• https://glassfish.dev.java.net/