-
|
Starting a discussion exploring support for GraalPython in JBang. Is it feasible, how would it work, what are the benefits and limitations? GraalPython in located in Maven Central at: GraalPython is a Python 3.11 compliant runtime on top of the GraalVM (JVM): |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
Moving from Jython to GraalPython: GraalPython with JBang integration demo: |
Beta Was this translation helpful? Give feedback.
-
|
// Install the Graal VM // Run the Graal Python code The first run took 2+ minutes to complete. The second run finished in 11 seconds. $ time jbang run qrcode.java "Hello from GraalPy!" Both times the following warning was printed on the console. This should be further investigated. Experimental run with EnableJVMCI enabled. $ export JBANG_JAVA_OPTIONS="-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI" Experimental run with EnableJVMCI enabled and Interpreter Warning set to false. $ export JBANG_JAVA_OPTIONS="-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Dpolyglot.engine.WarnInterpreterOnly=false" $ time jbang run qrcode.java "Hello from GraalPy!" TBD - test with optimizing Truffle runtime installed / enabled. |
Beta Was this translation helpful? Give feedback.
-
|
#!/usr/bin/env python-jvm
# restclient_graalpy.py
#
# Run: jbang run python-jvm@wfouche restclient_graalpy.py
#
# /// jbang
# requires-graalpy = "==24.2.1"
# requires-java = ">=21"
# debug = false
# dependencies = [
# "org.springframework.boot:spring-boot-starter-web:3.4.4"
# ]
# [graalpy]
# allowAllAccess = true
# emulateJython = true
# [java]
# runtime-options = "-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -Dpolyglot.engine.WarnInterpreterOnly=false"
# [jbang]
# integrations = false
# ///
import java.lang.String as String
import org.springframework.web.client.RestClient as RestClient
def restApiCall(uri: str, id: int):
restClient = RestClient.create()
rsp = restClient.get().uri(uri, id).retrieve().body(String)
print(rsp)
def main():
restApiCall("https://jsonplaceholder.typicode.com/todos/{id}", 1)
main()Output: |
Beta Was this translation helpful? Give feedback.
-
|
Running $ jbang run python-jvm@wfouche
python-jvm/1/2025-04-24T17:58:24
Jython 2.7.4 (tags/v2.7.4:3f256f4a7, Aug 18 2024, 10:30:53)
[OpenJDK 64-Bit Server VM (Eclipse Adoptium)] on java21.0.6
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print(1+1)
2
>>>
>>> |
Beta Was this translation helpful? Give feedback.

python-jvm@wfoucheis a JBang app that streamlines the process of executing GraalPython programs within a JVM environment.