GraalPy

A high-performance embeddable Python 3 runtime for Java

Benefits

access icon

Python for Java

Load and use Python packages directly in Java
compatibility icon

Python 3 Compatible

Runs the latest Python AI and Data Science packages
speed icon

Fastest Python on the JVM

Graal JIT compiles Python for native code speed
upgrade icon

Modern Python for the JVM

GraalPy provides an upgrade path for Jython users
code icon

Script Java with Python

Extend applications with Python scripts that interact with Java classes and framework
binary icon

Simple distribution

Package Python applications as a single binary with GraalVM Native Image

How to Get Started

1. Add GraalPy as a dependency from Maven Central


<dependency>
  <groupId>org.graalvm.polyglot</groupId>
  <artifactId>polyglot</artifactId> 
  <version>24.0.2</version>
</dependency>
<dependency>
  <groupId>org.graalvm.polyglot</groupId>
  <artifactId>python</artifactId> 
  <version>24.0.2</version>
  <type>pom</type>
</dependency>
                

or


  implementation("org.graalvm.polyglot:polyglot:24.0.2")
  implementation("org.graalvm.polyglot:python:24.0.2")
                

2. Embed Python code in Java


import org.graalvm.polyglot.Context;

try (Context context = Context.create()) {
    context.eval("python", "print('Hello from GraalPy!')");
}
                

3. Add GraalPy plugins for additional Python packages (optional)


<plugin>
  <groupId>org.graalvm.python</groupId>
  <artifactId>graalpy-maven-plugin</artifactId>
  <version>24.0.2</version>
  <executions>
    <execution>
      <configuration>
        <packages>
          <!-- Select Python packages to install via pip. -->
          <package>pyfiglet==1.0.2</package>
        </packages>
      </configuration>
      <goals>
        <goal>process-graalpy-resources</goal>
      </goals>
    </execution>
  </executions>
</plugin>
                

Move from Jython to Modern Python

Move your Jython applications to GraalPy for high performance and modern language features, while preserving an easy interoperability with Java.

Python Data Science Libraries in Java Applications

Using Python from Java with GraalVM

GraalPy brings the world of Python data science libraries to Java and other languages running on GraalVM. Using GraalVM's polyglot interfaces, it is now easier than ever to embed Python code in Java applications and with good performance to boot! Oracle GraalVM also includes sandboxing option to run Python native extensions like NumPy, SciPy, or Matplotlib in a managed Java application.

Connect with us