0

Right way to call Python code from Java

asked 2019-03-15 15:08:22 +0800

Vindieselwalker gravatar image Vindieselwalker
1

In my company some data science components are written using Python scripts. But our web application is Java. Now, I need to call these Python scripts from my web application supplying some data and run time parameters. What is the best way to make such calls.

Our data scientists are thinking of opening their Python APIs as ZeroRPC based endpoints and expect me to write a Java client to call their APIs. (I Googled and there is not a lot of information on this). Is this the right way? What are the typical/standard ways to interact with Python code?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-04-11 12:52:10 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2019-04-11 12:52:29 +0800

unusual question ... (for a ZK forum) I guess the simplest way would be to execute a new process and consume the output stream

https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html


as for remote calls (RPC) it depends on the protocol used, if you find a Java api to call zerorpc

I found this 5 year old implementation: https://github.com/jamescarr/zerorpc-java

the code for the client implementation doesn't look complicated and easy to reuse:

https://github.com/jamescarr/zerorpc-java/blob/master/src/main/java/org/zerorpc/ZeroRPCClient.java

I haven't tried this but it looks like it's based on 2 other libraries jeromq and msgpack (which still seem active up to today)

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2019-03-15 15:08:22 +0800

Seen: 8 times

Last updated: Apr 11 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More