Skip to main content



MLChain: Auto-Magical Deploy AI model at large scale, high performance, and easy to use

Explore the docs »

Our Website · Examples in Python

PyPI version Downloads CI codecov Documentation Status license

MLChain is a simple, easy to use library that allows you to deploy your Machine Learning model to hosting server easily and efficiently, drastically reducing the time required to build API that support an end-to-end AI product.

Key features

  • Fast: MLChain prioritize speed above other criteria.

  • Fast to code: With a finished Machine Learning model, it takes 4 minutes on average to deploy a fully functioning API with MLChain.

  • Flexible: The nature of ML-Chain allows developing end-to-end adaptive, with varied serializer and framework hosting at your choice.

  • Less debugging : We get it. Humans make mistakes. With MLChain, its configuration makes debugging a lot easier and almost unnecessary.

  • Easy to code: as a piece of cake!

  • Standards-based: Based on the open standards for APIs: OpenAPI (previously known as Swagger), along with JSON Schema and other options.

Installation

MLChain required Python 3.6 and above

PyPI

To install latest stable version of MLChain, simply run:

pip install mlchain

Build from source

If you can't wait for the next release, install the most up to date code with from master branch by running the following command:

git clone https://github.com/Techainer/mlchain-python
cd mlchain-python
pip install -r requirements.txt
python setup.py install

Or simply install using git:

pip install git+https://github.com/Techainer/mlchain-python@master --upgrade

Documentation

Read ours documentation here

Demo

Here's a minimal example of serving a dummy python class

Create a server.py file:

import cv2
import numpy as np
from mlchain.base import ServeModel


class Model():
  """ Just a dummy model """

  def predict(self, image: np.ndarray):
      """
      Resize input to 100 by 100.
      Args:
          image (numpy.ndarray): An input image.
      Returns:
          The image (np.ndarray) at 100 by 100.
      """
      image = cv2.resize(image, (100, 100))
      return image


# Define model
model = Model()

# Serve model
serve_model = ServeModel(model)

# Deploy model
if __name__ == '__main__':
    from mlchain.server import FlaskServer
    # Run flask model with upto 12 threads
    FlaskServer(serve_model).run(port=5000, threads=12)

Now run:

python server.py

And you should see something like this:

[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:424]---------------------------------------------------------------------------------
[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:425]-Served model with Flask at host=127.0.0.1, port=5000
[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:426]-Debug = False
[mlchain-logger]:[7895] [2020-08-18 09:53:02 +0700]-[INFO]-[flask_server.py:427]---------------------------------------------------------------------------------

Now you can access your API at http://localhost:5000

You can open Swagger UI at http://localhost:5000/swagger and try your API out right away

swagger

After explore all your API endpoint over there, create a client.py file:

import numpy as np
from mlchain.client import Client

model = Client(api_address='http://localhost:5000').model()
# Create a dummy input with shape (200, 200)
input_image = np.ones((200, 200), dtype=np.uint8)
# Then pass it through our client just like normal Python
result_image = model.predict(input_image)
print(result_image.shape)  # And the result should be (100, 100)

Now you have a supper simple Client to work with. Sooo easy :D

Examples

Asking for help

Welcome to the MLChain community!

If you have any questions, please feel free to:

  1. Read the docs
  2. Open an issues

We are happy to help

Metadata

Release files for mlchain 0.3.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 mlchain 0.3.1
File Size Uploaded Provenance
mlchain-0.3.1.tar.gz 1.5 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mlchain 0.3.1
File Interpreter ABI Platform
mlchain-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 MB

Release files / mlchain-0.3.1.tar.gz

Download URL mlchain-0.3.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
6b6dc244ed68b60c0b6b8f743da6b394ef590b99121e298f9c8b435b2c504b33
BLAKE2b-256 checksum
How to use checksums
481f08baf1f6705944647d863baa61f81da2688402d6d776a23c249ea17e9b28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / mlchain-0.3.1-py3-none-any.whl

Download URL mlchain-0.3.1-py3-none-any.whl
Size 5.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4aefe28c72486d1fb84a7f51b86a49e5c1e2836a250ba404e346b3e02169a158
BLAKE2b-256 checksum
How to use checksums
2fdb3a39e5a9e46f702065ffe2038a7ecdda63d6e129aab90ef89622589ba462
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for mlchain 0.3.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.

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