Skip to content

Repository files navigation

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:

  1. Accepting Java source code as input
  2. Parsing and extracting static method signatures using regex
  3. Generating reflection-compatible wrapper classes that use Java's reflection APIs
  4. 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 types
  • String - 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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages