On this page

Graal Languages

1 Introduction

Micronaut Graal Languages is a collection of components for integration of Graal based dynamic languages with Micronaut Framework.

Note: Micronaut React server-side rendering, which is based on GraalJS, is part of Micronaut Views.

2 Release History

For this project, you can find a list of releases (with release notes) here:

3 GraalPy

Micronaut GraalPy is an annotation-based feature to expose Python modules as Java Beans.

3.1 Getting Started

To use the GraalPy integration:

1) Add the micronaut-graalpy dependency on your classpath:

implementation("io.micronaut.micronaut-graal-languages:micronaut-graalpy")

2) Add the GraalPy plugin configuration for your build tool

pom.xml

<build>
 <plugins>
  <plugin>
    <groupId>org.graalvm.python</groupId>
    <artifactId>graalpy-maven-plugin</artifactId>
    <version>${graalpy.version}</version>
    <executions>
      <execution>
        <configuration>
          <packages>
            <package>termcolor==2.2</package> <!-- (1) -->
          </packages>
        </configuration>
      </execution>
    </executions>
  </plugin>
 </plugins>
 <!-- ... -->

build.gradle

3) Add the dealer.py Python script to the resources folder. The location follows the convention recognized by the GraalPy support library.

src/main/resources/org.graalvm.python.vfs/src/dealer.py
import random
def shuffle(data):
    random.shuffle(data)
    return data

4) Create a Java interface for the Python module

5) This library will provide an injectable implementation of the interface backed by the Python module.

import io.micronaut.context.annotation.Bean;
import jakarta.inject.Inject;

@Bean
public class DocExample {
    @Inject DealerService dealerService;

    public Object[] play() {
        Object[] cards = new Object[] { 1, 2, 3 };
        cards = dealerService.shuffle(cards);
        // ...
        return cards;
    }
}
Note
See GraalPyModule documentation for more details about global state, threading, and limitations.

4 Repository

You can find the source code of this project in this repository: