or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client.mdconfiguration.mddata.mdframeworks.mdgenai.mdindex.mdmodels.mdprojects.mdtracing.mdtracking.md

client.mddocs/

0

# Client API

1

2

MLflow's Client API provides low-level programmatic access to MLflow's REST API for managing experiments, runs, model registry, and artifacts. The MlflowClient class offers comprehensive methods for tracking, model management, and artifact storage with fine-grained control over MLflow operations.

3

4

## Capabilities

5

6

### Client Initialization

7

8

Core client class for direct API access to MLflow tracking and model registry servers with support for different backend stores.

9

10

```python { .api }

11

class MlflowClient:

12

def __init__(self, tracking_uri=None, registry_uri=None):

13

"""

14

Initialize MLflow client.

15

16

Parameters:

17

- tracking_uri: str, optional - Address of tracking server

18

- registry_uri: str, optional - Address of model registry server

19

20

Returns:

21

MlflowClient instance

22

"""

23

```

24

25

### Experiment Management

26

27

Methods for creating, managing, and searching experiments with comprehensive filtering and organization capabilities.

28

29

```python { .api }

30

def create_experiment(self, name, artifact_location=None, tags=None):

31

"""

32

Create a new experiment.

33

34

Parameters:

35

- name: str - Unique experiment name

36

- artifact_location: str, optional - Location to store artifacts

37

- tags: dict, optional - Dictionary of experiment tags

38

39

Returns:

40

str - Experiment ID

41

"""

42

43

def get_experiment(self, experiment_id):

44

"""

45

Retrieve experiment by ID.

46

47

Parameters:

48

- experiment_id: str - The experiment ID

49

50

Returns:

51

Experiment object

52

"""

53

54

def get_experiment_by_name(self, name):

55

"""

56

Retrieve experiment by name.

57

58

Parameters:

59

- name: str - The experiment name (case sensitive)

60

61

Returns:

62

Experiment object or None if not found

63

"""

64

65

def search_experiments(self, view_type=ViewType.ACTIVE_ONLY, max_results=None, filter_string=None, order_by=None, page_token=None):

66

"""

67

Search experiments matching criteria.

68

69

Parameters:

70

- view_type: ViewType - Type of experiments to return

71

- max_results: int, optional - Maximum number of experiments

72

- filter_string: str, optional - Filter expression

73

- order_by: list, optional - List of columns to order by

74

- page_token: str, optional - Token for pagination

75

76

Returns:

77

PagedList of Experiment objects

78

"""

79

80

def delete_experiment(self, experiment_id):

81

"""

82

Delete an experiment (soft delete).

83

84

Parameters:

85

- experiment_id: str - The experiment ID to delete

86

"""

87

88

def restore_experiment(self, experiment_id):

89

"""

90

Restore a deleted experiment.

91

92

Parameters:

93

- experiment_id: str - The experiment ID to restore

94

"""

95

96

def rename_experiment(self, experiment_id, new_name):

97

"""

98

Update experiment name.

99

100

Parameters:

101

- experiment_id: str - The experiment ID

102

- new_name: str - New unique name for the experiment

103

"""

104

```

105

106

### Run Management

107

108

Methods for creating, updating, and managing individual runs with comprehensive metadata and lifecycle control.

109

110

```python { .api }

111

def create_run(self, experiment_id, start_time=None, tags=None, run_name=None):

112

"""

113

Create a new run.

114

115

Parameters:

116

- experiment_id: str - The experiment ID

117

- start_time: int, optional - Unix timestamp of run start

118

- tags: dict, optional - Dictionary of run tags

119

- run_name: str, optional - Human-readable run name

120

121

Returns:

122

Run object representing the created run

123

"""

124

125

def get_run(self, run_id):

126

"""

127

Fetch run from backend store.

128

129

Parameters:

130

- run_id: str - Unique run identifier

131

132

Returns:

133

Run object with metadata and data

134

"""

135

136

def update_run(self, run_id, status=None, name=None):

137

"""

138

Update run status or name.

139

140

Parameters:

141

- run_id: str - The run ID to update

142

- status: str, optional - New run status

143

- name: str, optional - New run name

144

"""

145

146

def delete_run(self, run_id):

147

"""

148

Delete a run (soft delete).

149

150

Parameters:

151

- run_id: str - The run ID to delete

152

"""

153

154

def restore_run(self, run_id):

155

"""

156

Restore a deleted run.

157

158

Parameters:

159

- run_id: str - The run ID to restore

160

"""

161

162

def search_runs(self, experiment_ids, filter_string="", run_view_type=ViewType.ACTIVE_ONLY, max_results=SEARCH_MAX_RESULTS_DEFAULT, order_by=None, page_token=None):

163

"""

164

Search for runs matching criteria.

165

166

Parameters:

167

- experiment_ids: list - List of experiment IDs to search

168

- filter_string: str - Filter expression for runs

169

- run_view_type: ViewType - Type of runs to return

170

- max_results: int - Maximum number of runs

171

- order_by: list, optional - Columns to order by

172

- page_token: str, optional - Pagination token

173

174

Returns:

175

PagedList of Run objects

176

"""

177

178

def set_terminated(self, run_id, status=None, end_time=None):

179

"""

180

Set run status to terminated.

181

182

Parameters:

183

- run_id: str - The run ID to terminate

184

- status: str, optional - Final status (defaults to FINISHED)

185

- end_time: int, optional - Unix timestamp of completion

186

"""

187

188

def get_parent_run(self, run_id):

189

"""

190

Get parent run for nested run.

191

192

Parameters:

193

- run_id: str - Child run ID

194

195

Returns:

196

Run object of parent or None if not nested

197

"""

198

```

199

200

### Logging Operations

201

202

Methods for logging parameters, metrics, artifacts, and other run data with support for batch operations and async logging.

203

204

```python { .api }

205

def log_param(self, run_id, key, value, synchronous=None):

206

"""

207

Log a parameter for a run.

208

209

Parameters:

210

- run_id: str - The run ID

211

- key: str - Parameter name

212

- value: Any - Parameter value (converted to string)

213

- synchronous: bool, optional - Whether to log synchronously

214

215

Returns:

216

Parameter value when synchronous, RunOperations when async

217

"""

218

219

def log_metric(self, run_id, key, value, timestamp=None, step=None, synchronous=None, dataset_name=None, dataset_digest=None, model_id=None):

220

"""

221

Log a metric for a run.

222

223

Parameters:

224

- run_id: str - The run ID

225

- key: str - Metric name

226

- value: float - Metric value

227

- timestamp: int, optional - Unix timestamp in milliseconds

228

- step: int, optional - Training step number

229

- synchronous: bool, optional - Whether to log synchronously

230

- dataset_name: str, optional - Associated dataset name

231

- dataset_digest: str, optional - Associated dataset digest

232

- model_id: str, optional - Associated model ID

233

234

Returns:

235

None when synchronous, RunOperations when async

236

"""

237

238

def log_batch(self, run_id, metrics=(), params=(), tags=(), synchronous=None):

239

"""

240

Log multiple metrics, params, and tags.

241

242

Parameters:

243

- run_id: str - The run ID

244

- metrics: Sequence[Metric] - List of Metric objects

245

- params: Sequence[Param] - List of Param objects

246

- tags: Sequence[RunTag] - List of RunTag objects

247

- synchronous: bool, optional - Whether to log synchronously

248

249

Returns:

250

None when synchronous, RunOperations when async

251

"""

252

253

def get_metric_history(self, run_id, key):

254

"""

255

Get history of a metric across steps.

256

257

Parameters:

258

- run_id: str - The run ID

259

- key: str - Metric name

260

261

Returns:

262

List of Metric objects with historical values

263

"""

264

```

265

266

### Artifact Management

267

268

Methods for uploading, downloading, and managing artifacts with support for various storage backends.

269

270

```python { .api }

271

def log_artifact(self, run_id, local_path, artifact_path=None):

272

"""

273

Log a file as an artifact.

274

275

Parameters:

276

- run_id: str - The run ID

277

- local_path: str - Local file path

278

- artifact_path: str, optional - Relative path in artifact store

279

"""

280

281

def log_artifacts(self, run_id, local_dir, artifact_path=None):

282

"""

283

Log directory of files as artifacts.

284

285

Parameters:

286

- run_id: str - The run ID

287

- local_dir: str - Local directory path

288

- artifact_path: str, optional - Relative path in artifact store

289

"""

290

291

def log_text(self, run_id, text, artifact_file):

292

"""

293

Log text content as an artifact.

294

295

Parameters:

296

- run_id: str - The run ID

297

- text: str - Text content to log

298

- artifact_file: str - Artifact file path

299

"""

300

301

def log_dict(self, run_id, dictionary, artifact_file):

302

"""

303

Log dictionary as JSON/YAML artifact.

304

305

Parameters:

306

- run_id: str - The run ID

307

- dictionary: dict - Dictionary to log

308

- artifact_file: str - Artifact file path (determines format)

309

"""

310

311

def log_figure(self, run_id, figure, artifact_file, save_kwargs=None):

312

"""

313

Log matplotlib or plotly figure as artifact.

314

315

Parameters:

316

- run_id: str - The run ID

317

- figure: Figure - Matplotlib or plotly figure object

318

- artifact_file: str - Artifact file path

319

- save_kwargs: dict, optional - Additional save arguments

320

"""

321

322

def log_image(self, run_id, image, artifact_file=None, key=None, step=None, timestamp=None, synchronous=None):

323

"""

324

Log image as artifact or time-series data.

325

326

Parameters:

327

- run_id: str - The run ID

328

- image: Image - PIL Image, numpy array, or mlflow.Image

329

- artifact_file: str, optional - For static artifact logging

330

- key: str, optional - For time-series image logging

331

- step: int, optional - Training step number

332

- timestamp: int, optional - Unix timestamp in milliseconds

333

- synchronous: bool, optional - Whether to log synchronously

334

"""

335

336

def log_table(self, run_id, data, artifact_file):

337

"""

338

Log tabular data as artifact.

339

340

Parameters:

341

- run_id: str - The run ID

342

- data: DataFrame or dict - Tabular data to log

343

- artifact_file: str - Artifact file path (.json or .parquet)

344

"""

345

346

def list_artifacts(self, run_id, path=None):

347

"""

348

List artifacts for a run.

349

350

Parameters:

351

- run_id: str - The run ID

352

- path: str, optional - Relative path within artifacts

353

354

Returns:

355

List of FileInfo objects

356

"""

357

358

def download_artifacts(self, run_id, path, dst_path=None):

359

"""

360

Download artifacts from a run.

361

362

Parameters:

363

- run_id: str - The run ID

364

- path: str - Relative source path to artifact

365

- dst_path: str, optional - Local destination directory

366

367

Returns:

368

str - Local path to downloaded artifacts

369

"""

370

371

def load_table(self, experiment_id, artifact_file, run_ids=None, extra_columns=None):

372

"""

373

Load table artifact from multiple runs.

374

375

Parameters:

376

- experiment_id: str - Experiment ID to search

377

- artifact_file: str - Artifact file path

378

- run_ids: list, optional - Specific run IDs to load from

379

- extra_columns: list, optional - Additional columns to append

380

381

Returns:

382

pandas.DataFrame - Combined table data

383

"""

384

```

385

386

### Tagging Operations

387

388

Methods for managing tags on runs and experiments for organization and metadata purposes.

389

390

```python { .api }

391

def set_tag(self, run_id, key, value, synchronous=None):

392

"""

393

Set tag on a run.

394

395

Parameters:

396

- run_id: str - The run ID

397

- key: str - Tag key (max 250 chars)

398

- value: Any - Tag value (converted to string, max 5000 chars)

399

- synchronous: bool, optional - Whether to set synchronously

400

401

Returns:

402

None when synchronous, RunOperations when async

403

"""

404

405

def delete_tag(self, run_id, key):

406

"""

407

Delete tag from a run.

408

409

Parameters:

410

- run_id: str - The run ID

411

- key: str - Tag key to delete

412

"""

413

414

def set_experiment_tag(self, experiment_id, key, value):

415

"""

416

Set tag on an experiment.

417

418

Parameters:

419

- experiment_id: str - The experiment ID

420

- key: str - Tag key

421

- value: Any - Tag value (converted to string)

422

"""

423

424

def delete_experiment_tag(self, experiment_id, key):

425

"""

426

Delete tag from an experiment.

427

428

Parameters:

429

- experiment_id: str - The experiment ID

430

- key: str - Tag key to delete

431

"""

432

```

433

434

### Model Registry Operations

435

436

Methods for managing registered models and model versions in the MLflow Model Registry.

437

438

```python { .api }

439

def create_registered_model(self, name, tags=None, description=None, deployment_job_id=None):

440

"""

441

Create a new registered model.

442

443

Parameters:

444

- name: str - Unique model name

445

- tags: dict, optional - Model tags

446

- description: str, optional - Model description

447

- deployment_job_id: str, optional - Deployment job ID

448

449

Returns:

450

RegisteredModel object

451

"""

452

453

def get_registered_model(self, name):

454

"""

455

Get registered model by name.

456

457

Parameters:

458

- name: str - Registered model name

459

460

Returns:

461

RegisteredModel object

462

"""

463

464

def update_registered_model(self, name, description=None, deployment_job_id=None):

465

"""

466

Update registered model metadata.

467

468

Parameters:

469

- name: str - Registered model name

470

- description: str, optional - New description

471

- deployment_job_id: str, optional - New deployment job ID

472

473

Returns:

474

RegisteredModel object

475

"""

476

477

def rename_registered_model(self, name, new_name):

478

"""

479

Rename a registered model.

480

481

Parameters:

482

- name: str - Current model name

483

- new_name: str - New unique model name

484

485

Returns:

486

RegisteredModel object

487

"""

488

489

def delete_registered_model(self, name):

490

"""

491

Delete a registered model.

492

493

Parameters:

494

- name: str - Registered model name to delete

495

"""

496

497

def search_registered_models(self, filter_string=None, max_results=SEARCH_REGISTERED_MODEL_MAX_RESULTS_DEFAULT, order_by=None, page_token=None):

498

"""

499

Search registered models.

500

501

Parameters:

502

- filter_string: str, optional - Filter expression

503

- max_results: int - Maximum number of models

504

- order_by: list, optional - Columns to order by

505

- page_token: str, optional - Pagination token

506

507

Returns:

508

PagedList of RegisteredModel objects

509

"""

510

511

def create_model_version(self, name, source, run_id=None, tags=None, run_link=None, description=None, await_creation_for=DEFAULT_AWAIT_MAX_SLEEP_SECONDS, model_id=None):

512

"""

513

Create new model version from source.

514

515

Parameters:

516

- name: str - Registered model name

517

- source: str - Model artifact URI

518

- run_id: str, optional - Source run ID

519

- tags: dict, optional - Model version tags

520

- run_link: str, optional - Link to source run

521

- description: str, optional - Version description

522

- await_creation_for: int - Seconds to wait for creation

523

- model_id: str, optional - Source model ID

524

525

Returns:

526

ModelVersion object

527

"""

528

529

def get_model_version(self, name, version):

530

"""

531

Get model version by name and version.

532

533

Parameters:

534

- name: str - Registered model name

535

- version: str - Model version number

536

537

Returns:

538

ModelVersion object

539

"""

540

541

def update_model_version(self, name, version, description=None):

542

"""

543

Update model version metadata.

544

545

Parameters:

546

- name: str - Registered model name

547

- version: str - Model version number

548

- description: str, optional - New description

549

550

Returns:

551

ModelVersion object

552

"""

553

554

def delete_model_version(self, name, version):

555

"""

556

Delete a model version.

557

558

Parameters:

559

- name: str - Registered model name

560

- version: str - Model version to delete

561

"""

562

563

def get_model_version_download_uri(self, name, version):

564

"""

565

Get download URI for model version.

566

567

Parameters:

568

- name: str - Registered model name

569

- version: str - Model version number

570

571

Returns:

572

str - Download URI for model artifacts

573

"""

574

575

def search_model_versions(self, filter_string=None, max_results=SEARCH_MODEL_VERSION_MAX_RESULTS_DEFAULT, order_by=None, page_token=None):

576

"""

577

Search model versions.

578

579

Parameters:

580

- filter_string: str, optional - Filter expression

581

- max_results: int - Maximum number of versions

582

- order_by: list, optional - Columns to order by

583

- page_token: str, optional - Pagination token

584

585

Returns:

586

PagedList of ModelVersion objects

587

"""

588

589

def copy_model_version(self, src_model_uri, dst_name):

590

"""

591

Copy model version to new registered model.

592

593

Parameters:

594

- src_model_uri: str - Source model URI (models:/ scheme)

595

- dst_name: str - Destination registered model name

596

597

Returns:

598

ModelVersion object representing copied version

599

"""

600

```

601

602

### Model Aliasing

603

604

Methods for managing model aliases for flexible model referencing and deployment workflows.

605

606

```python { .api }

607

def set_registered_model_alias(self, name, alias, version):

608

"""

609

Set alias for registered model version.

610

611

Parameters:

612

- name: str - Registered model name

613

- alias: str - Alias name (cannot be v<number> format)

614

- version: str - Model version number

615

"""

616

617

def delete_registered_model_alias(self, name, alias):

618

"""

619

Delete registered model alias.

620

621

Parameters:

622

- name: str - Registered model name

623

- alias: str - Alias name to delete

624

"""

625

626

def get_model_version_by_alias(self, name, alias):

627

"""

628

Get model version by alias.

629

630

Parameters:

631

- name: str - Registered model name

632

- alias: str - Alias name

633

634

Returns:

635

ModelVersion object

636

"""

637

```

638

639

### Tracing Operations

640

641

Methods for managing distributed traces and spans for LLM/GenAI application observability.

642

643

```python { .api }

644

def start_trace(self, name, span_type=SpanType.UNKNOWN, inputs=None, attributes=None, tags=None, experiment_id=None, start_time_ns=None):

645

"""

646

Create new trace and start root span.

647

648

Parameters:

649

- name: str - Trace and root span name

650

- span_type: str - Type of span

651

- inputs: Any, optional - Inputs to set on root span

652

- attributes: dict, optional - Span attributes

653

- tags: dict, optional - Trace tags

654

- experiment_id: str, optional - Experiment ID for trace

655

- start_time_ns: int, optional - Start time in nanoseconds

656

657

Returns:

658

Span object representing root span

659

"""

660

661

def end_trace(self, trace_id, outputs=None, attributes=None, status="OK", end_time_ns=None):

662

"""

663

End trace and log to backend.

664

665

Parameters:

666

- trace_id: str - Trace ID to end

667

- outputs: Any, optional - Trace outputs

668

- attributes: dict, optional - Additional attributes

669

- status: SpanStatus or str - Final status

670

- end_time_ns: int, optional - End time in nanoseconds

671

"""

672

673

def start_span(self, name, trace_id, parent_id, span_type=SpanType.UNKNOWN, inputs=None, attributes=None, start_time_ns=None):

674

"""

675

Create and start new span under trace.

676

677

Parameters:

678

- name: str - Span name

679

- trace_id: str - Trace ID to attach span to

680

- parent_id: str - Parent span ID

681

- span_type: str - Type of span

682

- inputs: Any, optional - Span inputs

683

- attributes: dict, optional - Span attributes

684

- start_time_ns: int, optional - Start time in nanoseconds

685

686

Returns:

687

Span object

688

"""

689

690

def end_span(self, trace_id, span_id, outputs=None, attributes=None, status="OK", end_time_ns=None):

691

"""

692

End span with given IDs.

693

694

Parameters:

695

- trace_id: str - Trace ID

696

- span_id: str - Span ID to end

697

- outputs: Any, optional - Span outputs

698

- attributes: dict, optional - Additional attributes

699

- status: SpanStatus or str - Final status

700

- end_time_ns: int, optional - End time in nanoseconds

701

"""

702

703

def get_trace(self, trace_id, display=True):

704

"""

705

Get trace by ID.

706

707

Parameters:

708

- trace_id: str - Trace ID to fetch

709

- display: bool - Whether to display in notebook

710

711

Returns:

712

Trace object

713

"""

714

715

def search_traces(self, experiment_ids, filter_string=None, max_results=SEARCH_TRACES_DEFAULT_MAX_RESULTS, order_by=None, page_token=None, run_id=None, include_spans=True, model_id=None, sql_warehouse_id=None):

716

"""

717

Search traces matching criteria.

718

719

Parameters:

720

- experiment_ids: list - List of experiment IDs to search

721

- filter_string: str, optional - Filter expression

722

- max_results: int - Maximum number of traces

723

- order_by: list, optional - Columns to order by

724

- page_token: str, optional - Pagination token

725

- run_id: str, optional - Associated run ID

726

- include_spans: bool - Whether to include span data

727

- model_id: str, optional - Associated model ID

728

- sql_warehouse_id: str, optional - SQL warehouse for search

729

730

Returns:

731

PagedList of Trace objects

732

"""

733

734

def delete_traces(self, experiment_id, max_timestamp_millis=None, max_traces=None, trace_ids=None):

735

"""

736

Delete traces based on criteria.

737

738

Parameters:

739

- experiment_id: str - Experiment ID for traces

740

- max_timestamp_millis: int, optional - Maximum timestamp for deletion

741

- max_traces: int, optional - Maximum number to delete

742

- trace_ids: list, optional - Specific trace IDs to delete

743

744

Returns:

745

int - Number of traces deleted

746

"""

747

748

def set_trace_tag(self, trace_id, key, value):

749

"""

750

Set tag on trace.

751

752

Parameters:

753

- trace_id: str - Trace ID

754

- key: str - Tag key (max 250 chars)

755

- value: str - Tag value (max 250 chars)

756

"""

757

758

def delete_trace_tag(self, trace_id, key):

759

"""

760

Delete tag from trace.

761

762

Parameters:

763

- trace_id: str - Trace ID

764

- key: str - Tag key to delete

765

"""

766

```

767

768

## Usage Examples

769

770

### Basic Client Operations

771

772

```python

773

from mlflow import MlflowClient

774

775

# Initialize client with custom URIs

776

client = MlflowClient(

777

tracking_uri="http://localhost:5000",

778

registry_uri="sqlite:///mlflow_registry.db"

779

)

780

781

# Create experiment and run

782

experiment_id = client.create_experiment(

783

name="client-api-experiment",

784

tags={"project": "client-demo"}

785

)

786

787

run = client.create_run(

788

experiment_id=experiment_id,

789

run_name="client-demo-run"

790

)

791

792

# Log data to run

793

client.log_param(run.info.run_id, "learning_rate", 0.01)

794

client.log_metric(run.info.run_id, "accuracy", 0.95, step=10)

795

796

# Terminate run

797

client.set_terminated(run.info.run_id, status="FINISHED")

798

```

799

800

### Model Registry Operations

801

802

```python

803

from mlflow import MlflowClient

804

805

client = MlflowClient()

806

807

# Create registered model

808

model_name = "my-classification-model"

809

client.create_registered_model(

810

name=model_name,

811

description="Production classification model",

812

tags={"team": "ml-platform"}

813

)

814

815

# Create model version from run

816

model_version = client.create_model_version(

817

name=model_name,

818

source=f"runs:/{run_id}/model",

819

run_id=run_id,

820

description="Initial model version"

821

)

822

823

# Set model alias

824

client.set_registered_model_alias(

825

name=model_name,

826

alias="champion",

827

version=model_version.version

828

)

829

830

# Get model by alias

831

champion_model = client.get_model_version_by_alias(

832

name=model_name,

833

alias="champion"

834

)

835

```

836

837

### Batch Logging Operations

838

839

```python

840

from mlflow import MlflowClient

841

from mlflow.entities import Metric, Param, RunTag

842

import time

843

844

client = MlflowClient()

845

846

# Create run

847

run = client.create_run(experiment_id="0")

848

849

# Prepare batch data

850

timestamp = int(time.time() * 1000)

851

metrics = [

852

Metric("accuracy", 0.95, timestamp, 1),

853

Metric("precision", 0.92, timestamp, 1),

854

Metric("recall", 0.88, timestamp, 1)

855

]

856

params = [

857

Param("model_type", "random_forest"),

858

Param("n_estimators", "100"),

859

Param("max_depth", "10")

860

]

861

tags = [

862

RunTag("experiment_type", "hyperparameter_tuning"),

863

RunTag("framework", "scikit-learn")

864

]

865

866

# Log batch

867

client.log_batch(

868

run_id=run.info.run_id,

869

metrics=metrics,

870

params=params,

871

tags=tags

872

)

873

874

client.set_terminated(run.info.run_id)

875

```

876

877

### Prompt Management

878

879

Client methods for managing prompts in the MLflow prompt registry with versioning, aliasing, and search capabilities.

880

881

```python { .api }

882

def create_prompt(self, name, prompt, tags=None, description=None, metadata=None):

883

"""

884

Create new prompt in registry.

885

886

Parameters:

887

- name: str - Unique prompt name

888

- prompt: str - Prompt content or template

889

- tags: dict, optional - Prompt tags

890

- description: str, optional - Prompt description

891

- metadata: dict, optional - Additional metadata

892

893

Returns:

894

Prompt object

895

"""

896

897

def get_prompt(self, name, version=None):

898

"""

899

Get prompt by name and version.

900

901

Parameters:

902

- name: str - Prompt name

903

- version: str or int, optional - Prompt version

904

905

Returns:

906

Prompt object

907

"""

908

909

def search_prompts(self, filter_string=None, max_results=None, order_by=None, page_token=None):

910

"""

911

Search prompts with filtering.

912

913

Parameters:

914

- filter_string: str, optional - Filter expression

915

- max_results: int, optional - Maximum results

916

- order_by: list, optional - Sort order

917

- page_token: str, optional - Pagination token

918

919

Returns:

920

PagedList of Prompt objects

921

"""

922

923

def register_prompt(self, prompt, name, version=None, tags=None, description=None, metadata=None):

924

"""

925

Register prompt in registry.

926

927

Parameters:

928

- prompt: str - Prompt content

929

- name: str - Prompt name

930

- version: str or int, optional - Version number

931

- tags: dict, optional - Prompt tags

932

- description: str, optional - Description

933

- metadata: dict, optional - Additional metadata

934

935

Returns:

936

Prompt object

937

"""

938

```

939

940

### Assessment and Feedback Management

941

942

Client methods for managing assessments and feedback on runs and traces.

943

944

```python { .api }

945

def log_assessment(self, assessment, request_id=None, run_id=None, timestamp_ms=None):

946

"""

947

Log assessment for run or trace.

948

949

Parameters:

950

- assessment: Assessment - Assessment object to log

951

- request_id: str, optional - Trace request ID

952

- run_id: str, optional - MLflow run ID

953

- timestamp_ms: int, optional - Assessment timestamp

954

955

Returns:

956

Assessment object

957

"""

958

959

def get_assessment(self, assessment_id):

960

"""

961

Get assessment by ID.

962

963

Parameters:

964

- assessment_id: str - Assessment identifier

965

966

Returns:

967

Assessment object

968

"""

969

970

def update_assessment(self, assessment_id, **kwargs):

971

"""

972

Update existing assessment.

973

974

Parameters:

975

- assessment_id: str - Assessment ID to update

976

- **kwargs: Updated assessment attributes

977

978

Returns:

979

Updated Assessment object

980

"""

981

982

def delete_assessment(self, assessment_id):

983

"""

984

Delete assessment by ID.

985

986

Parameters:

987

- assessment_id: str - Assessment ID to delete

988

"""

989

```

990

991

### Webhook Management

992

993

Client methods for managing webhooks for MLflow events and notifications.

994

995

```python { .api }

996

def create_webhook(self, events, http_url_spec, description=None, status="ACTIVE", model_name=None):

997

"""

998

Create webhook for MLflow events.

999

1000

Parameters:

1001

- events: list - List of event types to trigger webhook

1002

- http_url_spec: dict - HTTP endpoint specification

1003

- description: str, optional - Webhook description

1004

- status: str - Webhook status ("ACTIVE", "INACTIVE")

1005

- model_name: str, optional - Model name filter

1006

1007

Returns:

1008

Webhook object

1009

"""

1010

1011

def get_webhook(self, webhook_id):

1012

"""

1013

Get webhook by ID.

1014

1015

Parameters:

1016

- webhook_id: str - Webhook identifier

1017

1018

Returns:

1019

Webhook object

1020

"""

1021

1022

def list_webhooks(self, events=None, model_name=None, page_token=None):

1023

"""

1024

List webhooks with optional filtering.

1025

1026

Parameters:

1027

- events: list, optional - Filter by event types

1028

- model_name: str, optional - Filter by model name

1029

- page_token: str, optional - Pagination token

1030

1031

Returns:

1032

PagedList of Webhook objects

1033

"""

1034

1035

def update_webhook(self, webhook_id, **kwargs):

1036

"""

1037

Update existing webhook.

1038

1039

Parameters:

1040

- webhook_id: str - Webhook ID to update

1041

- **kwargs: Updated webhook attributes

1042

1043

Returns:

1044

Updated Webhook object

1045

"""

1046

1047

def delete_webhook(self, webhook_id):

1048

"""

1049

Delete webhook by ID.

1050

1051

Parameters:

1052

- webhook_id: str - Webhook ID to delete

1053

"""

1054

```

1055

1056

### Logged Model Management

1057

1058

Client methods for managing logged models with enhanced metadata and search capabilities.

1059

1060

```python { .api }

1061

def create_logged_model(self, name, run_id, model_path, flavor=None, metadata=None):

1062

"""

1063

Create logged model entry.

1064

1065

Parameters:

1066

- name: str - Model name

1067

- run_id: str - Associated run ID

1068

- model_path: str - Path to model artifacts

1069

- flavor: str, optional - Model flavor

1070

- metadata: dict, optional - Model metadata

1071

1072

Returns:

1073

LoggedModel object

1074

"""

1075

1076

def search_logged_models(self, filter_string=None, max_results=None, order_by=None, page_token=None):

1077

"""

1078

Search logged models with filtering.

1079

1080

Parameters:

1081

- filter_string: str, optional - Filter expression

1082

- max_results: int, optional - Maximum results

1083

- order_by: list, optional - Sort order

1084

- page_token: str, optional - Pagination token

1085

1086

Returns:

1087

PagedList of LoggedModel objects

1088

"""

1089

1090

def log_model_params(self, run_id, model_params):

1091

"""

1092

Log model parameters for run.

1093

1094

Parameters:

1095

- run_id: str - Run ID

1096

- model_params: dict - Model parameters to log

1097

"""

1098

```

1099

1100

## Types

1101

1102

```python { .api }

1103

from mlflow.entities import Experiment, Run, RunInfo, RunData, Metric, Param, RunTag

1104

from mlflow.entities.model_registry import RegisteredModel, ModelVersion

1105

from mlflow.entities import Trace, Span, FileInfo

1106

from mlflow.store.entities.paged_list import PagedList

1107

from mlflow.client import MlflowClient

1108

1109

class MlflowClient:

1110

tracking_uri: str

1111

_registry_uri: str

1112

1113

class Experiment:

1114

experiment_id: str

1115

name: str

1116

artifact_location: str

1117

lifecycle_stage: str

1118

tags: Dict[str, str]

1119

creation_time: int

1120

last_update_time: int

1121

1122

class Run:

1123

info: RunInfo

1124

data: RunData

1125

1126

class RunInfo:

1127

run_id: str

1128

run_name: str

1129

experiment_id: str

1130

user_id: str

1131

status: str

1132

start_time: int

1133

end_time: int

1134

artifact_uri: str

1135

lifecycle_stage: str

1136

1137

class RunData:

1138

metrics: List[Metric]

1139

params: List[Param]

1140

tags: List[RunTag]

1141

1142

class RegisteredModel:

1143

name: str

1144

creation_timestamp: int

1145

last_updated_timestamp: int

1146

description: str

1147

latest_versions: List[ModelVersion]

1148

tags: Dict[str, str]

1149

aliases: Dict[str, str]

1150

1151

class ModelVersion:

1152

name: str

1153

version: str

1154

creation_timestamp: int

1155

last_updated_timestamp: int

1156

description: str

1157

user_id: str

1158

current_stage: str

1159

source: str

1160

run_id: str

1161

status: str

1162

status_message: str

1163

tags: Dict[str, str]

1164

run_link: str

1165

aliases: List[str]

1166

1167

class FileInfo:

1168

path: str

1169

is_dir: bool

1170

file_size: int

1171

1172

class PagedList[T]:

1173

items: List[T]

1174

token: Optional[str]

1175

1176

class ViewType:

1177

ACTIVE_ONLY: str = "1"

1178

DELETED_ONLY: str = "2"

1179

ALL: str = "3"

1180

```