Communication between Java and Python


Table of contents

Communication through bindings

Java's JNI promises the ability to bind Java to C and C++, and allows calls from C-to-Java and vice-versa. Sun maintains a fairly good tutorial ( that provides the basic understanding of how to utilize the bindings. Using Python bindings and JNI together will provide Python-to-C-to-Java functionallity (and vice-versa). This looks like a promising route. Some of the packages listed below (at least JPE and JPI) were developed using JNI.

  • JPI ( is a two-way Python-Java Interface. It is no longer being developed, and may take some effort to get working with the latest version of Python. JPI uses a reimplimentation of the Python interpreter, and thus suffers from some slight descrepancies between it's version of Python and the standard version of Python.
  • JPE ( (Java-Python Extension) uses JNI to provide a bridging mechanism between Java and a Python interpreter (including use of C extensions for Python). A colleague of ours, Michael Sanner, was one of the JPE developers when active development ceased in mid 2002. JPE seems to have a better, more generic implimentation than JPI, but again looks like it will take some effort to update JPE to Python2.4 and get it working. However, this is a fairly straightforward option, and should be fairly easy to enable. The source code is a bit hard to locate on the webpage; it accessable from the JPE cvs repository ( on sourceforge.

Communication through Virtual Machines

JPype ( is an effort to allow python programs full access to java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both Virtual Machines. This effort can easily be used to call native java from python, and development is ongoing for calling existing java classes from python.

Reimplementation of Python

Jython ( provides Python implemented for the Java Virtual Machine, and as such can't directly make use of Python extensions written in C. Jython is designed for this task and most Python scripts should run with little or no modification on Jython. The exception is scripts that use C extensions that have not be converted. Jython is also only at 2.1 at the moment, so 2.2 and later features will not work. A 2.2/2.3 release is supposed to happen sometime in late 2004. The inability to use Python extenstions written in C severly the versatility of this package.

Client-server communication

It is possible to wrap Python libraries in a wrapper like XML-RPC and run it as a server. Similarly, one could use a CORBA orb, or SOAP, or even COM. These all work in essentially the same way, with Python running as a separate process and exposing the functionality to client programs that could be written in any language. This seems to provide robust interconnectivity to any language, however it also seems bulky and complex. Some of the packages listed below (SPIRO and Pyro) use orb technology.

SPIRO ( or Pyro ( use ORB (Object-Request Broker) technology that is similar to Java's RMI (Remote Method Invocation), and is a lot like RPC. SPIRO seems to be nice in that it bridges the gap between Python and Jython, thus allowing communication between Python and Java. SPIRO is a fairly new package, and may also be a promising route. As a side note, Sun also maintains a good tutorial for Java's RMI (

Personal tools
Document Uploads/Links