orjp (Java & Python Interop) is a Python package that allows you to call static Java methods directly from Python code, making Java interoperability seamless and intuitive.
- Call static Java methods as if they were Python functions
- Automatically converts Java source files to reflection-friendly classes
- Support for all Java primitive types (int, double, float, boolean, long, String)
- Reflection-based approach that doesn't require JNI or external JVM libraries
pip install orjpfrom orjp import subject
# Call static methods like Python functions
result = subject.test() # Calls into Java
result = subject.greet("world", 3) # Calls into the matching Java overload
# Or use the call API
from orjp import call
call("subject.java", "test")Create a .java file in the orjp/jvm/ directory:
public class Subject {
public static String greet(String name, int times) {
return String.format("Hello %s (x%s)", name, times);
}
public static void test() {
System.out.println("Test method called");
}
}The package will automatically convert this to a reflection-friendly class available in Python.
The package works by:
- Accepting Java source code as input
- Parsing and extracting static method signatures using regex
- Generating reflection-compatible wrapper classes that use Java's reflection APIs
- Creating Python classes that map directly to these generated Java classes
This approach eliminates the need for JNI (Java Native Interface) and complex JVM native libraries, while providing a clean, Pythonic interface for Java interop.
- No JNI required - Uses pure Java reflection
- Clean API - Java methods look and behave like Python functions
- Type-safe - Maintains Java type checking while providing Python-like syntax
- Simple setup - No external JVM installation needed
- Automatic conversion - Java files are transformed transparently
int,double,float,boolean,long- converted to appropriate Java typesString- passed through directly- Other types - supported through reflection
This package is intended for development and demonstration purposes. For commercial use or production environments, consider the associated licensing terms.