On this page
Graal Languages
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.
For this project, you can find a list of releases (with release notes) here:
Micronaut GraalPy is an annotation-based feature to expose Python modules as Java Beans.
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.
import random
def shuffle(data):
random.shuffle(data)
return data4) 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. |
You can find the source code of this project in this repository: