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.1.1</version>
</dependency>
<dependency>
  <groupId>org.graalvm.polyglot</groupId>
  <artifactId>python</artifactId> 
  <version>24.1.1</version>
  <type>pom</type>
</dependency>
                

or


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

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.1.1</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>
                

or


plugins {
    id("org.graalvm.python") version "24.1.1"
}

graalPy {
    packages = setOf("pyfiglet==1.0.2")
}
                

GraalPy Quick Start

Jump right in with this starter project

Videos

Supercharge your Java Applications with Python!

The Python ecosystem provides many powerful packages for data science, machine learning, and more, that you can now leverage in Java. Get started by adding GraalPy as a dependency to your Java project. There are also Maven and Gradle plugins for GraalPy that help you install additional Python packages. In this presentation, we also show live demos that illustrate different use cases, such as: a Spring Boot application that visualizes data with Python, Python running on JBang!, a Java application scripted with Python, and more.

Connect with us