Skip to main content

Running Mate

PyPI version GitHub Actions Status

Version and monitor your models, record inferences, and send alerts without any additional infrastructure. Designed for small data science or machine learning teams lacking a full MLOps solution.

Training:

  1. Create local SQLite database
  2. Version model
  3. Generate baseline stats

Inference:

  1. Check features against baseline stats
  2. Create and send alerts

Getting Started

Install:

$ pip install running-mate

Running Mate stores data in a local SQLite database. Start by creating the database, creating a new Mate (which represent your AI/ML model), and generate the baseline statistics:

from mate.db import connect_db, version_or_create_mate
from mate.generators import generate_baseline_stats


connect_db()
mate = version_or_create_mate("mate-name")
generate_baseline_stats(your_dataframe, "mate-name")

This ideally happens at training time.

Then, in your serving environment, define the alert targets, get the current Mate version, load the model, wrap you model prediction in the mate context manager:

from mate.alerts import TerminalAlertTarget
from mate.db import connect_db, get_current_mate
from mate.run import RunningMate


alert_targets = [
    TerminalAlertTarget(),
]

connect_db()
version = get_current_mate("mate-name").version

model = load(f"models/mate-name-{version}.joblib")

with RunningMate("mate-name", version, your_dataframe, alert_targets):
    model.predict(enc.transform(your_dataframe))

By default, not all feature values are recorded. To record all values, set should_save_all_feature_values to True:

with RunningMate("mate-name", version, your_dataframe, alert_targets, should_save_all_feature_values=True):
    model.predict(enc.transform(df))

You can generate a summary stats report like so:

from mate.generators import generate_baseline_stats

print(generate_feature_stats_summary_report("mate-name"))

Examples

The basic example project, found in "examples/basic", uses TerminalAlertTarget, for outputting alerts to the terminal, and AlertWebhookTarget, for sending alerts to http://localhost:5000/hook.

Create/activate a virtual environment and install the dependencies:

$ cd example/basic

$ python3 -m venv venv
$ source venv/bin/activate

$ pip install -r requirements.txt

In one terminal window, run the web server:

$ cd web

$ FLASK_DEBUG=1 python -m flask run

Then, train the model and run an inference through it in a different window:

$ python train.py
$ python infer.py

Navigate to http://localhost:5000 to see the alert.

There's also a drift example in examples/drift.

Development

After cloning down the repo, create/activate a virtual environment and install the dependencies:

$ python3 -m venv venv
$ source venv/bin/activate

(venv)$ pip install -r requirements-dev.txt

Install as local package:

(venv)$ pip install -e .

Run tests:

(venv)$ python -m pytest .

Lint, format code, and type check:

(venv)$ python -m flake8 --ignore=E501,W503 mate tests examples

(venv)$ python -m black mate tests examples

(venv)$ python -m isort --profile black mate tests examples

(venv)$ python -m mypy mate tests examples

Metadata

Release files for running-mate 0.0.6

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

Source distribution (sdist)

Source distribution for running-mate 0.0.6
File Size Uploaded
running-mate-0.0.6.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for running-mate 0.0.6
File Interpreter ABI Platform
running_mate-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 25.2 kB

Release files / running-mate-0.0.6.tar.gz

Download URL running-mate-0.0.6.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
63e99685b00fb7869aa18257f48d7a4266d8cd7210341e7068bc241813bde3a9
BLAKE2b-256 checksum
How to use checksums
8f6ad924006012febd770b55cc14f04ca031d503beb33b9eb2dc5935d7137f78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release files / running_mate-0.0.6-py3-none-any.whl

Download URL running_mate-0.0.6-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a51f6c330b74651eda7975c301f542b8db4b018638b21d9ff33bab74fd5e0770
BLAKE2b-256 checksum
How to use checksums
0a651d99137473491782d950c8c2e2054333b5bf8afc68b823f95efa1d034941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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