Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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
Release History

Release History

This version
History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
jpserve-0.1.0.zip (6.8 kB) Copy SHA256 Checksum SHA256 Source Oct 11, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting