Registry / serialization / pemja
library0.6.1pypypi✓ verified 82d ago

PemJa is a Python-Java bridge that enables embedding a JVM within a Python process, allowing dynamic interaction with Java objects and classes. It simplifies calling Java methods from Python and provides mechanisms for classpath management. The current version is 0.6.1, with releases occurring as features are added or bugs are fixed, but without a strict regular cadence.

pip install pemja
INSTALL
IMPORT
SIG · PEMJA
P
pemja
serializationpythonv0.6.1
Install
1.8s avg
Import
Disk
16MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

launch_jvm
import pemja
from pemja import launch_jvm

This quickstart demonstrates launching a JVM, accessing static Java methods, creating Java object instances, calling instance methods, and basic Java exception handling. It's crucial to have JDK 8+ installed on your system for PemJa to function.

import pemja # Ensure JDK 8+ is installed and accessible in your system's PATH or JAVA_HOME. # In a production environment, consider explicit JVM options or classpath management. try: print("Launching JVM...") # Using a context manager ensures the JVM is shut down cleanly with pemja.launch_jvm() as jvm: print("JVM launched successfully.") # 1. Access a static method from a core Java class System = jvm.find_class("java.lang.System") java_version = System.getProperty("java.version") print(f"Java version reported by JVM: {java_version}") # 2. Create an instance of a Java class and call a method String = jvm.find_class("java.lang.String") greeting = jvm.create_instance(String, "Hello from PemJa in Python!") print(f"Original Java string: {greeting}") print(f"Uppercase Java string: {greeting.toUpperCase()}") # 3. Handle exceptions from Java # This is a simple example; real error handling would be more robust try: Integer = jvm.find_class("java.lang.Integer") Integer.parseInt("not_a_number") # This will throw a Java NumberFormatException except jvm.JavaException as e: print(f"Caught Java Exception: {e.get_stack_trace()}") except pemja.PemjaException as e: print(f"PemJa specific error: {e}") print("Please ensure JDK 8+ is correctly installed and configured.") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThe parameters for `pemja.launch_jvm()` changed significantly in version 0.6.0. The `config` dictionary was replaced with more explicit parameters like `options` and `classpath`.
fix
Review the PemJa documentation for `launch_jvm` (e.g., on GitHub) and update your calls to use the new explicit parameters. For general JVM arguments, use the `options` list (e.g., `options=['-Xmx512m']`).
affects: 0.6.0+
gotchaPemJa requires a Java Development Kit (JDK) version 8 or higher to be installed on the system where Python is running. Without a properly configured JDK, PemJa cannot launch the JVM.
fix
Install JDK 8+ and ensure its `bin` directory is in your system's PATH environment variable, or set the `JAVA_HOME` environment variable to point to your JDK installation directory.
affects: All
gotchaThe JVM should generally be launched only once per Python process using `pemja.launch_jvm()`. Attempting to launch it multiple times can lead to errors or undefined behavior.
fix
Call `pemja.launch_jvm()` once at the beginning of your application. Store the returned `jvm` object and reuse it throughout your application. Use a context manager (`with pemja.launch_jvm() as jvm:`) for safe shutdown.
affects: All
gotchaWhen working with custom Java JARs, ensuring they are correctly added to the JVM's classpath is critical. Incorrect classpath configuration leads to `NoClassDefFoundError` or similar issues.
fix
Use `pemja.find_jar()` to locate JARs and pass the result to the `classpath` argument of `pemja.launch_jvm()`. For multiple JARs, `classpath` accepts a list of paths.
affects: All
Upgrade
Version history
0.6.1latest on PyPI · released Jun 27, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
pemja — pip install pemja · libregistry