Skip to main content

scikit-rest

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.

Prerequisites

This package officially supports Python 3

Installing

pip install scikit_rest

Usage

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

    serve(
        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,
    )

col_list

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']

col_types

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
}

transform_fn

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

predict_fn

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

Port Number where the REST API should be served upon

is_nullable

Whether input API can be nullable

name

Name of the program

Example

Example of Usage can be found at example folder

Contributing

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

Authors

[Aditya Kelvianto Sidharta][https://adityasidharta.com]

License

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

Metadata

Release files for scikit_rest 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scikit_rest 0.1.1
File Size Uploaded Provenance Actions
scikit_rest-0.1.1.tar.gz 28.8 kB Without provenance Details for scikit_rest-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scikit_rest 0.1.1
File Interpreter ABI Platform Actions
scikit_rest-0.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for scikit_rest-0.1.1-py2.py3-none-any.whl

Total release size: 43.2 kB

Release files / scikit_rest-0.1.1.tar.gz

Download URL scikit_rest-0.1.1.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0855814cbcf827cdc66f3ff9b3905d51fba2c04cfa41ff04b9f2efa51b5e0840
BLAKE2b-256 checksum
How to use checksums
a62206a60b2ab588dadeebaf198dce565c31ee7cfe078e2d75d354fad47e61ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.18.4

Release files / scikit_rest-0.1.1-py2.py3-none-any.whl

Download URL scikit_rest-0.1.1-py2.py3-none-any.whl
Size 14.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e61eec09fcb6e124d0890ffaa3173ab578979feac37688b1ee4201b15e258e1a
BLAKE2b-256 checksum
How to use checksums
c45ff81d2750a6c969da12d2a7b6f54f2fd89bb2c497717473333c3c61b187e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.18.4

Security for scikit_rest 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page