neuraxle.rest.flask

Module-level documentation for neuraxle.rest.flask. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:


Neuraxle’s Flask Wrapper classes

The flask wrapper classes are used to easily serve pipeline predictions using a flask rest api.

Classes

FlaskRestApiWrapper(json_decoder, wrapped, …)

Wrap a pipeline to easily deploy it to a REST API.

JSONDataBodyDecoder(hyperparams, …)

Class to be used within a FlaskRESTApiWrapper to convert input json to actual data (e.g.: arrays)

JSONDataResponseEncoder(hyperparams, …)

Base class to be used within a FlaskRESTApiWrapper to convert prediction output to json response.

Examples using neuraxle.rest.flask.FlaskRestApiWrapper

Examples using neuraxle.rest.flask.JSONDataBodyDecoder

Examples using neuraxle.rest.flask.JSONDataResponseEncoder


class neuraxle.rest.flask.JSONDataBodyDecoder(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples = None, hyperparams_space: neuraxle.hyperparams.space.HyperparameterSpace = None, config: Union[Dict[KT, VT], neuraxle.hyperparams.space.RecursiveDict] = None, name: str = None, savers: List[neuraxle.base.BaseSaver] = None)[source]

Bases: neuraxle.base.BaseStep, abc.ABC

Class to be used within a FlaskRESTApiWrapper to convert input json to actual data (e.g.: arrays)

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

decode(data_inputs: dict)[source]

Will convert data_inputs to a dict or a compatible data structure for jsonification

Parameters

data_inputs (dict parsed from json) (encoded) –

Returns

data_inputs (as a data structure compatible with pipeline’s data inputs)

_abc_impl = <_abc_data object>
class neuraxle.rest.flask.JSONDataResponseEncoder(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples = None, hyperparams_space: neuraxle.hyperparams.space.HyperparameterSpace = None, config: Union[Dict[KT, VT], neuraxle.hyperparams.space.RecursiveDict] = None, name: str = None, savers: List[neuraxle.base.BaseSaver] = None)[source]

Bases: neuraxle.base.BaseStep, abc.ABC

Base class to be used within a FlaskRESTApiWrapper to convert prediction output to json response.

transform(data_inputs) → flask.wrappers.Response[source]

Transform processed data inputs into a flask response object.

Return type

Response

Parameters

data_inputs

Returns

flask response object

encode(data_inputs) → dict[source]

Convert data_inputs to a dict or a compatible data structure for jsonification.

Return type

dict

Parameters

(a data structure outputted by the pipeline after a transform) (data_inputs) –

Returns

encoded data_inputs (jsonifiable dict)

_abc_impl = <_abc_data object>
class neuraxle.rest.flask.FlaskRestApiWrapper(json_decoder: neuraxle.rest.flask.JSONDataBodyDecoder, wrapped: neuraxle.base.BaseStep, json_encoder: neuraxle.rest.flask.JSONDataResponseEncoder, route='/')[source]

Bases: neuraxle.pipeline.Pipeline

Wrap a pipeline to easily deploy it to a REST API. Just provide a json encoder and a json decoder.

Usage example:

``` class CustomJSONDecoderFor2DArray(JSONDataBodyDecoder):

‘’’This is a custom JSON decoder class that precedes the pipeline’s transformation.’’’

def decode(self, data_inputs: dict):

values_in_json_2d_arr: List[List[int]] = data_inputs[“values”] return np.array(values_in_json_2d_arr)

class CustomJSONEncoderOfOutputs(JSONDataResponseEncoder):

‘’’This is a custom JSON response encoder class for converting the pipeline’s transformation outputs.’’’

def encode(self, data_inputs) -> dict:
return {

‘predictions’: list(data_inputs)

}

app = FlaskRestApiWrapper(

json_decoder=CustomJSONDecoderFor2DArray(), wrapped=Pipeline(…), json_encoder=CustomJSONEncoderOfOutputs(),

).get_app()

app.run(debug=False, port=5000) ```

__init__(json_decoder: neuraxle.rest.flask.JSONDataBodyDecoder, wrapped: neuraxle.base.BaseStep, json_encoder: neuraxle.rest.flask.JSONDataResponseEncoder, route='/')[source]

Initialize self. See help(type(self)) for accurate signature.

get_app()[source]

This methods returns a REST API wrapping the pipeline.

Returns

a Flask app (as given by app = Flask(__name__) and then configured).

_abc_impl = <_abc_data object>