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 extendbaseexperimentto 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"}
}
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},
"artifacts": "path/to/local/artifact_dir_or_file",
"model_local_path": "path/to/saved_model",
"model_name": "my_registered_model"
}
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlops_wrapper-0.1.4.tar.gz.
File metadata
- Download URL: mlops_wrapper-0.1.4.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18e63c6af244ead2d768b86ce94a2ebd815a61d1ff9502e9944029fc2dfb673a
|
|
| MD5 |
5df64e5b954c9b2c2155fe180ddbdfef
|
|
| BLAKE2b-256 |
6b6a878ff359ff94ae14d44f8a43c58e125ae033cb97c6b8160bbf6e4c80196b
|
File details
Details for the file mlops_wrapper-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mlops_wrapper-0.1.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e50d3fb6df8cc14c7f6160e29b8352948effd958847fd9dd0541a2aaa4adbb31
|
|
| MD5 |
dcfc1bdcf81ad4081999080d71866f28
|
|
| BLAKE2b-256 |
1141c2d4f60630ef911431707df86c09b24272861e56407e658f31a20149ee5b
|