Call static Java methods from Python as if they were Python functions. Converts Java source files to reflection-friendly classes automatically.
Project description
orjp - Python & Java Interop
Overview
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.
Features
- 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
Quick Start
1. Installation
pip install orjp
2. Import and Use
from 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")
3. Creating Java Source Files
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.
Implementation Details
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.
Advantages
- 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
Supported Types
int,double,float,boolean,long- converted to appropriate Java typesString- passed through directly- Other types - supported through reflection
Note on Licensing
This package is intended for development and demonstration purposes. For commercial use or production environments, consider the associated licensing terms.
Project Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orjp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: orjp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c14cf508763dd98b0868fb511eb8a2fa5090f283ef0f4eaf99724102dd5bb5c9
|
|
| MD5 |
23bdadb05865be327b8673c523726f75
|
|
| BLAKE2b-256 |
2fa3a004f22782f5a4607c046ad91c86b2653f569761b6e502765e932945a8a0
|