GraalPy

3 min read Original article ↗

A high-performance embeddable Python 3 runtime for Java

Python icon

Benefits

speed icon

Fastest Python on the JVM

Graal JIT compiles Python for native code speed

binary icon

Simple distribution

Package Python applications as a single binary with GraalVM Native Image

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

Maven icon

or

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

Gradle icon

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!')");
}

Java icon

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>25.0.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>

Maven icon

or

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

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

Gradle icon

Guides

Demos

Videos

Tips and Tricks for GraalVM and Graal Languages

In this session, Fabio Niephaus from the GraalVM team shows his favourite tips and tricks for using GraalPy and other Graal Languages in IntelliJ IDEA. He also shows how to use IntelliJ IDEA as a multi-language IDE. Language injections and support for various debugging protocols make it easy to embed and debug code written in languages like Python in Java applications.

Supercharge your Java Applications with Python!
Jfokus'25

Projects such as LangChain4j, Spring AI, and llama3.java got the Java community very excited about AI in the last year. The Python ecosystem also provides many powerful packages for data science, machine learning, and more. Wouldn't it be cool if you, as a Java developer, could benefit from this, too?
In this talk, we show how you can get started with GraalPy and use packages from the Python ecosystem. We also show some live demos and preview upcoming features that will improve the interaction between Java and native extensions that ship with popular Python packages.

Supercharge your Java Applications with Python!
Devoxx'24

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.