Package: predictor-api-client
Predictor API clientThis package provides aPyPi-installablelightweight client application for thePredictor APIRESTFull server application. The package implementsPredictorApiClientclass enabling fast and easy method-based calls to all endpoints accessible on the API. To make working with the client a piece of cake, it provides full-documented example scripts for each of the supported endpoints. For more information about the Predictor API, please read the officialreadmeanddocumentation.The full programming sphinx-generated docs can be seen in theofficial documentation.Endpoints:predictor endpoints (/predictand/predict_proba)/predict- calls.predicton the specified predictor./predict_proba- calls.predict_probaon the specified predictor.security endpoints (/signup,/login, and/refresh)/signup- signs-up a new user./login- logs-in an existing user (obtains access and refresh authorization tokens)./refresh- refreshes an expired access token (obtains refreshed authorization access token).Contents:InstallationConfigurationDataExamplesLicenseContributorsInstallationpip install predictor-api-clientConfigurationThe package provides the following configuration of thePredictorApiClientobject during the instantiation:API deployment specific configuration: it supports the configuration of thehost(IP address),port(port number), and other settings related to the deployment and operation of the Predictor API (for more information, see thedocs/).API client specific configuration: it supports the configuration of the logging (logging_configuration). In this version, the package provides logging of the successful as well as unsuccessful/predictand/predict_probaendpoint calls (for more information, see thedocs/).DataThe full description of the requirements on input/output data (format, shape, etc.) can be foundhere.ExamplesIn general, every time a client is used, thePredictorApiClientclass must be instantiated. Next, all endpoint-specific data must be prepared. And finally, the endpoint-specific methods can be called. The full example scripts for each of the supported endpoints are placed at./examples(simplified examples are shown bellow).Client instantiationfrompprintimportpprintfromhttpimportHTTPStatusfrompredictor_api_client.clientimportPredictorApiClient# Prepare the predictor API client settings## --------------------------------------------- ## Must be same as for the running Predictor API ## --------------------------------------------- ### 1. host (IP address)# 2. port (port number)# 3. request verification# 4. request timeout in secondshost="http://127.0.0.1"port=5000verify=Truetimeout=2# Instantiate the predictor API clientclient=PredictorApiClient(host=host,port=port,verify=verify,timeout=timeout)User sign-up# This example assumes the presence of the client instantiation code# TODO: prepare data for a new user (see the API's requirements on the password)## 1. username# 2. password (e.g. can be generated with https://passwordsgenerator.net/)username="<TODO: FILL-IN>"password="<TODO: FILL-IN>"print("\n-- [01] example --")print(f"Signing-up a new user with username:{username}and password:{password}\n")# Sign-up a new userresponse,status_code=client.sign_up(username,password)# Check the outputifstatus_code==HTTPStatus.OK:print("Successfully signed-up a new user")else:print(f"The request was unsuccessful ({status_code}):{response}")print("Response:")pprint(response)User log-in# This example assumes the presence of the client instantiation code# TODO: prepare data for an existing user (data from: user sign-up)## 1. username# 2. passwordusername="<TODO: FILL-IN>"password="<TODO: FILL-IN>"print("\n-- [02] example --")print(f"Logging-in an existing user with username:{username}and password:{password}\n")# Log-in an existing userresponse,status_code=client.log_in(username,password)# Check the outputifstatus_code==HTTPStatus.OK:print("Successfully logged-in an existing user")else:print(f"The request was unsuccessful ({status_code}):{response}")print("Response:")pprint(response)Expired access token refresh# This example assumes the presence of the client instantiation code# TODO: prepare data for request authorization (refresh token from: user log-in)refresh_token="<TODO: FILL-IN>"print("\n-- [03] example --")print("Refreshing an expired access token\n")# Refresh an expired access tokenresponse,status_code=client.refresh_access_token(refresh_token)# Check the outputifstatus_code==HTTPStatus.OK:print("Successfully refreshed an expired access token")else:print(f"The request was unsuccessful ({status_code}):{response}")print("Response:")pprint(response)Prediction# This example assumes the presence of the client instantiation codeimportnumpy# TODO: prepare data for request authorization (access token and refresh token)access_token="<TODO: FILL-IN>"refresh_token="<TODO: FILL-IN>"# TODO: prepare model identifier## Example:# model_identifier = "dummy_predictor"model_identifier="<TODO: FILL-IN>"# TODO: prepare predictor data (feature values/labels)## ---------------------------------------------------- ## Must meet the data requirements of the Predictor API ## ---------------------------------------------------- ### Example (10 subjects, each having 100 1-D features):# feature_values = numpy.random.rand(10, 1, 100)# feature_labels = Nonefeature_values="<TODO: FILL-IN>"feature_labels=Noneprint("\n-- [04] example --")print(f"Calling for prediction(s) on a predictor identified with:{model_identifier}\n")# Make the prediction(s)## Use one of the following:# 1. client.predict(...)# 2. client.predict_proba(...)response,status_code=client.predict(# or client.predict_proba(...)access_token=access_token,refresh_token=refresh_token,model_identifier=model_identifier,feature_values=feature_values,feature_labels=feature_labels)# Check the outputifstatus_code==HTTPStatus.OK:print("Successfully called .predict(...)/.predict_proba(...)")else:print(f"The request was unsuccessful ({status_code}):{response}")print("Response:")pprint(response)LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.ContributorsThis package is developed by the members ofBrain Diseases Analysis Laboratory. For more information, please contact the head of the laboratory Jiri Mekyskamekyska@vut.czor the main developer: Zoltan Galazgalaz@vut.cz.