Edit on GitHub


Saves given object to a given path

def save(
    obj: Any,
    path: str,
    project: Optional[str] = None,
    fs: Union[str, AbstractFileSystem] = None,
    index: bool = None,
    external: Optional[bool] = None,
    params: Dict[str, str] = None,
) -> MlemObject


from mlem.api import save

save(obj, path, index=False, external=True)


Saves a given object to a given path. The path can belong to different file systems (eg: S3). The function returns and saves the object as a MLEM Object.


  • obj (required) - Object to dump
  • path (required) - If not located on LocalFileSystem, then should be uri or fs argument should be provided
  • project (optional) - path to mlem project
  • sample_data (optional) - If the object is a model or function, you can provide input data sample, so MLEM will include its schema in the model's metafile
  • fs (optional) - FileSystem for the path argument
  • index (optional) - Whether to add object to mlem project index
  • external (optional) - Save result directly to path (not inside .mlem/)
  • params (optional) - arbitrary params for object


  • MlemObjectNotFound - Thrown if we can't find MLEM object

Example: Save a trained model with MLEM

import os
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from pandas import DataFrame
from mlem.api import save

train, target = load_iris(return_X_y=True)
train = DataFrame(train)
train.columns = train.columns.astype(str)
model = DecisionTreeClassifier().fit(train, target)
path = os.path.join(os.getcwd(), "saved-model")

save(model, path, sample_data=train, index=False)

­čÉŤ Found an issue? Let us know! Or fix it:

Edit on GitHub

ÔŁô Have a question? Join our chat, we will help you:

Discord Chat