Skip to content

Latest commit

 

History

History

graalpy-spring-boot-pygal-charts

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SVG Charts with GraalPy and Spring Boot

This demo illustrates how GraalPy can be used to embed Pygal, a dynamic SVG charting library written in Python, in a Spring Boot application. In particular, this demo shows four different approaches to interact with Pygal from Java.

Preparation

Install GraalVM for JDK 23 and set the value of JAVA_HOME accordingly. We recommend using SDKMAN!. (For other download options, see GraalVM Downloads.)

sdk install java 23-graal

Run the Application

To start the demo, simply run:

./mvnw package spring-boot:run

When the demo runs, open the following URLs in a browser:

URL Service
http://localhost:8080/java PyGalServicePureJava
http://localhost:8080/python PyGalServicePurePython
http://localhost:8080/mixed PyGalServiceMixed
http://localhost:8080/dynamic PyGalServiceValueAPIDynamic

Implementation Details

The DemoController uses four services that all render the same XY chart using different implementations:

The DemoApplicationTests ensures that all four service implementations render the same XY chart. Run it with ./mvnw test.

Note: This demo uses a single GraalPyContext, which can execute Python code in only one thread at a time. Threads running Python code are internally scheduled in round-robin fashion. Pure Python packages including Pygal can be used in multiple GraalPy contexts, for example one context per thread, to improve the throughput of the application. Other demos such as graalwasm-micronaut-photon illustrate how to pool multiple contexts.