sockets - How (in what form) to share (deliver) a Python function? -


the final outcome of work should python function takes json object input , return json object output. keep more specific, data scientist, , function speaking about, derived data , delivers predictions (in other words, machine learning model).

so, question how deliver function "tech team" going incorporate web-service.

at moment face few problems. first, tech team not work in python environment. so, cannot "copy , paste" function code. second, want make sure function runs in same environment mine. example, can imagine use library tech team not have or have version differ version use.

added

as possible solution consider following. start python process listen socket, accept incoming strings, transforms them json, gives json "published" function , returns output json string. solution have disadvantages? in other words, idea "publish" python function background process listening socket?

you have right idea using socket there tons of frameworks doing want. hleggs, suggest checkout flask build microservice. let other team post json objects in http request flask application , receive json objects back. no knowledge of underlying system or additional requirements required!

here's template flask app replies , responds json

from flask import flask, request, jsonify  app = flask(__name__)  @app.route('/', methods=['post']) def index():     json = request.json     return jsonify(your_function(json))   if __name__=='__main__':     app.run(host='0.0.0.0', port=5000) 

edit: embeded code directly per peter britain's advice


Comments