Use Modules From Any Technology

Your stack:

Goal

Use a module from any supported technology directly in a Java service with Graftcode - no REST wrapper, no rewrite, no custom interop. In this tutorial we use a Python module as the example.

What You'll See

  • Install a module from another technology as a strongly-typed Graft using Maven - just like any other dependency.
  • Configure the generated client to point at the in-memory host.
  • Import and call it from your Java code as if it were a native Maven library.

Prerequisites

Step 1. Create a project folder

Create a new folder and set up a Maven project:

mkdir java-python-module-demo
cd java-python-module-demo

Create a pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>currency-demo</artifactId>
    <version>1.0.0</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>graftcode</id>
            <url>https://grft.dev/maven2</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>graft.pypi</groupId>
            <artifactId>sdncenter-currency-converter</artifactId>
            <version>0.6.1</version>
        </dependency>
    </dependencies>
</project>

Step 2. Install a module from another technology

For this example we'll use a Python currency converter from PyPI (sdncenter-currency-converter), but the same approach works with any module from a supported repository - npm, PyPI, Maven or NuGet.

Run following command to checkout selected python module to local directory. We need it as we will run it within same process:

python -m pip install sdncenter-currency-converter --target ./

The dependencies declared in pom.xml above install a Graft - a strongly-typed Java client generated from the module. You import and call it like any other Maven dependency, regardless of which technology the module was originally written in.

Download the dependencies:

mvn dependency:resolve -q

Step 3. Set the SDK key

Set the HYPERTUBE_KEY environment variable in your terminal before running the project:

PowerShell:

$env:HYPERTUBE_KEY="Fe2w-p2GK-Mn26-j8ZY-Xe25"

Bash (macOS / Linux):

export HYPERTUBE_KEY="Fe2w-p2GK-Mn26-j8ZY-Xe25"

Windows CMD:

set HYPERTUBE_KEY=Fe2w-p2GK-Mn26-j8ZY-Xe25

Step 4. Call the cross-language module and run it

Create src/main/java/energy/Main.java:

package energy;

import graft.pypi.sdncenter_currency_converter.GraftConfig;
import graft.pypi.sdncenter_currency_converter.currency_converter.converter.SimpleCurrencyConverter;

public class Main {
    public static void main(String[] args) throws Exception {
        GraftConfig.host = "inMemory";

        double result = SimpleCurrencyConverter.convert(100, "USD", "EUR");
        System.out.println("Converted amount: " + result);
    }
}

Run it:

mvn compile exec:java "-Dexec.mainClass=energy.Main"

You should see the converted amount printed in your terminal. SimpleCurrencyConverter.convert(...) comes from a Python package, but your code reads like a regular method call - no HTTP request, no response parsing, no serialization. GraftConfig.host = "inMemory" tells Graftcode to load and execute the Python module inside the same process.

Everything above works without any account - perfect for learning and local development. When you're ready for real-world usage, create a free account at portal.graftcode.com, set up a project, and copy its Project Key.

With a Project Key, point GraftConfig.host at your project's stable registry URL instead of a raw WebSocket address. A Project Key gives you:

  • Stable registry URL - the address for your Grafts stays permanent, so install commands don't change when you redeploy.
  • Portal visibility - see all your gateways and services in one place at gateways.graftcode.com.
  • Access control - decide who can download your Grafts using package manager authentication and permissions.