Skip to main content

MLup logo


Linters and testing PyPI version Downloads

Introduction

MLup is a library for easy and fast running of ML models in production.

All you need is to deliver the model file to the server (a config is optional) — pymlup turns it into a FastAPI web application with one CLI command. No web app code to write or maintain.

  • Pure Python, no required framework-specific glue code;
  • Uses FastAPI for the web layer;
  • Works with any Python object that exposes a predict-like method, plus native (de)serialization support for scikit-learn, lightgbm, tensorflow, torch and onnx models.

Requirements

Python 3.10+ (3.11, 3.12, 3.13, 3.14 supported; the tensorflow extra requires Python <3.14 until TensorFlow publishes 3.14 wheels).

pymlup 0.4.0 runs on FastAPI and Pydantic v2. Python 3.8/3.9 and Pydantic v1 are still supported on the pymlup 0.3.x line.

Installation

pip install pymlup

With an ML backend extra:

pip install "pymlup[scikit-learn]"  # For scikit-learn
pip install "pymlup[lightgbm]"      # For microsoft lightgbm
pip install "pymlup[tensorflow]"    # For tensorflow
pip install "pymlup[torch]"         # For torch
pip install "pymlup[onnx]"          # For onnx models: torch, tensorflow, sklearn, etc...

Quick start

From a clean environment to a working prediction API in about five minutes, using scikit-learn as the example.

1. Create a virtual environment and install pymlup with the scikit-learn extra:

python3 -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install "pymlup[scikit-learn]"

2. Train and save a tiny model. Save this as train_model.py and run it:

# train_model.py
import pickle
from sklearn.tree import DecisionTreeClassifier

X = [[0, 0], [1, 1], [2, 2], [3, 3]]
y = [0, 0, 1, 1]

model = DecisionTreeClassifier().fit(X, y)

with open("model.pkl", "wb") as f:
    pickle.dump(model, f)
python train_model.py

3. Start the API:

mlup run -m ./model.pkl

4. Check it's alive (in another terminal):

curl http://localhost:8009/health
{"status":200}

5. Call the model:

curl -X POST http://localhost:8009/predict \
  -H "Content-Type: application/json" \
  -d '{"X": [[1, 1], [3, 3]]}'
{"predict_result":[0,1]}

6. Explore the interactive API docs. Open http://localhost:8009/docs in your browser for the Swagger UI, auto-generated from your model's predict signature — you can try /predict right there.

Stop the server with Ctrl+C.

Already have a serialized model (onnx, joblib, lightgbm, torch, tensorflow, ...) instead of training a new one? Point mlup run -m at it directly (install the matching extra from Installation) — see the full documentation for every supported format and config option.

Any Python object, no ML framework required

pymlup doesn't require a serialized model file at all — any Python object with a predict-like method works:

import mlup

class MyAnyModelForExample:
    def predict(self, X):
        return X

up = mlup.UP(ml_model=MyAnyModelForExample())
up.ml.load()
up.run_web_app(daemon=True)

Open http://localhost:8009/docs to try it, or call it from the same script — this needs pip install requests separately, it's not a pymlup dependency:

import requests
response = requests.post('http://localhost:8009/predict', json={'X': [[1, 2, 3], [4, 5, 6]]})
print(response.json())

up.stop_web_app()

Supported ML frameworks

Work tested with machine learning model frameworks (links to tests):

Support and tested with machine learning libraries:

Documentation

The full documentation — Python API, CLI reference, config file format, storages, binarizers, data transformers, web app architectures/API, application life cycle — lives at mlup.org (source: docs/).

Useful links

Metrics

MLup PyPi download statistics: https://pepy.tech/project/pymlup

Downloads Downloads Downloads

Download files

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

Source Distribution

pymlup-0.4.0.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymlup-0.4.0-py3-none-any.whl (61.1 kB view details)

Uploaded Python 3

File details

Details for the file pymlup-0.4.0.tar.gz.

File metadata

  • Download URL: pymlup-0.4.0.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for pymlup-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7aea0de395b90aeac2242d9b7bf1090b8b1afb4406e0663142dc7d49c961c734
MD5 86c2dd7c7115cf6b3a8a25b48dea42dd
BLAKE2b-256 3f452cc74d34a1c0b42d9709bb8bca817eff400cbe57263b77640afefdbf9514

See more details on using hashes here.

File details

Details for the file pymlup-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pymlup-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 61.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for pymlup-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4795be3d92cf8f0002324a1a1f5fca792a25b6718c5145083ca921d92f4e2eb
MD5 6b9f287f05f17cf8419c1f4bf9a96e85
BLAKE2b-256 c5fee33fd2c5c841c794338d87b7b6ff4f4fb7b7c422436997b7054e631043cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page