lightmlrestapi¶


lightmlrestapi implements a light machine learning REST API based on falcon. If I were to start again this project, I would probably choose FastAPI.
Documentation¶
Examples¶
You can test a dummy wsgi server by running:
start_mlrestapi --name=dummy
And then query it with:
import requests
import ujson
features = ujson.dumps({'X': [0.1, 0.2]})
r = requests.post('http://127.0.0.1:8081', data=features)
print(r)
print(r.json())
It should return:
{'Y': [[0.4994216179, 0.4514893599, 0.0490890222]]}
The command line is described at cmd_start_mlrestapi_cmd. The purpose is to start a REST API based on a custom model.
start_mlrestapi <filename.py>
<filename>.py
must contain a predict function described
as follows:
import pickle
# We declare an id for the REST API.
def restapi_version():
return "0.1.1234"
# We declare a loading function.
def restapi_load():
with open("iris2.pickle", "rb") as f:
loaded_model = pickle.load(f)
return loaded_model
# We declare a predict function.
def restapi_predict(clf, X):
return clf.predict_proba(X)
# We test it works.
if __name__ == "__main__":
clf = restapi_load()
print(restapi_predict(clf, [0.1, 0.2]))
Links: github, documentation, lightmlrestapi, blog