Skip to main content

a unified mlflow wrapper for standardized ML model logging and registration.

Project description

mlops-wrapper

custom python wrapper around mlflow

a unified mlflow wrapper that standardizes experiment tracking, artifact logging, and model registration across teams and projects. by providing decorators and base classes, this wrapper reduces boilerplate code and enforces best practices for mlflow usage.

why use this wrapper?

  • simplify mlflow usage: no need to manually start/stop mlflow runs or remember to log parameters/metrics/artifacts each time.
  • built-in flexibility: pass a single flag to enable autologging or choose to manually specify which details get logged.
  • extendable: easily add custom tags or additional params by returning them in a dictionary from your decorated function.
  • consistent experiment tracking: standardize how your team logs experiments, making it easier to compare runs and share best practices.

features

  • consistent logging: standardized interface for logging parameters, metrics, and artifacts.
  • model registry integration: automatically register models in mlflow’s model registry.
  • decorator & base class: use a python decorator (@mlflow_experiment) or extend baseexperiment to minimize boilerplate code.
  • error handling: automatically logs exceptions and ensures mlflow runs are closed gracefully.

quick start

do the following:

install the package:

pip install mlops-wrapper

then import it mlops_wrapper.mlflow_wrapper import mlflow_experiment

then decorate your training function with the @mlflow_experiment decorator

for autologging

with autologging enabled, the mlflow will automatically log all parameters, metrics, and artifacts from your training function with its intelligence. you can also pass extra/custom tags/params to be logged by returning them in a dictionary from your training function.

note: you cannot override the parameters/metrics logged by autologging, but you can add extra tags/params.

supported autologging libraries: refer to mlflow documentation

@mlflow_experiment(
    experiment_name="my_experiment",
    run_name_prefix="demo_run",
    tracking_uri="http://localhost:5000", 
    autolog_enabled=True,
    autolog_config={"log_models": True}
)
def train_my_model():
    ### your training logic here
    train_accuracy = 0.95
    test_accuracy = 0.90

    # optionally return extra tags/params for logging this works even for autolog=True
    return {
        "params": {"max_depth": 5, "n_estimators": 100},
        "metrics": {"train_accuracy": train_accuracy, "test_accuracy": test_accuracy},
        "tags": {"model_type": "random_forest"},
        "artifacts": "path/to/local/artifact_dir_or_file",
        "model_local_path": "path/to/saved_model",
        "model_name": "my_registered_model"
    }

if __name__ == "__main__":
    train_my_model()
  • run mlflow ui in your terminal and open http://localhost:5000 (adjust as needed).
  • you will see an experiment named my_experiment with your run logs, including any parameters and metrics.

for manual logging

@mlflow_experiment("your-manual-experiment-name")
def train_custom_model():
    # manual training code
    model = ...
    model.fit(...)
    # compute metrics, etc.
    accuracy = ...
    
    #  return a dictionary with params, metrics, and tags to be logged
    return {
        "params": {"some_param": 123},
        "metrics": {"accuracy": accuracy},
        "tags": {"special_run": True}
    }

feedback or contributions

this is a simple approach that works for some use cases. we would love your thoughts:

•	is it helpful for your projects?
•	any additional features or integrations you would like to see?
•	found a bug or have a suggestion? open an issue or submit a pull request.

hope this decorator reduces the friction of using mlflow and helps standardize your mlops workflows. thanks for checking it out!

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

mlops_wrapper-0.1.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

mlops_wrapper-0.1.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file mlops_wrapper-0.1.2.tar.gz.

File metadata

  • Download URL: mlops_wrapper-0.1.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for mlops_wrapper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 54aebfa8d75ec08c971048fb1efb963703f1acfa9f4be4692f3514b02bf38b1b
MD5 131e2cc079b61c2e44a205035c17dd59
BLAKE2b-256 d04036fcc68ffd1f33f0128896a3765bfde386f46efb7fa8f406fc6bbae5a7bc

See more details on using hashes here.

File details

Details for the file mlops_wrapper-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mlops_wrapper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for mlops_wrapper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 13b98b5514a485f4f31291cb3b69aaca7aefbe9b8a31b3241e522a0caa40732a
MD5 2549e371810f6eac3f4612257caa1d8d
BLAKE2b-256 17d60ff5a073ff317001bacfcbab8963119cc8359588f67239b02ca36b1e9ca6

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