Skip to content

PythonEmbed

Run Python code from Java — with full CPython compatibility and zero setup.

PythonEmbed embeds a real CPython interpreter in your JVM application via a subprocess + MessagePack binary protocol — just pure Java and CPython. All C extensions (numpy, scipy, torch) work out of the box.

Quick Look

Add the Gradle plugin:

plugins {
    id 'io.github.howtis.python-embed' version '1.0.2'
}

pythonEmbed {
    packages = ['numpy']
}

Then run Python from Java:

try (PythonEmbed py = PythonEmbed.create()) {
    py.exec("import numpy as np");
    int sum = py.eval("sum([1, 2, 3])").asInt();  // 6
}

Next Steps