Skip to content

Repository files navigation

English | 한국어

PythonEmbed

CIMaven CentralGradle Plugin PortalcodecovLicense

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.

📚 Full documentation at howtis.github.io/python-embed

Quick Start

=== "Gradle"

Add the Gradle plugin to `build.gradle`:
```groovy
plugins {
id 'io.github.howtis.python-embed' version '1.0.2'
}
pythonEmbed {
packages = ['numpy']
}
dependencies {
implementation 'io.github.howtis:python-embed-runtime:1.0.2'
}
```

=== "Maven"

Add the Maven plugin to `pom.xml`:
```xml
<dependencies>
<dependency>
<groupId>io.github.howtis</groupId>
<artifactId>python-embed-runtime</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.github.howtis</groupId>
<artifactId>python-embed-maven-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals><goal>setup</goal></goals>
</execution>
</executions>
<configuration>
<packages>
<package>numpy</package>
</packages>
</configuration>
</plugin>
</plugins>
</build>
```

Then use it in your Java code:

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

The build plugin handles Python installation, venv creation, and package installation at build time.

Key Features

CategoryHighlights
CompatibilityFull CPython — numpy, scipy, torch, matplotlib, all C extensions
SetupZero manual steps — Gradle plugin auto-downloads Python if needed
SafetySubprocess isolation — Python crashes never kill the JVM
PerformanceMessagePack binary protocol
ConcurrencyAuto-scaling pool with async CompletableFuture API
IntegrationSpring Boot auto-configuration, Actuator HealthIndicator
InteropObject handles, Java proxies, callbacks, streaming, batch ops
ObservabilityHealth checks, SLF4J log forwarding, close hooks

📚 Full documentation & API reference →

Modules

Building

./gradlew build

Requirements: JDK 17+, Python 3.8+ (auto-downloaded if absent).

License

MIT — see LICENSE for details.

About

Run Python code from Java — embed CPython in JVM apps via subprocess & MessagePack. Gradle & Maven plugins.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages