Pyjnius

1.7.0 · active · verified Thu Apr 16

Pyjnius is a Python library for accessing Java classes and objects using the Java Native Interface (JNI). It can either start a new Java Virtual Machine (JVM) within the Python process or attach to an already existing one, making it suitable for both desktop and Android applications. Actively maintained by the Kivy team, it typically sees new releases every few months. The current stable version is 1.7.0.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `autoclass` to reflect and interact with standard Java classes like `java.util.Stack` and `java.lang.System`. It shows how to instantiate objects, call methods, and access static fields.

from jnius import autoclass

# Access a standard Java class
Stack = autoclass('java.util.Stack')
stack = Stack()
stack.push('hello')
stack.push('world')

print(f"Popped: {stack.pop()}")
print(f"Popped: {stack.pop()}")

# Access static methods and fields
System = autoclass('java.lang.System')
System.out.println('Hello from Pyjnius!')

view raw JSON →