polyglot-adapter is a lightweight Java SDK providing a unified executor-based API for executing and embedding multi-language code (Python, JavaScript) via GraalVM Polyglot. It simplifies context creation, host access management, and interlanguage communication while preserving full control over GraalVM configuration.
β Focused on developer experience β predictable, fast, fully composable.
-
Unified
BaseExecutorAPI with nativeValueinterop (Value.as(...)) -
Automatic host-to-guest binding via Java interfaces (
bind()) -
Composable
Context.BuilderAPI through.apply(...) -
Extensible HostAccess with
.extendHostAccess(...) - Built-in type mappings (
Value β Path, user-extendable) - Virtual File System (VFS) integration for GraalPy
- Fully dependency-free (no frameworks)
- 100% compatible with GraalVM 25.x+
polyglot-adapter/
βββ api/
β βββ context/
β β βββ Language.java
β β βββ PolyglotContextFactory.java
β β βββ ResourcesProvider.java
β βββ executors/
β βββ BaseExecutor.java
β βββ PyExecutor.java
β βββ JsExecutor.java
βββ exceptions/
β βββ EvaluationException.java
βββ utils/
βββ CommonUtils.java
βββ StringCaseConverter.java
- JDK 25+
- Maven 3.9+
- GraalVM 25.x+
<dependency>
<groupId>io.github.ih0r-d</groupId>
<artifactId>polyglot-adapter</artifactId>
<version>0.1.0</version>
</dependency>Add only the runtimes you actually use. Marked as
optionalto avoid transitive pulls.
<dependency>
<groupId>org.graalvm.python</groupId>
<artifactId>python-embedding</artifactId>
<version>25.0.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.graalvm.python</groupId>
<artifactId>python-launcher</artifactId>
<version>25.0.1</version>
<optional>true</optional>
</dependency><dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>25.0.1</version>
<type>pom</type>
<optional>true</optional>
</dependency>try (var executor = PyExecutor.createDefault()) {
MyApi api = executor.bind(MyApi.class);
System.out.println(api.add(3, 5)); // 8
}Python side:
class MyApi:
def add(self, a, b): return a + b
polyglot.export_value("MyApi", MyApi).allowAllAccess(true)
.allowExperimentalOptions(true)Full access for interop, experimental options for latest GraalPy / GraalJS engines.
These defaults follow Oracleβs embedding best practices for SDKs (not sandboxes).
| Option | Purpose |
|---|---|
allowAllAccess(true) |
Enables complete Java β guest interoperability (IO, threads, polyglot bridge). |
allowExperimentalOptions(true) |
Activates all evolving GraalVM engine flags. |
If sandboxing is needed:
.apply(b -> b.allowAllAccess(false))
.apply(b -> b.allowIO(false))
.hostAccess(HostAccess.NONE);The SDK adds safe default mappings for convenience:
builder.targetTypeMapping(
Value.class, Path.class,
Value::isString, v -> Path.of(v.asString()),
HostAccess.TargetMappingPrecedence.LOW
);Users can extend or override mappings freely via:
.extendHostAccess(b -> b.targetTypeMapping(
Value.class, Instant.class,
Value::isString, v -> Instant.parse(v.asString())
));| Method | Description |
|---|---|
apply(Consumer<Context.Builder>) |
Direct low-level context configuration. |
extendHostAccess(Consumer<HostAccess.Builder>) |
Extend or override SDK default mappings. |
withSafePythonDefaults() |
Disable GraalPy C API, hide warnings, redirect logs. |
withNodeSupport() |
Enable Node.js compatibility for GraalJS. |
option(String, String) |
Add single engine option. |
options(Map<String,String>) |
Add multiple engine options. |
Run all tests (JUnit 5):
mvn clean testIncludes:
- Context creation tests (Python / JS)
- Executor binding and async evaluation tests
| Command | Action |
|---|---|
mvn clean verify |
Build & run tests |
mvn deploy -P release |
Publish to Maven Central |
task bump TYPE=minor |
Version bump |
task release VERSION=X.Y.Z |
Tag & release version |
Licensed under the Apache License 2.0.
See LICENSE for details.