Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Be more informative and less spammy
Source Link
iamsrp-deshaw

[ Disclaimer: I am the primary maintainer of PJRmi ]

Similar to JPype, PJRmi is one of the libraries which provides support for calling into Python; there are others listed in the Other Work section of the README.are:

  • py4j allows Python to call into Java. It also supports Java calling back into Python so that Python clients can implement Java interfaces. It works by communicating over a socket.

  • jpy is another in-process implementation. One of its key features is support for fast pass-by-value operations with arrays by use of pointer hand-off.

  • jpype is another in-process implementation. Since it also uses internal C-based handoff it's highly performant.

  • PyJNIus is another implementation which accesses Java classes using JNI.

A simple example of calling into Java from Python, where the Java process is long-lived, would look like:

>>> import pjrmi
>>> c = pjrmi.connect_to_child_jvm()
>>> HashMap = c.javaclass.java.util.HashMap
>>> m = HashMap(dict((str(i), i+1) for i in range(5)))
>>> m.get("3")
4

More detailed examplesWhich one of use can be found in the notebook invarious versions of the git repositoryPython/Java bridges you like depends upon your use-case. It also supports tightOnes which use direct JNI for hand-off numpy integration, via the Hypercube package; again(like JPype) tend to be very fast but might limit you to a notebook gives examples of thissingle Java instance per invocation.

[ Disclaimer: I am the primary maintainer of PJRmi ]

Similar to JPype, PJRmi is one of the libraries which provides support for calling into Python; there are others listed in the Other Work section of the README.

A simple example of calling into Java from Python would look like:

>>> import pjrmi
>>> c = pjrmi.connect_to_child_jvm()
>>> HashMap = c.javaclass.java.util.HashMap
>>> m = HashMap(dict((str(i), i+1) for i in range(5)))
>>> m.get("3")
4

More detailed examples of use can be found in the notebook in the git repository. It also supports tight numpy integration, via the Hypercube package; again a notebook gives examples of this.

[ Disclaimer: I am the primary maintainer of PJRmi ]

PJRmi is one of the libraries which provides support for calling into Python; others are:

  • py4j allows Python to call into Java. It also supports Java calling back into Python so that Python clients can implement Java interfaces. It works by communicating over a socket.

  • jpy is another in-process implementation. One of its key features is support for fast pass-by-value operations with arrays by use of pointer hand-off.

  • jpype is another in-process implementation. Since it also uses internal C-based handoff it's highly performant.

  • PyJNIus is another implementation which accesses Java classes using JNI.

A simple example of calling into Java from Python, where the Java process is long-lived, would look like:

>>> import pjrmi
>>> c = pjrmi.connect_to_child_jvm()
>>> HashMap = c.javaclass.java.util.HashMap
>>> m = HashMap(dict((str(i), i+1) for i in range(5)))
>>> m.get("3")
4

Which one of the various versions of the Python/Java bridges you like depends upon your use-case. Ones which use direct JNI for hand-off (like JPype) tend to be very fast but might limit you to a single Java instance per invocation.

Source Link
iamsrp-deshaw

[ Disclaimer: I am the primary maintainer of PJRmi ]

Similar to JPype, PJRmi is one of the libraries which provides support for calling into Python; there are others listed in the Other Work section of the README.

A simple example of calling into Java from Python would look like:

>>> import pjrmi
>>> c = pjrmi.connect_to_child_jvm()
>>> HashMap = c.javaclass.java.util.HashMap
>>> m = HashMap(dict((str(i), i+1) for i in range(5)))
>>> m.get("3")
4

More detailed examples of use can be found in the notebook in the git repository. It also supports tight numpy integration, via the Hypercube package; again a notebook gives examples of this.

default