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_name='image', accept_file_extensions=None, accept_multiple_files=False, 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_name (string[]]) – A list of acceptable input name for HTTP request. Default value is image
  • accept_file_extensions (string[]) – A list of acceptable image extensions. Default value is [.jpg, .jpeg, .png]
  • accept_multiple_files (boolean) – Accept multiple files in single request or not. Default value is False
  • 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#png-pil
Raises:

ImportError – imageio package is required to use ImageHandler

FastaiImageHandler

class bentoml.handlers.FastaiImageHandler(input_name=None, accept_file_extensions=None, convert_mode=None, div=True, cls=None, after_open=None)

Transform incoming image data to fastai.vision.Image

Handle incoming image data, process them into fastai.vision.Image instance and pass down to user defined API functions

Parameters:
  • input_name ([str]]) – A list of acceptable input name for HTTP request. Default value is image
  • accept_file_extensions ([str]) – A list of acceptable image extensions. Default value is [.jpg, .jpeg, .png]
  • accept_multiple_files (boolean) – Accept multiple files in single request or not. Default value is False
  • 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#png-pil
  • 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