Handlers

DataframeHandler

class bentoml.handlers.DataframeHandler(orient='records', output_orient='records', typ='frame', input_dtypes=None)
Dataframe handler expects inputs from rest request or cli options that

can be converted into a pandas Dataframe, and pass down the dataframe to user defined API function. It also returns response for REST API call or print result for CLI call

Parameters
  • orient (str) – Incoming json orient format for reading json data. Default is records.

  • output_orient (str) – Prefer json orient format for output result. Default is records.

  • typ (str) – Type of object to recover for read json with pandas. Default is frame

  • ({str (input_dtypes) – str}): A dict of column name and data type.

Raises
  • ValueError – Incoming data is missing required columns in input_dtypes

  • ValueError – Incoming data format is not handled. Only json and csv

ImageHandler

class bentoml.handlers.ImageHandler(input_names=('image', ), accept_image_formats=None, pilmode='RGB')

Transform incoming image data from http request, cli or lambda event into numpy array.

Handle incoming image data from different sources, transform them into numpy array and pass down to user defined API functions

Parameters
  • input_names (string[]]) – A tuple of acceptable input name for HTTP request. Default value is (image,)

  • accept_image_formats (string[]) – A list of acceptable image formats. Default value is loaded from bentoml config ‘apiserver/default_image_handler_accept_file_extensions’, which is set to [‘.jpg’, ‘.png’, ‘.jpeg’, ‘.tiff’, ‘.webp’, ‘.bmp’] by default. List of all supported format can be found here: https://imageio.readthedocs.io/en/stable/formats.html

  • pilmode (string) – The pilmode to be used for reading image file into numpy array. Default value is ‘RGB’. Find more information at: https://imageio.readthedocs.io/en/stable/format_png-pil.html

Raises

ImportError – imageio package is required to use ImageHandler

FastaiImageHandler

class bentoml.handlers.FastaiImageHandler(input_names=('image', ), accept_image_formats=None, convert_mode='RGB', div=True, cls=None, after_open=None)

BentoHandler specified for handling image input following fastai conventions by passing type fastai.vision.Image to user API function and providing options such as div, cls, and after_open

Parameters
  • input_names ([str]]) – A tuple of acceptable input name for HTTP request. Default value is (image,)

  • accept_image_formats ([str]) – A list of acceptable image formats. Default value is loaded from bentoml config ‘apiserver/default_image_handler_accept_file_extensions’, which is set to [‘.jpg’, ‘.png’, ‘.jpeg’, ‘.tiff’, ‘.webp’, ‘.bmp’] by default. List of all supported format can be found here: https://imageio.readthedocs.io/en/stable/formats.html

  • convert_mode (str) – The pilmode to be used for reading image file into numpy array. Default value is ‘RGB’. Find more information at https://imageio.readthedocs.io/en/stable/format_png-pil.html

  • div (bool) – If True, pixel values are divided by 255 to become floats between 0. and 1.

  • cls (Class) – Parameter from fastai.vision open_image, default is fastai.vision.Image

  • after_open (func) – Parameter from fastai.vision open_image, default is None

Raises
  • ImportError – imageio package is required to use FastaiImageHandler

  • ImportError – fastai package is required to use FastaiImageHandler

JsonHandler

class bentoml.handlers.JsonHandler

JsonHandler parses REST API request or CLI command into parsed_json(a dict in python) and pass down to user defined API function