MLflow REST API client

Summary

Main class

Experiment

list_experiments

List all existing experiments in MLflow database

list_experiments_iterator

Iterate by all existing experiments in MLflow database

get_experiment

Get experiment by its id

get_experiment_id

Get experiment id by name

get_experiment_by_name

Get experiment by its name

get_or_create_experiment

Get existing experiment by name or create new one

create_experiment

Create experiment

rename_experiment

Rename experiment

delete_experiment

Delete experiment

restore_experiment

Restore experiment

set_experiment_tag

Set experiment tag

Run

list_experiment_runs

List experiments runs

list_experiment_runs_iterator

Iterate by experiment runs

search_runs

Search for runs

search_runs_iterator

Iterate by runs

get_run

Get run by ID

create_run

Create run

set_run_status

Set run status

start_run

Change run status to STARTED

schedule_run

Change run status to SCHEDULED

finish_run

Change run status to FINISHED

fail_run

Change run status to FAILED

kill_run

Change run status to KILLED

delete_run

Delete run

restore_run

Restore run

log_run_parameter

Add or update run parameter value

log_run_parameters

Add or update run parameters

log_run_metric

Add or update run metric value

log_run_metrics

Add or update run parameters

log_run_batch

Add or update run parameters, mertics or tags withit one request

log_run_model

Add or update run model description

set_run_tag

Set run tag

set_run_tags

Set run tags

delete_run_tag

Delete run tag

delete_run_tags

Delete run tags

Run metrics

list_run_metric_history

List metric history

list_run_metric_history_iterator

Iterate by metric history

Run artifacts

list_run_artifacts

List run artifacts

list_run_artifacts_iterator

Iterate by run artifacts

Model

list_models

List models

list_models_iterator

Iterate by models

search_models

Search for models

search_models_iterator

Iterate models found by search query

get_model

Get model by name

get_or_create_model

Get existing model by name or create new one

create_model

Create model

rename_model

Rename model

set_model_description

Set model description

delete_model

Delete model

set_model_tag

Set model tag

delete_model_tag

Delete model tag

Model version

list_model_versions

List model versions (only latest version of each stage)

list_model_versions_iterator

Iterate by models versions (only latest version of each stage)

list_model_all_versions

List model versions (all versions of each stage)

list_model_all_versions_iterator

Iterate by models versions (all versions of each stage)

search_model_versions

Search for model versions

search_model_versions_iterator

Iterate by model versions

get_model_version

Get model version

get_model_version_download_url

Get download URL for model artifact by version

create_model_version

Create model version

set_model_version_description

Set model version description

delete_model_version

Delete model version

set_model_version_tag

Set model version tag

delete_model_version_tag

Delete model version tag

transition_model_version_stage

Transition model version between stages

test_model_version

Change model version stage to Staging

promote_model_version

Change model version stage to Production

archive_model_version

Change model version stage to Archived

Documentation

class mlflow_rest_client.mlflow_rest_client.MLflowRESTClient(api_url, user=None, password=None, token=None, ignore_ssl_check=False)

Client for MLflow REST API

Parameters
api_urlstr

MLflow URL

Example:

http://some.domain:5000

userstr, optional

MLflow user name (if exist)

passwordstr, optional

MLflow user password (if exist)

tokenstr, optional

MLflow user token (if exist)

ignore_ssl_checkbool

If True, skip SSL verify step

Examples

client = MLflowRESTClient(url="http://some.domain:5000")
client_with_basic_auth = MLflowRESTClient(
    url="http://some.domain:5000",
    user="abc",
    password="cde",
)
client_with_token_auth = MLflowRESTClient(
    url="http://some.domain:5000",
    token="68036ad49a92d53d02cc10ddf5ec2802",
)
client_without_ssl_check = MLflowRESTClient(
    url="http://some.domain:5000",
    ignore_ssl_check=True,
)
archive_model_version(name, version, **params)

Change model version stage to Archived

Parameters
namestr

Model name

version: int

Version number

Returns
model_versionmlflow_rest_client.model.ModelVersion

Updated model version

Examples

model_version = client.archive_model_version("some_run_id", 1)
Return type

ModelVersion

create_experiment(name, artifact_location=None)

Create experiment

Parameters
namestr

Experiment name

artifact_locationstr, optional

Path for artifacts

Returns
experiment:obj:mlflow_rest_client.experiment.Experiment

New experiment

Examples

experiment = client.create_experiment("some_experiment")

experiment = client.create_experiment("some_experiment", artifact_location="some/path")
Return type

Experiment

create_model(name, tags=None)

Create model

Parameters
namestr

Model name

tagsdict, list of dict, optional

List of run tags

Returns
model:obj:mlflow_rest_client.modelModel

New model

Examples

model = client.create_model("some_model")

tags = {"some": "tag"}
# or
tags = [{"key": "some", "value": "tag"}]
model = client.create_model("some_model", tags=tags)
Return type

Model

create_model_version(name, source=None, run_id=None, tags=None)

Create model version

Parameters
namestr

Model name

sourcestr

Model version source path

run_idstr

Run ID used for generating model

tagsdict, list of dict, optional

List of model tags

Returns
model_versionmlflow_rest_client.model.ModelVersion

ModelVersion

Examples

name = "some_model"
model_version = client.create_model_version(name)

source = "my_script.py"
model_version = client.create_model_version(name, source=source)

run_id = "some_run_id"
model_version = client.create_model_version(name, run_id=run_id)

tags = {"some": "tag"}
# or
tags = [{"key": "some", "value": "tag"}]
model_version = client.create_model_version(name, tags=tags)
Return type

ModelVersion

create_run(experiment_id, start_time=None, tags=None)

Create run

Parameters
experiment_idint

Experiment ID

start_timeint or datetime.datetime, optional

Start time

tagsdict, list of dict, optional

List of run tags

Returns
runmlflow_rest_client.run.Run

Run

Examples

experiment_id = 123
run = client.create_run(experiment_id)
run = client.create_run(experiment_id, start_time=datetime.datetime.now())

tags = {"some": "tag"}
# or
tags = [{"key": "some", "value": "tag"}]
run = client.create_run(experiment_id, tags=tags)
Return type

Run

delete_experiment(experiment_id)

Delete experiment

Parameters
experiment_idint

Experiment ID

Examples

client.delete_experiment(123)
Return type

None

delete_model(name)

Delete model

Parameters
namestr

Model name

Examples

client.delete_model("some_model")
Return type

None

delete_model_tag(name, key)

Delete model tag

Parameters
namestr

Model name

keystr

Tag name

Examples

client.delete_model_tag("some_model", "some.tag")
delete_model_version(name, version)

Delete model version

Parameters
namestr

Model name

version: int

Version number

Examples

client.delete_model_version("some_model", 1)
Return type

None

delete_model_version_tag(name, version, key)

Delete model version tag

Parameters
namestr

Model name

version: int

Version number

keystr

Tag name

Examples

client.delete_model_version_tag("some_model", 1, "some.tag")
Return type

None

delete_run(run_id)

Delete run

Parameters
run_idUUID

Run ID

Examples

client.delete_run("some_run_id")
Return type

None

delete_run_tag(run_id, key)

Delete run tag

Parameters
run_idUUID

Run ID

keystr

Tag name

Examples

client.delete_run_tag("some_run_id", "some.tag")
Return type

None

delete_run_tags(run_id, keys)

Delete run tags

Parameters
run_idstr

Run ID

tags:obj:dict, list of dict

Run tags list

Examples

run_tags = {"some": "tag"}
# or
run_tags = [{"key": "some", "value": "param"}]

client.delete_run_tags("some_run_id", run_tags)
fail_run(run_id, end_time=None)

Change run status to FAILED

Parameters
run_idstr

Run ID

end_timeint or datetime.datetime, optional

End time

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.fail_run("some_run_id")
run_info = client.fail_run("some_run_id", end_time=datetime.datetime.now())
Return type

RunInfo

finish_run(run_id, end_time=None)

Change run status to FINISHED

Parameters
run_idstr

Run ID

end_timeint or datetime.datetime, optional

End time

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.finish_run("some_run_id")
run_info = client.finish_run("some_run_id", end_time=datetime.datetime.now())
Return type

RunInfo

get_experiment(experiment_id)

Get experiment by its id

Parameters
experiment_idint

Experiment ID

Returns
experiment:obj:mlflow_rest_client.experiment.Experiment

Experiment

Examples

experiment = client.get_experiment(123)
Return type

Experiment

get_experiment_by_name(name)

Get experiment by its name

Parameters
namestr

Experiment name

Returns
experiment:obj:mlflow_rest_client.experiment.Experiment or None

Experiment, if exists

Examples

experiment = client.get_experiment_by_name("some_experiment")
Return type

Experiment | None

get_experiment_id(name)

Get experiment id by name

Parameters
namestr

Experiment name

Returns
idstr or None

Experiment ID, if exists

Examples

experiment_id = client.get_experiment_id("some_experiment")
Return type

int | None

get_model(name)

Get model by name

Parameters
name: str

Model name

Returns
modelmlflow_rest_client.run.Model

Model

Examples

model = client.get_model("some_model")
Return type

Model

get_model_version(name, version)

Get model version

Parameters
name: str

Model name

version: int

Version number

Returns
model_versionmlflow_rest_client.run.ModelVersion

ModelVersion

Examples

model_version = client.get_model_version("some_model", 1)
Return type

ModelVersion

get_model_version_download_url(name, version)

Get download URL for model artifact by version

Parameters
namestr

Model name

version: int

Version number

Returns
download_url: str

Artifact URL

Examples

download_url = client.get_model_version_download_url("some_model", 1)
Return type

str | None

get_or_create_experiment(name, artifact_location=None)

Get existing experiment by name or create new one

Parameters
namestr

Experiment name

artifact_locationstr, optional

Path for artifacts

Returns
experimentmlflow_rest_client.experiment.Experiment

New or existing experiment

Examples

experiment = client.get_or_create_experiment("some_experiment")
Return type

Experiment

get_or_create_model(name, tags=None)

Get existing model by name or create new one

Parameters
namestr

Model name

tagsdict, list of dict, optional

List of run tags

Returns
model:obj:mlflow_rest_client.modelModel

New or existing model

Examples

model = client.get_or_create_model("some_model")

tags = {"some": "tag"}
# or
tags = [{"key": "some", "value": "tag"}]
model = client.get_or_create_model("some_model", tags=tags)
Return type

Model

get_run(run_id)

Get run by ID

Parameters
run_idstr

Run ID

Returns
runmlflow_rest_client.run.Run

Run

Examples

run = client.get_run("some_run_id")
Return type

Run

kill_run(run_id, end_time=None)

Change run status to KILLED

Parameters
run_idstr

Run ID

end_timeint or datetime.datetime, optional

End time

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.kill_run("some_run_id")
run_info = client.kill_run("some_run_id", end_time=datetime.datetime.now())
Return type

RunInfo

list_experiment_runs(experiment_id)

List experiments runs

Parameters
experiment_idint

Experiment ID

Returns
runslist of mlflow_rest_client.run.Run

Runs list

Examples

runs = client.list_experiment_runs(123)
list_experiment_runs_iterator(experiment_id)

Iterate by experiment runs

Parameters
experiment_idint

Experiment ID

Returns
runsIterator of mlflow_rest_client.run.Run

Runs iterator

Examples

for run in client.list_experiment_runs_iterator(123):
    print(run)
Return type

Iterator

list_experiments(view_type=RunViewType.ACTIVE)

List all existing experiments in MLflow database

Parameters
view_typemlflow_rest_client.run.RunViewType, optional

View type

Returns
experiments_list:obj:mlflow_rest_client.experiment.ExperimentList

Experiments list

Examples

experiments_list = client.list_experiments()
list_experiments_iterator(view_type=RunViewType.ACTIVE)

Iterate by all existing experiments in MLflow database

Parameters
view_typemlflow_rest_client.run.RunViewType, optional

View type

Returns
experiments_iterator:obj:Iterator of mlflow_rest_client.experiment.Experiment

Experiments iterator

Examples

for experiment in client.list_experiments_iterator():
    print(experiment)
Return type

Iterator[Experiment]

list_model_all_versions(name, stages=None)

List model versions (all versions of each stage)

Parameters
namestr

Model name

stageslist of mlflow_rest_client.model.ModelVersionStage or list of str, optional

Model stages to fetch

Returns
model_versions_listmlflow_rest_client.model.ModelVersionList

Model versions list

Examples

model_versions_list = client.list_model_all_versions("some_model")
model_versions_list = client.list_model_all_versions(
    "some_model", stages=[ModelVersionStage.PROD]
)
Return type

ListableModelVersion

list_model_all_versions_iterator(name, stages=None)

Iterate by models versions (all versions of each stage)

Parameters
namestr

Model name

stageslist of mlflow_rest_client.model.ModelVersionStage or list of str, optional

Model stages to fetch

Returns
model_versions_iteratorIterator or mlflow_rest_client.model.ModelVersion

Model versions iterator

Examples

for model_version in client.list_model_all_versions_iterator("some_model"):
    print(model_version)

for model_version in client.list_model_all_versions_iterator(
    "some_model", stages=[ModelVersionStage.PROD]
):
    print(model_version)
Return type

Iterator

list_model_versions(name, stages=None)

List model versions (only latest version of each stage)

Parameters
namestr

Model name

stageslist of mlflow_rest_client.model.ModelVersionStage or list of str, optional

Model stages to fetch

Returns
model_versions_listmlflow_rest_client.model.ModelVersionList

Model versions list

Examples

model_versions_list = client.list_model_versions("some_model")
model_versions_list = client.list_model_versions(
    "some_model", stages=[ModelVersionStage.PROD]
)
Return type

ListableModelVersion

list_model_versions_iterator(name, stages=None)

Iterate by models versions (only latest version of each stage)

Parameters
namestr

Model name

stageslist of mlflow_rest_client.model.ModelVersionStage or list of str, optional

Model stages to fetch

Returns
model_versions_iteratorIterator or mlflow_rest_client.model.ModelVersion

Model versions iterator

Examples

for model_version in client.list_model_versions_iterator("some_model"):
    print(model_version)

for model_version in client.list_model_versions_iterator(
    "some_model", stages=[ModelVersionStage.PROD]
):
    print(model_version)
Return type

Iterator

list_models(max_results=100, page_token=None)

List models

Parameters
max_resultsint, optional

Max results to return

page_tokenstr, optional

Previous page token, to start search from next page

Returns
models_pagemlflow_rest_client.page.Page of mlflow_rest_client.model.Model

Models page

Examples

models_page = client.list_models()
models_page = client.list_models(max_results=1000)
models_page = client.list_models(page_token="next_page_id")
Return type

Page

list_models_iterator(max_results=100, page_token=None)

Iterate by models

Like list_models, but automatically fetches next page while iteration, until no pages left.

Parameters
max_resultsint, optional

Max results to return

page_tokenstr, optional

Previous page token, to start search from next page

Returns
modelsIterator of mlflow_rest_client.model.Model

Models iterator

Examples

for model in client.list_models():
    print(model)

for model in client.list_models(max_results=1000):
    print(model)

for model in client.list_models(page_token="next_page_id"):
    print(model)
Return type

Iterator

list_run_artifacts(run_id, path=None, page_token=None)

List run artifacts

Parameters
run_idUUID

Run ID

pathstr, optional

Artifacts path to search (can contain *)

page_tokenstr, optional

Previous page token, to start search from next page

Returns
artifacts_page:obj:mlflow_rest_client.page.Page of mlflow_rest_client.artifact.Artifact

Artifacts page

Examples

artifacts_page = client.list_run_artifacts("some_run_id")
artifacts_page = client.list_run_artifacts("some_run_id", path="some/path/*")
artifacts_page = client.list_run_artifacts("some_run_id", page_token="next_page_id")
Return type

Page

list_run_artifacts_iterator(run_id, path=None, page_token=None)

Iterate by run artifacts

Like list_run_artifacts, but automatically fetches next page while iteration, until no pages left.

Parameters
run_idstr

Run ID

pathstr, optional

Artifacts path to search (can contain *)

page_tokenstr, optional

Previous page token, to start search from next page

Returns
artifacts:obj:Iterator of mlflow_rest_client.artifact.Artifact

Artifacts iterator

Examples

for artifact in client.list_run_artifacts_iterator("some_run_id"):
    print(artifact)

for artifact in client.list_run_artifacts_iterator("some_run_id", path="some/path/*"):
    print(artifact)

for artifact in client.list_run_artifacts_iterator(
    "some_run_id", page_token="next_page_id"
):
    print(artifact)
Return type

Iterator[Artifact]

list_run_metric_history(run_id, key)

List metric history

Parameters
run_idUUID

Run ID

keystr

Metric name

Returns
metrics:obj:mlflow_rest_client.run.Metric

Metrics list

Examples

metrics_list = client.list_run_metric_history("some_run_id", "some.metric")
list_run_metric_history_iterator(run_id, key)

Iterate by metric history

Parameters
run_idstr

Run ID

keystr

Metric name

Returns
metrics:obj:Iterator of mlflow_rest_client.run.Metric

Metrics iterator

Examples

for metric in client.list_run_metric_history_iterator("some_run_id", "some.metric"):
    print(metric)
Return type

Iterator[Metric]

log_run_batch(run_id, params=None, metrics=None, timestamp=None, tags=None)

Add or update run parameters, mertics or tags withit one request

Parameters
run_idUUID

Run ID

paramsdict or list of dict, optional

Params list

metricsdict or list of dict, optional

Metrics list

timestampint or datetime.datetime, optional

Run tags Default timestamp for metric

tagsdict or list of dict, optional

Run tags list

Examples

params = {"some": "param"}
# or
params = [{"key": "some", "value": "param"}]
client.log_run_batch("some_run_id", params=params)

metrics = {"some": 0.1}
# or
metrics = [
    {"key": "some", "value": 0.1, "step": 0, "timestamp": datetime.datetime.now()}
]
client.log_run_batch("some_run_id", metrics=metrics)

metrics = {"some": 0.1}
# or
metrics = [{"key": "some", "value": 0.1, "step": 0}]
client.log_run_batch("some_run_id", metrics=metrics, timestamp=datetime.datetime.now())

run_tags = {"some": "tag"}
# or
run_tags = [{"key": "some", "value": "param"}]

client.log_run_batch("some_run_id", tags=run_tags)
Return type

None

log_run_metric(run_id, key, value, step=0, timestamp=None)

Add or update run metric value

Parameters
run_idUUID

Run ID

keystr

Metric name

valuefloat

Metric value

stepint, optional

Metric step (default: 0)

timestampint or datetime.datetime, optional

Metric timestamp

Examples

client.log_run_metric("some_run_id", "some.metric", 123)
client.log_run_metric("some_run_id", "some.metric", 123, step=2)
client.log_run_metric(
    "some_run_id", "some.metric", 123, timestamp=datetime.datetime.now()
)
Return type

None

log_run_metrics(run_id, metrics, timestamp=None)

Add or update run parameters

Parameters
run_idstr

Run ID

metricsdict or list of dict

Metrics

timestampint or datetime.datetime, optional

Metric timestamp

Examples

metrics = {"some": 0.1}
# or
metrics = [
    {"key": "some", "value": 0.1, "step": 0, "timestamp": datetime.datetime.now()}
]
client.log_run_metrics("some_run_id", metrics)
Return type

None

log_run_model(run_id, model)

Add or update run model description

Parameters
run_idUUID

Run ID

modeldict

MLmodel JSON description

Examples

model = {
    "flavors": {
        "sklearn": {"sklearn_version": "0.19.1", "pickled_model": "model.pkl"},
        "python_function": {"loader_module": "mlflow.sklearn"},
    }
}

client.log_run_model("some_run_id", model)
Return type

None

log_run_parameter(run_id, key, value)

Add or update run parameter value

Parameters
run_idUUID

Run ID

keystr

Parameter name

valuestr

Parameter value

Examples

client.log_run_parameter("some_run_id", "some.param", "some_value")
Return type

None

log_run_parameters(run_id, params)

Add or update run parameters

Parameters
run_idstr

Run ID

paramsdict or list of dict

Parameters

Examples

params = {"some": "param"}
# or
params = [{"key": "some", "value": "param"}]
client.log_run_parameters("some_run_id", params)
Return type

None

promote_model_version(name, version, **params)

Change model version stage to Production

Parameters
namestr

Model name

version: int

Version number

archive_existingbool, optional

If True, previous model versions should be archived

Returns
model_versionmlflow_rest_client.model.ModelVersion

Updated model version

Examples

model_version = client.promote_model_version("some_run_id", 1)
model_version = client.promote_model_version("some_run_id", 1, archive_existing=True)
Return type

ModelVersion

rename_experiment(experiment_id, new_name)

Rename experiment

Parameters
experiment_idint

Experiment id

new_namestr

New experiment name

Examples

client.rename_experiment(123, "new_experiment")
Return type

None

rename_model(name, new_name)

Rename model

Parameters
namestr

Old model name

new_namestr

New model name

Returns
model:obj:mlflow_rest_client.model.Model

Updated model

Examples

model = client.rename_model("old_model", "new_model")
Return type

Model

restore_experiment(experiment_id)

Restore experiment

Parameters
experiment_idint

Experiment ID

Examples

client.restore_experiment(123)
Return type

None

restore_run(run_id)

Restore run

Parameters
run_idUUID

Run ID

Examples

client.restore_run("some_run_id")
Return type

None

schedule_run(run_id)

Change run status to SCHEDULED

Parameters
run_idstr

Run ID

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.schedule_run("some_run_id")
Return type

RunInfo

search_model_versions(query, max_results=None, order_by=None, page_token=None)

Search for model versions

Parameters
querystr

Query to search

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
model_versions_page:obj:mlflow_rest_client.page.Page of mlflow_rest_client.model.ModelVersion

Model versions page

Examples

query = "name='some_model'"

model_versions_page = client.search_model_versions(query)

order_by = ["name", "version ASC"]
model_versions_page = client.search_model_versions(query, order_by=order_by)

model_versions_page = client.search_model_versions(query, max_results=100)
model_versions_page = client.search_model_versions(query, page_token="next_page_id")
Return type

Page

search_model_versions_iterator(query, max_results=100, order_by=None, page_token=None)

Iterate by model versions

Like search_model_versions, but automatically fetches next page while iteration, until no pages left.

Parameters
querystr

Query to search

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
model_versions_iterator:obj:Iterator of mlflow_rest_client.model.ModelVersion

Model versions iterator

Examples

query = "name='some_model'"

for model_versions in client.search_model_versions(query):
    print(page)

order_by = ["name", "version ASC"]
for model_versions in client.search_model_versions_iterator(query, order_by=order_by):
    print(page)

for model_versions in client.search_model_versions_iterator(query, max_results=100):
    print(page)
for model_versions in client.search_model_versions_iterator(
    query, page_token="next_page_id"
):
    print(page)
search_models(query, max_results=None, order_by=None, page_token=None)

Search for models

Parameters
querystr

Query to search

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
models_page:obj:mlflow_rest_client.page.Page of mlflow_rest_client.model.Model

Models page

Examples

query = "name = 'some_model%'"  # or "name LIKE "some-model%"'

models_page = client.search_models(query)

order_by = ["name", "version ASC"]
models_page = client.search_models(query, order_by=order_by)

models_page = client.search_models(query, max_results=100)
models_page = client.search_models(query, page_token="next_page_id")
Return type

Page

search_models_iterator(query, max_results=100, order_by=None, page_token=None)

Iterate models found by search query

Like search_models, but automatically fetches next page while iteration, until no pages left.

Parameters
querystr

Query to search

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
models:obj:Iterator of mlflow_rest_client.model.Model

Models iterator

Examples

query = "name = 'some_model%'"  # or "name LIKE "some-model%"'

for model in client.search_models_iterator(query):
    print(model)

order_by = ["name", "version ASC"]
for model in client.search_models_iterator(query, order_by=order_by):
    print(model)

for model in client.search_models_iterator(query, max_results=100):
    print(model)

for model in client.search_models_iterator(query, page_token="next_page_id"):
    print(model)
search_runs(experiment_ids, query='', run_view_type=RunViewType.ACTIVE, max_results=100, order_by=None, page_token=None)

Search for runs

Parameters
experiment_idslist of int

Experiment IDS

querystr, optional

Query to search

run_view_typemlflow_rest_client.run.RunViewType, optional

View type

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
runs_page:obj:mlflow_rest_client.page.Page of mlflow_rest_client.run.Run

Runs page

Examples

experiment_ids = [123]

runs_page = client.search_runs(experiment_ids)

query = "metrics.rmse < 1 and params.model_class = 'LogisticRegression'"
runs_page = client.search_runs(experiment_ids, query=query)

order_by = ["name", "version ASC"]
runs_page = client.search_runs(experiment_ids, order_by=order_by)

runs_page = client.search_runs(experiment_ids, run_view_type=RunViewType.ALL)
runs_page = client.search_runs(experiment_ids, max_results=100)
runs_page = client.search_runs(experiment_ids, page_token="next_page_id")
search_runs_iterator(experiment_ids, query='', run_view_type=RunViewType.ACTIVE, max_results=100, order_by=None, page_token=None)

Iterate by runs

Like search_runs, but automatically fetches next page while iteration, until no pages left.

Parameters
experiment_idslist of int

Experiment IDS

querystr, optional

Query to search

run_view_typemlflow_rest_client.run.RunViewType, optional

View type

max_resultsint, optional

Max results to return

order_bylist of str, optional

Order by expression

page_tokenstr, optional

Previous page token, to start search from next page

Returns
runs:obj:Iterator of mlflow_rest_client.run.Run

Runs iterator

Examples

experiment_ids = [123]

for run in client.search_runs_iterator(experiment_ids):
    print(run)

query = "metrics.rmse < 1 and params.model_class = 'LogisticRegression'"
for run in client.search_runs_iterator(experiment_ids, query=query):
    print(run)

order_by = ["name", "version ASC"]
for run in client.search_runs_iterator(experiment_ids, order_by=order_by):
    print(run)

for run in client.search_runs_iterator(experiment_ids, run_view_type=RunViewType.ALL):
    print(run)

for run in client.search_runs_iterator(experiment_ids, max_results=100):
    print(run)

for run in client.search_runs_iterator(experiment_ids, page_token="next_page_id"):
    print(run)
set_experiment_tag(experiment_id, key, value)

Set experiment tag

Parameters
experiment_idint

Experiment ID

keystr

Tag name

valuestr

Tag value

Examples

client.set_experiment_tag(123, "some.tag", "some.value")
Return type

None

set_model_description(name, description)

Set model description

Parameters
namestr

Old model name

descriptionstr

New model description

Returns
model:obj:mlflow_rest_client.model.Model

Updated model

Examples

model = client.set_model_description("some_model", "new description")
Return type

Model

set_model_tag(name, key, value)

Set model tag

Parameters
namestr

Model name

keystr

Tag name

valuestr

Tag value

Examples

client.set_model_tag("some_model", "some.tag", "some.value")
Return type

None

set_model_version_description(name, version, description)

Set model version description

Parameters
namestr

Old model name

version: int

Version number

descriptionstr

New model version description

Returns
model_version:obj:mlflow_rest_client.model.ModelVersion

Updated model version

Examples

model_version = client.set_model_version_description("some_model", 1, "new description")
Return type

ModelVersion

set_model_version_tag(name, version, key, value)

Set model version tag

Parameters
namestr

Model name

version: int

Version number

keystr

Tag name

valuestr

Tag value

Examples

client.set_model_version_tag("some_model", 1, "some.tag", "some.value")
Return type

None

set_run_status(run_id, status, end_time=None)

Set run status

Parameters
run_idstr

Run ID

statusstr or mlflow_rest_client.run.RunStatus

Run status

end_timeint or datetime.datetime, optional

End time

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.set_run_status("some_run_id", "FAILED")
run_info = client.set_run_status("some_run_id", RunStatus.FAILED)
run_info = client.set_run_status(
    "some_run_id", RunStatus.FINISHED, end_time=datetime.datetime.now()
)
Return type

RunInfo

set_run_tag(run_id, key, value)

Set run tag

Parameters
run_idUUID

Run ID

keystr

Tag name

valuestr

Tag value

Examples

client.set_run_tag("some_run_id", "some.tag", "some.value")
Return type

None

set_run_tags(run_id, tags)

Set run tags

Parameters
run_idstr

Run ID

tags:obj:dict, list of dict

Run tags list

Examples

run_tags = {"some": "tag"}
# or
run_tags = [{"key": "some", "value": "param"}]

client.set_run_tags("some_run_id", run_tags)
Return type

None

start_run(run_id)

Change run status to STARTED

Parameters
run_idstr

Run ID

Returns
run_infomlflow_rest_client.run.Runinfo

Run info

Examples

run_info = client.start_run("some_run_id")
Return type

RunInfo

test_model_version(name, version, **params)

Change model version stage to Staging

Parameters
namestr

Model name

version: int

Version number

archive_existingbool, optional

If True, previous model versions should be archived

Returns
model_versionmlflow_rest_client.model.ModelVersion

Updated model version

Examples

model_version = client.test_model_version("some_run_id", 1)
model_version = client.test_model_version("some_run_id", 1, archive_existing=True)
Return type

ModelVersion

transition_model_version_stage(name, version, stage, archive_existing=False)

Transition model version between stages

Parameters
namestr

Model name

version: int

Version number

stagestr or mlflow_rest_client.model.ModelVersionStage

Model version state

archive_existingbool, optional

If True, previous model versions should be archived

Returns
model_versionmlflow_rest_client.model.ModelVersion

Updated model version

Examples

model_version = client.transition_model_version_stage("some_run_id", 1, "Production")
model_version = client.transition_model_version_stage(
    "some_run_id", 1, ModelVersionStage.PROD
)
model_version = client.transition_model_version_stage(
    "some_run_id", 1, ModelVersionStage.PROD, archive_existing=True
)
Return type

ModelVersion