PemJa
What is it?
PemJa is an open source cross language call framework based on FFI. It aims to provide a high-performance
framework of calling between different languages.
Where to get it
Python binary installers for the latest released version are available at the Python package index
pip install pemja
Java Maven Dependency
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>pemja</artifactId>
<version>{version}</version>
</dependency>
Dependencies
Installation from sources
Prerequisites for building PemJa:
- Unix-like environment (we use Linux, Mac OS X)
- Git
- Maven (we recommend version 3.2.5 and require at least 3.1.1)
- Java 8 or 11 (Java 9 or 10 may work)
- Python >= 3.8 (we recommend version 3.8, 3.9, 3.10, 3.11)
git clone https://github.com/alibaba/pemja.git
cd pemja
mvn clean install -DskipTests
pip install -r dev/dev-requirements.txt
python setup.py sdist
pip install dist/*.tar.gz
Usage
String path = ...;
PythonInterpreterConfig config = PythonInterpreterConfig
.newBuilder()
.setPythonExec("python3")
.addPythonPaths(path)
.build();
PythonInterpreter interpreter = new PythonInterpreter(config);
interpreter.set("a", 12345);
interpreter.get("a");
interpreter.get("a", Integer.class);
interpreter.exec("print(a)");
interpreter.exec("import str_upper");
String result = interpreter.invoke("str_upper.upper", "abcd");
interpreter.exec("import invoke");
interpreter.exec("a = invoke.A()");
interpreter.invokeMethod("a", "add", 3);
interpreter.invokeMethod("a", "minus", 2);
interpreter.invokeMethod("a", "add_all", 1, 2, 3);
interpreter.exec("import call_back")
print(interpreter.invoke("call_back.callback_java"))
Documentation