A high-performance embeddable Python 3 runtime for Java
Benefits
Python 3 Compatible
Compatible with many Python packages, including popular AI and Data Science libraries
How to Get Started
You have the option to extend your Java application with Python, or go straight to the starter project
1. Add GraalPy as a dependency from Maven Central
1. Add GraalPy as a dependency from Maven Central
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>24.1.2</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>python</artifactId>
<version>24.1.2</version>
<type>pom</type>
</dependency>
or
implementation("org.graalvm.polyglot:polyglot:24.1.2")
implementation("org.graalvm.polyglot:python:24.1.2")
2. Embed Python code in Java
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)
3. Add GraalPy plugins for additional Python packages (optional)
<plugin>
<groupId>org.graalvm.python</groupId>
<artifactId>graalpy-maven-plugin</artifactId>
<version>24.1.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>
or
plugins {
id("org.graalvm.python") version "24.1.2"
}
graalPy {
packages = setOf("pyfiglet==1.0.2")
}