Skip to main content

No project description provided

Project description

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]

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

pymlservice-0.1.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

pymlservice-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file pymlservice-0.1.1.tar.gz.

File metadata

  • Download URL: pymlservice-0.1.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pymlservice-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f163c5a72cb3993f97c43119b808f7cfe3fa972f98c567f7530ca96eac26cd05
MD5 0889578623d0bcedfd73d68b519b0ce8
BLAKE2b-256 70fa9e47a0fdc1c0e75688526ea347710c5f565e24e3f30182096617f518c917

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymlservice-0.1.1.tar.gz:

Publisher: github-deploy.yml on bochen0909/mlservice

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymlservice-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pymlservice-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pymlservice-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 174178109e51e1379ec6425e716478d8bedcc116349d2c079aa81094354a9adc
MD5 3319c82a4bf0519ca196e48a0ef68ce6
BLAKE2b-256 6094b0e411bd4f170371bbe13ee0cb153c0caf1e7499948e2bf7f7415819d448

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymlservice-0.1.1-py3-none-any.whl:

Publisher: github-deploy.yml on bochen0909/mlservice

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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