🌐
GitHub
github.com › mohdzain98 › JavaPython-Integration
GitHub - mohdzain98/JavaPython-Integration: Running python code inside java · GitHub
Running python code inside java. Contribute to mohdzain98/JavaPython-Integration development by creating an account on GitHub.
Author   mohdzain98
Java implementation of the Python interpreter
Jython Logo
Jython, named JPython until 1999, is an implementation of the programming language Python designed to run on the Java virtual machine of the Java platform. It is free and open-source software released … Wikipedia
Factsheet
Family JVM-hosted
First appeared January 17, 2001; 25 years ago (2001-01-17)
Stable release 2.7.4
/ 18 August 2024; 22 months ago (18 August 2024)
Factsheet
Family JVM-hosted
First appeared January 17, 2001; 25 years ago (2001-01-17)
Stable release 2.7.4
/ 18 August 2024; 22 months ago (18 August 2024)
🌐
Jython
jython.org
Home | Jython
There is work towards a Python 3 in the project’s GitHub repository. Jython implementations are freely available for both commercial and non-commercial use. They are distributed with source code under the PSF License v2. Jython is complementary to Java and is especially suited for the following tasks:
Discussions

Best way to combine Python and Java?
I've used JPype for a while. It also starts a JVM from python. Once set up, interoperating with Java is transparent. You can start the JVM in such a way that it can be debugged directly using remote debugging tools. More on reddit.com
🌐 r/java
82
60
October 29, 2022
Where to start with learning how to use API's?
And if you have a suggestion as to an easier API I could learn to use as my first one then that would be awesome too! Google Maps API is very easy. I recommend starting with the with the distance calculator web service API , then try experimenting with some of the JavaScript and Android APIs if you're feeling adventurous. More on reddit.com
🌐 r/learnprogramming
62
397
October 12, 2016
HackerRank - Array Pairs Problem Help
Note that you don't need to print the actual pairs - you can alter the array to optimize. You should be able to find the maximum element of the array in a single pass (O(n)). Then, for each element, you want to check with how many elements after it it would give a product of less than or equal that amount with. However, looking through all cases would result in O(n2) complexity, which is just slightly too much. Now, consider you reorder the array such that the smaller elements are at the front and the larger ones at the end - now, you can find the largest number such that when multiplied by the current one, it yields a number less than or equal to the maximum (note that a special case is needed for 0). If you reordered the array, you could then search for the position up to which all the elements are less than or equal to the maximum factor (using binary search) - that would be O(log n) per element or O(n log n) in total, which should fit nicely in the given bounds. (All the elements before that position should give a product less than or equal to the maximum, while all the ones after should give a product larger than the maximum). More on reddit.com
🌐 r/learnprogramming
3
1
March 11, 2020
Coming from Java to Python

You're going to have to unlearn a whole bunch of bullshit boilerplate.

More on reddit.com
🌐 r/learnpython
17
10
December 7, 2018
Top answer
1 of 12
38

Why not use Jython? The only downside I can immediately think of is if your library uses CPython native extensions.

EDIT: If you can use Jython now but think you may have problems with a later version of the library, I suggest you try to isolate the library from your app (e.g. some sort of adapter interface). Go with the simplest thing that works for the moment, then consider JNI/CPython/etc if and when you ever need to. There's little to be gained by going the (painful) JNI route unless you really have to.

2 of 12
21

Frankly most ways to somehow run Python directly from within JVM don't work. They are either not-quite-compatible (new release of your third party library can use python 2.6 features and will not work with Jython 2.5) or hacky (it will break with cryptic JVM stacktrace not really leading to solution).

My preferred way to integrate the two would use RPC. XML RPC is not a bad choice here, if you have moderate amounts of data. It is pretty well supported — Python has it in its standard library. Java libraries are also easy to find. Now depending on your setup either Java or Python part would be a server accepting connection from other language.

A less popular but worth considering alternative way to do RPCs is Google protobuffers, which have 2/3 of support for nice rpc. You just need to provide your transport layer. Not that much work and the convenience of writing is reasonable.

Another option is to write a C wrapper around that pieces of Python functionality that you need to expose to Java and use it via JVM native plugins. You can ease the pain by going with SWIG SWIG.

Essentially in your case it works like that:

  1. Create a SWIG interface for all method calls from Java to C++.
  2. Create C/C++ code that will receive your calls and internally call python interpreter with right params.
  3. Convert response you get from python and send it via swig back to your Java code.

This solution is fairly complex, a bit of an overkill in most cases. Still it is worth doing if you (for some reason) cannot afford RPCs. RPC still would be my preferred choice, though.

🌐
GitHub
github.com › ninia › jep
GitHub - ninia/jep: Embed Python in Java · GitHub
Jep embeds CPython in Java through JNI. ... Using the native Python interpreter may be much faster than alternatives.
Starred by 1.5K users
Forked by 166 users
Languages   C 52.1% | Java 30.2% | Python 17.7%
🌐
GitHub
github.com › topics › java-python
java-python · GitHub Topics · GitHub
JPyxie is a Java integration for executing Python scripts efficiently, with support for REST, gRPC, Process API, JEP, Jython, and GraalPy. The project goal is to make Python integration as easy as it is able to be.
🌐
GitHub
github.com › amemifra › Spring-Jython
GitHub - amemifra/Spring-Jython: Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython · GitHub
Java integration of Python script and classes into a Spring Boot Web Application. Powered by Jython - amemifra/Spring-Jython
Starred by 12 users
Forked by 11 users
Languages   Python 99.3% | Java 0.7%
🌐
GitHub
github.com › hpi-swa-lab › graalpython-java-example
GitHub - hpi-swa-lab/graalpython-java-example: Java and Python Integration Example for GraalVM · GitHub
Java and Python Integration Example for GraalVM. Contribute to hpi-swa-lab/graalpython-java-example development by creating an account on GitHub.
Starred by 21 users
Forked by 4 users
Languages   Java 64.4% | Python 35.6%
Find elsewhere
🌐
Reddit
reddit.com › r/java › best way to combine python and java?
r/java on Reddit: Best way to combine Python and Java?
October 29, 2022 -

My project uses some packages that are available only in Python and heavily rely on C libraries. The project also greatly benefits from Java libraries and the JVM. What's the optimal way to call Python functions from Java?

I tried:

  1. Small web-services: overhead to serialize data, start and stop the services. Also debugging is harder and implementing each new function is now double the effort.

  2. Jpy: a library that runs an interpreter in the JVM. Spare the service start/stop, but: isn't really feasible for more than a single-liner, data translation between Java and Python is cumbersome, and I also encountered runtime segmentation fault errors.

Any other options?

The project is in the machine-learning domain, so involves exchanging large numeric arrays and text. In some cases the execution switches back and forth between the platforms.

🌐
GitHub
github.com › bcdev › jpy
GitHub - bcdev/jpy: A bi-directional Python-Java bridge used to embed Java in CPython or the other way round. · GitHub
August 5, 2021 - A bi-directional Python-Java bridge used to embed Java in CPython or the other way round. - bcdev/jpy
Starred by 188 users
Forked by 37 users
Languages   C 54.6% | Java 25.9% | Python 18.7%
🌐
Medium
medium.com › graalvm › supercharge-your-java-apps-with-python-ec5d30634d18
Supercharge Your Java Apps with Python | by Tim Felgentreff | graalvm
May 5, 2023 - In this article we look at an example application developed by students at the Hasso Plattner Institute (HPI) in Potsdam which can be used as a template for using Python libraries from Java on GraalVM. The full source code is available at the GitHub repository of the HPI Software Architecture Group.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Mixing Java and Python: Building Polyglot Apps for AI and Data Science - Java Code Geeks
October 15, 2025 - Py4J Official Documentation Learn ... https://www.py4j.org/ JPype GitHub Repository Explore the JPype project, which allows Python code to run Java classes natively using JNI....
🌐
GitHub
github.com › topics › java-to-python
java-to-python · GitHub Topics · GitHub
To associate your repository with the java-to-python topic, visit your repo's landing page and select "manage topics."
🌐
Py4j
py4j.org
Welcome to Py4J — Py4J
This is the Java program that was executing at the same time (no code was generated and no tool was required to run these programs). The AdditionApplication app instance is the gateway.entry_point in the previous code snippet. Note that the Java program must be started before executing the Python code above.
🌐
GitHub
github.com › topics › java-and-python
java-and-python · GitHub Topics · GitHub
To associate your repository with the java-and-python topic, visit your repo's landing page and select "manage topics."
🌐
GitHub
github.com › perusworld › hornetq-jms-python
GitHub - perusworld/hornetq-jms-python: Sample HornetQ JMS Python Integration
Sample HornetQ JMS Python Integration ... implements Queue producer/consumer in java/python. The java implementation uses JMS while the python implementation uses STOMP ·...
Author   perusworld
🌐
Readthedocs
jython.readthedocs.io › en › latest › JythonAndJavaIntegration
Chapter 10: Jython and Java Integration — Definitive Guide to Jython latest documentation
The Java language added scripting ... Jython code into our Java applications. Similarly, the PythonInterpreter can be used from within Java code to invoke Jython. Also keep an eye on projects such as Clamp (http://github.com/groves/clamp/tree/master) that are on the ...
🌐
GitHub
github.com › topics › python
python · GitHub Topics · GitHub
Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running math code and a java based math library on top of the core c++ library. Also includes samediff: a pytorch/tensorflow like library for running deep learni… · python java clojure scala spark hadoop gpu intellij linear-algebra artificial-intelligence deeplearning neural-nets dl4j matrix-library deeplearning4j
🌐
SourceForge
jpype.sourceforge.net
JPype - Java to Python integration
Links: Python Java Jython/JPython · Similar Projects : JEP JPE
🌐
Baeldung
baeldung.com › home › java › how to call python from java
How to Call Python From Java | Baeldung
August 27, 2025 - In this tutorial, we’ve learned about some of the most popular technologies for calling Python code from Java. The code backing this article is available on GitHub.