Skip to main content

Enables Python to dynamically access arbitrary Java objects (ctypes/cffi-based Barthelemy Dagenais's Py4J)

Project description

jtypes.py4j

Enables Python to dynamically access arbitrary Java objects.

Overview

jtypes.py4j enables Python programs to dynamically access arbitrary Java objects via Java’s Native Invocation Interface (JNI).

jtypes.py4j is a lightweight Python Java package, based on the ctypes FFI library.
It is an almost fully compliant implementation of Barthelemy Dagenais’s good known Py4J package by reimplementing whole it’s functionality in a clean Python via JNI instead of Python and Java via custom API service.

About Py4J:

Note from the original website:

Welcome to Py4J

Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects.

Here is a brief example of what you can do with Py4J.
The following Python program creates a java.util.Random instance from a JVM and calls some of its methods.
>>> from py4j.java_gateway import JavaGateway
>>> gateway = JavaGateway()                  # connect to the JVM
>>> random = gateway.jvm.java.util.Random()  # create a java.util.Random instance
>>> number1 = random.nextInt(10)             # call the Random.nextInt method
>>> number2 = random.nextInt(10)
>>> print(number1,number2)
(2, 7)

Requirements

  • Java Runtime (JRE) or Java Development Kit (JDK), and NumPy.

Installation

pip install --upgrade jtypes.py4j

To ensure everything is running correctly you can run the tests using

python -m jt.py4j.tests

Prerequisites:

License

Copyright (c) 2014-2016, Adam Karpierz

Licensed under the BSD license
Please refer to the LICENSE file.

Authors

Changelog

0.0.1 (2014-08-05)

  • Initial version.

Project details


Release history Release notifications

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page