Skip to main content

Automatically serve ML model as a REST API

Project description


logo Automatically deploy your ML model as a REST API

Often times, deploying your favorite Scikit-learn / XGBoost / Pytorch / Tensorflow model as a REST API might take a lot of time. There are a lot of boilerplate codes to be written. scikit-rest is a package designed to alleviate most of the pain points within this process.


This package officially supports Python 3


pip install scikit_rest


The main function offered in this package is serve, with the following syntax:

        col_list: List[str],
        col_types: Dict[str, Union[List, type]],
        transform_fn: Callable,
        predict_fn: Union[Callable, sklearn.base.BaseEstimator],
        port: int,
        is_nullable: bool ,
        name: str,


List of Column names, where the order of the values will dictate the order within the pandas DataFrame

col_list = ['class', 'sex', 'age', 'embarked', 'date', 'is_englishman']


Dictionary of Column Names and the type of the variable, used for input Validation. If the values of the dictionary is instead a list, We assume that any input for the variable can only be any of the ones listed within the list

col_types = {
    'class' : int,
    'sex' : str,
    'age' : float,
    'embarked': ['C', 'S', 'Q'],
    'date': datetime.datetime,
    'is_englishman': bool


Function which convert the input dataframe into test dataframe, we can call model.predict upon to get the final result

def transform_fn(input_df):
    df = input_df.copy()
    df['sex'] = df['sex'].apply(lambda x : transform_sex(x))
    df['embarked'] = df['embarked'].apply(lambda x : transform_embarked(x))
    df['date'] = df['date'].dt.year
    df = df.fillna(0.)
    return df


Function which convert the test dataframe into result. If a ML model instance is passed in, we will instead try to call model.predict_proba / model.predict to get the result

def predict_fn(input_df):
    df = input_df.copy()
    return model.predict(df).item()


Port Number where the REST API should be served upon


Whether input API can be nullable


Name of the program


Example of Usage can be found at example folder


Please read for details on our code of conduct, and the process for submitting pull requests to us.


[Aditya Kelvianto Sidharta][]


This project is licensed under the MIT License - see the LICENSE file for details

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scikit_rest-0.1.1.tar.gz (28.8 kB view hashes)

Uploaded source

Built Distribution

scikit_rest-0.1.1-py2.py3-none-any.whl (14.5 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page