jpserve: Calling Python from JAVA
Project description
jpserve
Jpserve provides a simple and high performance way to execute Python script in JAVA. It includes PyServe and JClient API.
PyServe is an execute server running on Python side and listening the execute requests from JAVA.
The JClient API can executes Python snippet or complete script file from java, it send the script to PyServe and get the execution result. The result is JSON format, so you can exchange the complex data between JAVA and Python flexibly.
Quick Start
Python Side
Open Python console, import jpserve and start the PyServe:
>>> from jpserve.jpserve import PyServe >>> server = PyServe(("localhost", 8888)) >>> server.start() >>> INFO:pserve:starting... INFO:pserve:pyserve listening in localhost 8888 >>>
JAVA Side
>>> // init the PyServeContext, it will make a connection to PyServe PyServeContext.init("localhost", 8888); // // prepare the script, and assign the return value to _result_ String script = "a = 2\n" + "b = 3\n" + "_result_ = a * b"; // // sned the script to PyServe, it returns the final result PyResult rs = executor.exec(script); // // check if the execution is success if (rs.isSuccess()) { System.out.println("Result: " + rs.getResult()); // get the _result_ value } else { System.out.println("Execute python script failed: " + rs.getMsg()); } ------------------------ Result: 6
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jpserve-0.1.0.zip
(6.8 kB
view details)
File details
Details for the file jpserve-0.1.0.zip
.
File metadata
- Download URL: jpserve-0.1.0.zip
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9b8ce0a72b6598988ac87b0ff4570cf4d11c2f001f2f76a9ec18cbeadc141f2 |
|
MD5 | 53fec2ebfb47c62c341477693991a0d0 |
|
BLAKE2b-256 | 0bd42579171502b606d81e35d817202ee88e386eb7902dba1f23cfe5779e16a5 |