mlflow.entities
The mlflow.entities
module defines entities returned by the MLflow
REST API.
-
class
mlflow.entities.
Dataset
(name: str, digest: str, source_type: str, source: str, schema: Optional[str] = None, profile: Optional[str] = None)[source] Dataset object associated with an experiment.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
DatasetInput
(dataset: Dataset, tags: Optional[List[InputTag]] = None)[source] DatasetInput object associated with an experiment.
-
classmethod
from_proto
(proto)[source]
Array of input tags.
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
Document
(page_content: str, metadata: Dict[str, Any] = <factory>, id: Optional[str] = None)[source] An entity used in MLflow Tracing to represent retrieved documents in a RETRIEVER span.
- Parameters
page_content – The content of the document.
metadata – A dictionary of metadata associated with the document.
id – The ID of the document.
-
classmethod
from_langchain_document
(document)[source]
-
classmethod
from_llama_index_node_with_score
(node_with_score)[source]
-
to_dict
()[source]
-
class
mlflow.entities.
Experiment
(experiment_id, name, artifact_location, lifecycle_stage, tags=None, creation_time=None, last_update_time=None)[source] Experiment object.
-
classmethod
from_proto
(proto)[source]
Tags that have been set on the experiment.
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
ExperimentTag
(key, value)[source] Tag object associated with an experiment.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
FileInfo
(path, is_dir, file_size)[source] Metadata about a file or directory.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
InputTag
(key: str, value: str)[source] Input tag object associated with a dataset.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
LifecycleStage
[source] -
-
classmethod
is_valid
(lifecycle_stage)[source]
-
classmethod
matches_view_type
(view_type, lifecycle_stage)[source]
-
classmethod
view_type_to_stages
(view_type=3)[source]
-
classmethod
-
class
mlflow.entities.
LiveSpan
(otel_span: opentelemetry.trace.span.Span, request_id: str, span_type: str = 'UNKNOWN')[source] A “live” version of the
Span
class.The live spans are those being created and updated during the application runtime. When users start a new span using the tracing APIs within their code, this live span object is returned to get and set the span attributes, status, events, and etc.
-
add_event
(event: SpanEvent)[source] Add an event to the span.
- Parameters
event – The event to add to the span. This should be a
SpanEvent
object.
-
set_attribute
(key: str, value: Any)[source] Set a single attribute to the span.
-
set_attributes
(attributes: Dict[str, Any])[source] Set the attributes to the span. The attributes must be a dictionary of key-value pairs. This method is additive, i.e. it will add new attributes to the existing ones. If an attribute with the same key already exists, it will be overwritten.
-
set_inputs
(inputs: Any)[source] Set the input values to the span.
-
set_outputs
(outputs: Any)[source] Set the output values to the span.
-
set_status
(status: Union[SpanStatusCode, str])[source] Set the status of the span.
- Parameters
status – The status of the span. This can be a
SpanStatus
object or a string representing of the status code defined inSpanStatusCode
e.g."OK"
,"ERROR"
.
-
-
class
mlflow.entities.
Metric
(key, value, timestamp, step)[source] Metric object.
-
classmethod
from_dictionary
(metric_dict)[source] Create a Metric object from a dictionary.
- Parameters
metric_dict (dict) – Dictionary containing metric information.
- Returns
The Metric object created from the dictionary.
- Return type
-
classmethod
from_proto
(proto)[source]
-
to_dictionary
()[source] Convert the Metric object to a dictionary.
- Returns
The Metric object represented as a dictionary.
- Return type
dict
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
NoOpSpan
[source] No-op implementation of the Span interface.
This instance should be returned from the mlflow.start_span context manager when span creation fails. This class should have exactly the same interface as the Span so that user’s setter calls do not raise runtime errors.
E.g.
with mlflow.start_span("span_name") as span: # Even if the span creation fails, the following calls should pass. span.set_inputs({"x": 1}) # Do something
-
end
()[source]
-
set_attribute
(key: str, value: Any)[source]
-
set_attributes
(attributes: Dict[str, Any])[source]
-
set_inputs
(inputs: Dict[str, Any])[source]
-
set_outputs
(outputs: Dict[str, Any])[source]
-
set_status
(status: SpanStatus)[source]
-
-
class
mlflow.entities.
Param
(key, value)[source] Parameter object.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
Run
(run_info: RunInfo, run_data: RunData, run_inputs: Optional[RunInputs] = None)[source] Run object.
-
classmethod
from_proto
(proto)[source]
-
to_dictionary
() → Dict[Any, Any][source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
RunData
(metrics=None, params=None, tags=None)[source] Run data (metrics and parameters).
-
classmethod
from_proto
(proto)[source]
-
property
metrics
Dictionary of string key -> metric value for the current run. For each metric key, the metric value with the latest timestamp is returned. In case there are multiple values with the same latest timestamp, the maximum of these values is returned.
Dictionary of tag key (string) -> tag value for the current run.
-
to_dictionary
()[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
RunInfo
(run_uuid, experiment_id, user_id, status, start_time, end_time, lifecycle_stage, artifact_uri=None, run_id=None, run_name=None)[source] Metadata about a run.
-
property
artifact_uri
[source] String root artifact URI of the run.
-
property
end_time
[source] End time of the run, in number of milliseconds since the UNIX epoch.
-
classmethod
from_proto
(proto)[source]
-
classmethod
get_orderable_attributes
()[source]
-
classmethod
get_searchable_attributes
()[source]
-
property
lifecycle_stage
One of the values in
LifecycleStage
describing the lifecycle stage of the run.
-
property
run_id
[source] String containing run id.
-
property
run_name
[source] String containing run name.
-
property
start_time
[source] Start time of the run, in number of milliseconds since the UNIX epoch.
-
property
status
[source] One of the values in
mlflow.entities.RunStatus
describing the status of the run.
-
to_proto
()[source]
-
property
user_id
[source] String ID of the user who initiated this run.
-
property
-
class
mlflow.entities.
RunInputs
(dataset_inputs: List[DatasetInput])[source] RunInputs object.
-
classmethod
from_proto
(proto)[source]
-
to_dictionary
() → Dict[Any, Any][source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
RunStatus
[source] Enum for status of an
mlflow.entities.Run
.-
static
all_status
()[source]
-
static
from_string
(status_str)[source]
-
static
is_terminated
(status)[source]
-
static
to_string
(status)[source]
-
static
-
class
mlflow.entities.
RunTag
(key, value)[source] Tag object associated with a run.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.
SourceType
[source] Enum for originating source of a
mlflow.entities.Run
.-
SOURCETYPE_TO_STRING
= {1: 'NOTEBOOK', 2: 'JOB', 3: 'PROJECT', 4: 'LOCAL', 5: 'UNKNOWN', 6: 'RECIPE'}
-
static
from_string
(status_str)[source]
-
static
to_string
(status)[source]
-
-
class
mlflow.entities.
Span
(otel_span: opentelemetry.sdk.trace.ReadableSpan)[source] A span object. A span represents a unit of work or operation and is the building block of Traces.
This Span class represents immutable span data that is already finished and persisted. The “live” span that is being created and updated during the application runtime is represented by the
LiveSpan
subclass.-
property
attributes
Get all attributes of the span.
- Returns
A dictionary of all attributes of the span.
-
classmethod
from_dict
(data: Dict[str, Any]) → Span[source] Create a Span object from the given dictionary.
-
get_attribute
(key: str) → Optional[Any][source] Get a single attribute value from the span.
- Parameters
key – The key of the attribute to get.
- Returns
The value of the attribute if it exists, otherwise None.
-
property
request_id
The request ID of the span, a unique identifier for the trace it belongs to. Request ID is equivalent to the trace ID in OpenTelemetry, but generated differently by the tracing backend.
-
to_dict
()[source]
-
property
-
class
mlflow.entities.
SpanEvent
(name: str, timestamp: int = <factory>, attributes: Dict[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]] = <factory>)[source] An event that records a specific occurrences or moments in time during a span, such as an exception being thrown. Compatible with OpenTelemetry.
- Parameters
name – Name of the event.
timestamp – The exact time the event occurred, measured in microseconds. If not provided, the current time will be used.
attributes – A collection of key-value pairs representing detailed attributes of the event, such as the exception stack trace. Attributes value must be one of
[str, int, float, bool, bytes]
or a sequence of these types.
-
attributes
: Dict[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]
-
classmethod
from_exception
(exception: Exception)[source] Create a span event from an exception.
-
json
()[source]
-
class
mlflow.entities.
SpanStatus
(status_code: SpanStatusCode, description: str = '')[source] Status of the span or the trace.
- Parameters
status_code – The status code of the span or the trace. This must be one of the values of the
mlflow.entities.SpanStatusCode
enum or a string representation of it like “OK”, “ERROR”.description – Description of the status. This should be only set when the status is ERROR, otherwise it will be ignored.
-
status_code
: SpanStatusCode
-
class
mlflow.entities.
SpanStatusCode
(value)[source] Enum for status code of a span
-
class
mlflow.entities.
SpanType
[source] Predefined set of span types.
-
class
mlflow.entities.
Trace
(info: TraceInfo, data: TraceData)[source] A trace object.
- Parameters
info – A lightweight object that contains the metadata of a trace.
data – A container object that holds the spans data of a trace.
-
data
: TraceData
-
info
: TraceInfo
-
static
pandas_dataframe_columns
() → List[str][source]
-
to_dict
() → Dict[str, Any][source]
-
to_json
(pretty=False) → str[source]
-
to_pandas_dataframe_row
() → Dict[str, Any][source]
-
class
mlflow.entities.
TraceData
(spans: List[mlflow.entities.span.Span] = <factory>, request: Optional[str] = None, response: Optional[str] = None)[source] A container object that holds the spans data of a trace.
- Parameters
spans – List of spans that are part of the trace.
request – Input data for the entire trace. Equivalent to the input of the root span but added for ease of access. Stored as a JSON string.
response – Output data for the entire trace. Equivalent to the output of the root span. Stored as a JSON string.
-
classmethod
from_dict
(d)[source]
-
spans
: List[Span]
-
to_dict
() → Dict[str, Any][source]
-
class
mlflow.entities.
TraceInfo
(request_id: str, experiment_id: str, timestamp_ms: int, execution_time_ms: Optional[int], status: mlflow.entities.trace_status.TraceStatus, request_metadata: Dict[str, str] = <factory>, tags: Dict[str, str] = <factory>)[source] Metadata about a trace.
- Parameters
request_id – id of the trace.
experiment_id – id of the experiment.
timestamp_ms – start time of the trace, in milliseconds.
execution_time_ms – duration of the trace, in milliseconds.
status – status of the trace.
request_metadata – Key-value pairs associated with the trace. Request metadata are designed for immutable values like run ID associated with the trace.
tags – Tags associated with the trace. Tags are designed for mutable values like trace name, that can be updated by the users after the trace is created, unlike request_metadata.
-
classmethod
from_dict
(trace_info_dict)[source] Convert trace info dictionary to TraceInfo object.
-
classmethod
from_proto
(proto)[source]
-
to_dict
()[source] Convert trace info to a dictionary for persistence. Update status field to the string value for serialization.
-
to_proto
()[source]
-
class
mlflow.entities.
ViewType
[source] Enum to filter requested experiment types.
-
classmethod
from_proto
(proto_view_type)[source]
-
classmethod
from_string
(view_str)[source]
-
classmethod
to_proto
(view_type)[source]
-
classmethod
to_string
(view_type)[source]
-
classmethod
-
class
mlflow.entities.model_registry.
ModelVersion
(name, version, creation_timestamp, last_updated_timestamp=None, description=None, user_id=None, current_stage=None, source=None, run_id=None, status='READY', status_message=None, tags=None, run_link=None, aliases=None)[source] MLflow entity for Model Version.
-
property
creation_timestamp
Integer. Model version creation timestamp (milliseconds since the Unix epoch).
-
classmethod
from_proto
(proto)[source]
-
property
last_updated_timestamp
Integer. Timestamp of last update for this model version (milliseconds since the Unix epoch).
-
property
run_link
String. MLflow run link referring to the exact run that generated this model version.
Dictionary of tag key (string) -> tag value for the current model version.
-
to_proto
()[source]
-
property
-
class
mlflow.entities.model_registry.
ModelVersionSearch
(*args, **kwargs)[source] -
aliases
()[source] List of aliases (string) for the current model version.
Dictionary of tag key (string) -> tag value for the current model version.
-
-
class
mlflow.entities.model_registry.
ModelVersionTag
(key, value)[source] Tag object associated with a model version.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.model_registry.
RegisteredModel
(name, creation_timestamp=None, last_updated_timestamp=None, description=None, latest_versions=None, tags=None, aliases=None)[source] MLflow entity for Registered Model.
-
property
creation_timestamp
Integer. Model version creation timestamp (milliseconds since the Unix epoch).
-
classmethod
from_proto
(proto)[source]
-
property
last_updated_timestamp
Integer. Timestamp of last update for this model version (milliseconds since the Unix epoch).
-
property
latest_versions
List of the latest
mlflow.entities.model_registry.ModelVersion
instances for each stage.
Dictionary of tag key (string) -> tag value for the current registered model.
-
to_proto
()[source]
-
property
-
class
mlflow.entities.model_registry.
RegisteredModelAlias
(alias, version)[source] Alias object associated with a registered model.
-
classmethod
from_proto
(proto)[source]
-
to_proto
()[source]
-
classmethod
-
class
mlflow.entities.model_registry.
RegisteredModelSearch
(*args, **kwargs)[source] -
aliases
()[source] Dictionary of aliases (string) -> version for the current registered model.
Dictionary of tag key (string) -> tag value for the current registered model.
-