Java and CPython compatibility bridge
Best way to combine Python and Java?
Py4J - A Bridge between Python and Java
That's cool. So you have to have a java program running before you use the Python code?
More on reddit.comI made an AUTO-BRIDGING program for Minecraft Bedwars
Is this cheating? Please can someone answer. I am not challenging you, I am just wondering others opinions. I believe it is partially cheating as it bridges for the player but I suppose if you have written it yourself it is fair.
More on reddit.comVideos
» pip install python-javabridge
» pip install javabridge
I've implemented support for two-way compatibility between Java and Python/CPython, meaning that Java can import standard CPython modules and use code as if it were Java, and Python can import Java classes and use them as if they were Python classes.
Imports in both languages are done with standard import statements.
How It Works
Java code imported into Python is subjected to reflection and then Python wrapper classes are generated using the Python API that provide runtime translations between the two language runtimes. A native Python module is provided that provides the "magic import" functionality from Java to Python (https://qoretechnologies.com/manual/qorus/current/python/html/index.html#python_qoreloader_import_java).
Python code imported into Java is introspected using the Python C API and then bytecode is generated for Java wrapper classes that provide a similar runtime translation as the imports in the other direction. A custom compiler based on javax.tools is provided (QoreJavaCompiler docs) as well as runtime dynamic code generation support for wrapper APIs in a custom class loader (QoreURLClassLoader - more info with some code examples here: https://qoretechnologies.com/manual/qorus//gitlab-docs/develop/jni/html/index.html).
This is all accomplished using a third language called Qore that provides the functionality of a "language bridge" and also manages the references to data in each separate runtime. Because Qore has a deterministic garbage collector, strong references to Python and Java data are managed in Qore and released when there are no more valid references to the data (in Qore - therefore various tricks are used to manage references transparently including sing thread-local data; there is also the possibility of using custom reference handlers to maintain the validity of objects using different language runtimes and garbage collection implementations). A high level description of the approach is here: https://drive.google.com/file/d/1QfzoXKoqgm6s1wTTykB0VdnIo4j5p0oK/view?usp=sharing
While support for importing Java into Python has been released, importing Python into Java will be released in April 2021 but is currently working and stable.
The idea is to facilitate the mixed use of enterprise technologies (Java) and AI / data science technologies (Python).
All of the source code required has been released under permissive open source licenses (MIT).
I hope it could be interesting and useful for someone - happy to provide more information if there's interest.
» pip install jpy