Skip to main content

Modelmanager API With Insight Generation and Pycausal, MLFlow Integration, Drivers Analysis, ModelCard, Forecasting API

Project description

ModelManager Python Client

Python client wrappers for the ModelManager backend API.

This repository contains a lightweight HTTP client (built on requests) that:

  • Creates/updates/deletes usecases (projects) and models
  • Uploads datasets / model artifacts by file path
  • Supports AzureML and MLFlow workflows
  • Exposes optional governance / visualization endpoints (WIT, Netron, reports)
  • Supports versioning endpoints (Git/DVC integration)

Table of Contents

Install

This workspace does not include a top-level packaging file (e.g. pyproject.toml).

  • If you are using a published package:

    pip install mmanager
    
  • If you are using the code in this repo directly:

    • Add mmanager-test/ to your PYTHONPATH, or
    • Install from a folder that contains a setup.py (for example under versions/).

Authentication & Base URL

All requests use an Authorization header in the format:

Authorization: secret-key <YOUR_SECRET_KEY>

base_url should include scheme + host (+ port), for example:

http://localhost:8000
https://api.example.com

Quickstart

from mmanager.mmanager import Usecase, Model

secret_key = "YOUR_SECRET_KEY"
base_url = "http://localhost:8000"

usecase = Usecase(secret_key=secret_key, base_url=base_url)
model = Model(secret_key=secret_key, base_url=base_url)

# Create a usecase ("project")
usecase_resp = usecase.post_usecase({
    "name": "Fraud Detection",
    "description": "Detect fraud in transactions",
})

# Create a model (upload file paths)
model_resp = model.post_model({
    "project": "<usecase-id>",
    "transformerType": "Classification",  # also commonly: "Regression", "Forecasting"
    "datasetinsertionType": "Manual",      # "Manual", "AzureML", "MLFlow"
    "training_dataset": "/path/to/train.csv",
    "test_dataset": "/path/to/test.csv",
    "pred_dataset": "/path/to/pred.csv",
    "actual_dataset": "/path/to/truth.csv",
    "model_file_path": "/path/to/model.pkl",
    "target_column": "Class",
})

Supported Client Classes

The main client classes live in mmanager/mmanager.py:

  • Core: ModelManager
  • Usecases: Usecase
  • Models: Model
  • Database metadata: TableInfo, FieldInfo
  • External databases: ExternalDatabase (legacy), RelatedDatabase, DatabaseLink
  • Integrations: MLFlow, VersionControl
  • What-if resources: WhatIf
  • Other: Applications, ReleaseTable, LLMCreds, ModelCard

Usecases (Projects)

from mmanager.mmanager import Usecase

secret_key = "YOUR_SECRET_KEY"
base_url = "http://localhost:8000"
api = Usecase(secret_key=secret_key, base_url=base_url)

# Create
api.post_usecase({
    "name": "My Usecase",
    "description": "Short description",
})

# List (usecases uploaded by authenticated user)
api.get_usecases()

# Detail
api.get_detail(usecase_id="<usecase-id>")

# Update (supports optional 'image' and 'banner' file paths)
api.patch_usecase({"description": "Updated"}, usecase_id="<usecase-id>")

# Delete
api.delete_usecase(usecase_id="<usecase-id>")

# Models under a usecase
api.get_models(usecase_id="<usecase-id>")

# Load database cache
api.load_cache(usecase_id="<usecase-id>")

Forecasting usecase

post_usecase() accepts optional forecasting_fields and forecasting_feature_tabs when usecase_type == "Forecasting".

from mmanager.mmanager import Usecase

api = Usecase(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

usecase_info = {
    "name": "Sales Forecast",
    "usecase_type": "Forecasting",
    "author": "Jane Doe",
    "description": "Forecast future sales",
}

forecasting_fields = {
    "forecasting_template": "two_conditions",
    "notification_emails": ["jane.doe@example.com"],
}

forecasting_feature_tabs = {
    "result_tab": True,
    "series_tab": True,
    "condition_tab": True,
    "performance_tab": True,
    "ab_testing_tab": True,
    "release_tab": True,
}

api.post_usecase(usecase_info, forecasting_fields, forecasting_feature_tabs)

Models

Create (upload by file path)

Model.post_model() opens the files you pass (e.g. training_dataset) and uploads them. Ensure paths exist.

from mmanager.mmanager import Model

api = Model(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

api.post_model({
    "project": "<usecase-id>",
    "transformerType": "Classification",  # also commonly: "Regression", "Forecasting"
    "datasetinsertionType": "Manual",      # "Manual", "AzureML", "MLFlow"
    "training_dataset": "/path/to/train.csv",
    "test_dataset": "/path/to/test.csv",
    "pred_dataset": "/path/to/pred.csv",
    "actual_dataset": "/path/to/truth.csv",
    "model_file_path": "/path/to/model.pkl",
    "target_column": "Class",
})

Update / delete / detail

from mmanager.mmanager import Model

api = Model(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

api.patch_model({
    "target_column": "Class",
    "training_dataset": "/path/to/train_updated.csv",
}, model_id="<model-id>")

api.get_details(model_id="<model-id>")
api.delete_model(model_id="<model-id>")

Metrics and reports

from mmanager.mmanager import Model

api = Model(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

api.get_latest_metrics(model_id="<model-id>", metric_type="<metric-type>")
api.generate_report(model_id="<model-id>")
api.get_all_reports(model_id="<model-id>")

Database Metadata (Tables/Fields)

from mmanager.mmanager import TableInfo, FieldInfo

base = dict(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

TableInfo(**base).post_table_info({
    "table_type": "actual",
    "table_name": "daily_act2",
    "db_link": 11,
})

FieldInfo(**base).post_field_info({
    "table_id": 9,
    "display_name": "actual2",
    "field_type": "",
    "field_name": "",
})

AzureML Integration

AzureML flows use ml_options["credPath"] pointing to a JSON file. The client loads it and sends it as amlCred.

Example credential file:

{
  "subscription_id": "<subscription-id>",
  "resource_group": "<resource-group>",
  "workspace_name": "<workspace-name>",
  "tenant-id": "<tenant-id>",
  "datastore_name": "<datastore-name>"
}

Fetch from AzureML:

from mmanager.mmanager import Model

model_data = {
    "project": "<usecase-id>",
    "transformerType": "Classification",
    "datasetinsertionType": "AzureML",
    "target_column": "Class",
}

ml_options = {
    "credPath": "config.json",
    "fetchOption": ["Model"],
    "modelName": "<registered-model-name>",
    "dataPath": "<dataset-name>",
}

Model(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000").post_model(model_data, ml_options)

MLFlow Integration

  1. Create MLFlow creds
from mmanager.mmanager import MLFlow

api = MLFlow(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")
api.post_mlflow_creds({
    "name": "Test Credentials",
    "tracking_uri": "https://example.mlflow.com",
    "mlflow_s3_endpoint_url": "https://sfo3.digitaloceanspaces.com",
    "artifact_path": "pathtomodelfiles",
    "aws_access_key_id": "",
    "aws_secret_access_key": "",
    "usecase": "<usecase-id>",
})
  1. Download dataset/model pointers
from mmanager.mmanager import MLFlow

api = MLFlow(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")
resp = api.download_dataset_model(mlflow_cred_id="<mlflow-cred-id>", exp_name="<experiment-name>")
  1. Create model with datasetinsertionType == "MLFlow" and pass returned paths

What-If / Netron / Data Distribution

These endpoints return IPython.display.IFrame (intended for notebooks):

from mmanager.mmanager import Model

api = Model(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")
api.get_wit(model_id="<model-id>")
api.get_netron(model_id="<model-id>")
api.get_data_distribution(model_id="<model-id>")

Version Control (Git/DVC)

from mmanager.mmanager import VersionControl

api = VersionControl(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")

api.git_config({
    "tag": "dvc_example",
    "git_repo": "https://github.com/jhondoe/example.git",
    "git_branch": "main",
    "username": "jhondoe",
    "email": "jhondoe@gmail.com",
    "access_token": "",
    "is_active": True,
})

api.dvc_set(git_config_id="<git-config-id>")
api.get_version_tags(model_id="<model-id>", usecase_id="<usecase-id>")
api.get_version_details(tag_name="<tag>")
api.switch_data_version(model_id="<model-id>", usecase_id="<usecase-id>", tag_name="<tag>")
api.export_datasets(model_id="<model-id>", usecase_id="<usecase-id>", tag_name="<tag>")

Model Card

from mmanager.mmanager import ModelCard

api = ModelCard(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")
api.create_modelcard({"usecase_id": 118, "series": "ED Visits"})
api.create_modelcard_bulk(usecase_id="118")
api.get_modelcard_data({"usecase_id": 118, "model_id": 97})

Forecasting API

  from mmanager.mmanager import Forecasting
  payload = {
          "usecase_name": "Doe",
          "series": "ED Visits",
          "condition_one": "DRV",
          "condition_two": "1_year",
          "condition_three": "October_2025",
          "prediction_period": "7"
          }
  api = Forecasting(secret_key="YOUR_SECRET_KEY", base_url="http://localhost:8000")
  api.get_forecast(payload)

Logging

Logs are written to mmanager_log.log (rotating) and also emitted to stdout. Set the log level via:

export MMANAGER_LOG_LEVEL=DEBUG

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

mmanager-2.4.1.tar.gz (91.5 MB view details)

Uploaded Source

Built Distribution

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

mmanager-2.4.1-py3-none-any.whl (91.5 MB view details)

Uploaded Python 3

File details

Details for the file mmanager-2.4.1.tar.gz.

File metadata

  • Download URL: mmanager-2.4.1.tar.gz
  • Upload date:
  • Size: 91.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mmanager-2.4.1.tar.gz
Algorithm Hash digest
SHA256 b98d465d6d1c12f9d24e871d5ef9b2d19f6af2e64bad6b96fba51e63f4ab54f9
MD5 d80ad1f771f703bee27ccc65d927821f
BLAKE2b-256 0400dc546a780896b3f79c31a1e469b59f78c9b6e179ecf00ca6d7d254bc5ab1

See more details on using hashes here.

File details

Details for the file mmanager-2.4.1-py3-none-any.whl.

File metadata

  • Download URL: mmanager-2.4.1-py3-none-any.whl
  • Upload date:
  • Size: 91.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mmanager-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79a87f8371eef4b307f056188ba2dd00bfa7729124c604c452004b34ecff3e58
MD5 281381c05c705468b6a814a9ba676176
BLAKE2b-256 8899f9b7a95502674992c5e1c0f891d47a8fcdfc84180723fc198dba69f3547c

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 Pingdom Monitoring Sentry Error logging StatusPage Status page