Skip to main content

PyMLService

A FastAPI-based service for deploying machine learning models with dynamic route registration capabilities. PyMLService provides a flexible and extensible framework for serving ML models through REST APIs.

Features

  • Dynamic Route Registration: Register new endpoints dynamically using a decorator-based registry pattern
  • ML Model Support: Built-in support for tabular machine learning models (regression and classification)
  • External Route Integration: Easily extend functionality by importing external route modules
  • API Documentation: Automatic Swagger/OpenAPI documentation at /docs endpoint
  • Scikit-learn Integration: Built-in support for scikit-learn models with extensible base classes
  • CI/CD Ready: Integrated GitHub Actions workflows for testing and deployment

Installation

Prerequisites

  • Python >3.10
  • Poetry (Python package manager)

Setup

  1. Clone the repository:
git clone <repository-url>
cd mlservice
  1. Install dependencies using Poetry:
poetry install

Usage

Starting the Server

Run the server with default settings:

# Note: Even though the PyPI package is named 'pymlservice', 
# we still use the internal module name 'mlservice'
poetry run python -m mlservice.main

Custom configuration:

poetry run python -m mlservice.main --host 0.0.0.0 --port 8000 --external-routines external_routes.sklearn

Adding ML Models

  1. Create a new model class inheriting from TabRegression or TabClassification:
from mlservice.core.tabml import TabRegression
from mlservice.core.ml import model_endpoints

@model_endpoints("sklearn/ridge")
class RidgeModel(TabRegression):
    def __init__(self, params=None):
        super().__init__(params)
        self.model = Ridge(alpha=self.hyperparameters.get("alpha", 1.0))

    def _train(self, train_data, eval_data=None):
        # Implementation
        pass

    def _predict(self, data):
        # Implementation
        pass
  1. Register the model routes using the model_endpoints decorator
  2. Import the model module when starting the server

API Documentation

Access the interactive API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

Project Structure

mlservice/
├── mlservice/
│   ├── core/            # Core functionality
│   │   ├── ml.py       # Base ML model classes
│   │   ├── registry.py # Route registration system
│   │   ├── router.py   # Core router setup
│   │   └── tabml.py    # Tabular ML model support
│   └── main.py         # FastAPI application setup
├── external_routes/     # External route modules
│   ├── sklearn/        # Scikit-learn model implementations
│   └── demo/           # Example implementations
├── tests/              # Test suite
├── poetry.lock         # Lock file for dependencies
└── pyproject.toml      # Project configuration

Development

Running Tests

Run the test suite using pytest:

poetry run pytest

With coverage report:

poetry run pytest --cov

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement your changes
  4. Write or update tests
  5. Submit a pull request

License

[Add License Information]

Metadata

Release files for pymlservice 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 pymlservice 0.1.1
File Size Uploaded Provenance
pymlservice-0.1.1.tar.gz 10.0 kB With provenance Details

Built distribution (wheel)

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

Total release size: 21.5 kB

Release files / pymlservice-0.1.1.tar.gz

Download URL pymlservice-0.1.1.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f163c5a72cb3993f97c43119b808f7cfe3fa972f98c567f7530ca96eac26cd05
BLAKE2b-256 checksum
How to use checksums
70fa9e47a0fdc1c0e75688526ea347710c5f565e24e3f30182096617f518c917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.

Transparency log

Release files / pymlservice-0.1.1-py3-none-any.whl

Download URL pymlservice-0.1.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
174178109e51e1379ec6425e716478d8bedcc116349d2c079aa81094354a9adc
BLAKE2b-256 checksum
How to use checksums
6094b0e411bd4f170371bbe13ee0cb153c0caf1e7499948e2bf7f7415819d448
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.

Transparency log

Security for pymlservice 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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pymlservice-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 30, 2025.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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