PemJa
Project Links
Meta
Author: Apache Software Foundation
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
License
- OSI Approved :: Apache Software License
Programming Language
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: Implementation :: CPython
Operating System
- Unix
- MacOS
- Microsoft :: Windows
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>
Installation from sources
Prerequisites for building PemJa:
- Unix-like environment (we use Linux, Mac OS X), Windows
- 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) with $JAVA_HOME set correctly
- Python >= 3.8 (we recommend version 3.8, 3.9, 3.10, 3.11, 3.12, 3.13)
NOTE for windows:
- Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools"
- The compressed package in folder dist must be uncompressed and use the following command to install
pip install dist/$packageName$
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") // specify python exec, use "python" on Windows
.addPythonPaths(path) // add path to search path
.build();
PythonInterpreter interpreter = new PythonInterpreter(config);
// set & get
interpreter.set("a", 12345);
interpreter.get("a"); // Object
interpreter.get("a", Integer.class); // Integer
// exec & eval
interpreter.exec("print(a)");
// invoke functions
interpreter.exec("import str_upper");
String result = interpreter.invoke("str_upper.upper", "abcd");
// Object invoke(String name, Object... args);
// Object invoke(String name, Object[] args, Map<String, Object> kwargs);
// invoke object methods
/*
// invoke.py
class A:
def __init__(self):
self._a = 0
def get_value(self):
return self._a
def add(self, n):
self._a += n
def add_all(self, *args):
for item in args:
self._a += item
return self._a
def minus(self, n):
self._a -= n
return self._a
*/
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);
// python callback java methods
/*
// invoke_callback.py
from pemja import findClass
StringBuilder = findClass('java.lang.StringBuilder')
Integer = findClass('java.lang.Integer')
def callback_java():
sb = StringBuilder()
sb.append('pemja')
sb.append('java')
sb.append('python')
sb.append(Integer.toHexString(Integer.MAX_VALUE))
return sb.toString()
*/
interpreter.exec("import call_back")
print(interpreter.invoke("call_back.callback_java"))
Documentation
How To Contribute
Jun 27, 2025
0.6.1
Jun 24, 2025
0.6.0
Sep 15, 2025
0.5.5
Jul 08, 2025
0.5.4
Jun 27, 2025
0.5.3
Jun 20, 2025
0.5.2
May 07, 2025
0.5.1
Apr 30, 2025
0.5.0
Jan 09, 2025
0.4.2
Oct 12, 2023
0.4.1
Sep 13, 2023
0.4.0
Dec 05, 2024
0.3.2
Aug 30, 2023
0.3.1
Jan 12, 2023
0.3.0
Sep 23, 2022
0.2.6
Aug 30, 2022
0.2.5
Aug 03, 2022
0.2.4
Jul 30, 2022
0.2.3
Jul 27, 2022
0.2.2
Jul 27, 2022
0.2.1
Jul 05, 2022
0.2.0
Sep 23, 2022
0.1.6
May 10, 2022
0.1.5
Apr 02, 2022
0.1.4
Mar 25, 2022
0.1.3
Jan 24, 2022
0.1.2
Jan 20, 2022
0.1.1
Jan 20, 2022
0.1.0
Jan 20, 2022
0.1.dev0
Wheel compatibility matrix
Platform | CPython 3.8 | CPython 3.9 | CPython 3.10 | CPython 3.11 | CPython 3.12 | CPython 3.13 | CPython (additional flags: t) 3.13 |
---|---|---|---|---|---|---|---|
macosx_10_13_x86_64 | |||||||
macosx_10_9_x86_64 | |||||||
macosx_11_0_arm64 | |||||||
manylinux1_x86_64 |
Files in release
Extras:
None
Dependencies: