0
# Client and Authentication
1
2
The MLClient class is the main entry point for all Azure Machine Learning operations. It provides a unified interface to interact with Azure ML services and manages authentication, workspace connections, and operation groups.
3
4
## Capabilities
5
6
### MLClient Initialization
7
8
Creates the main client for Azure Machine Learning operations with credential and workspace configuration.
9
10
```python { .api }
11
class MLClient:
12
def __init__(
13
self,
14
credential,
15
subscription_id: str = None,
16
resource_group_name: str = None,
17
workspace_name: str = None,
18
registry_name: str = None,
19
**kwargs
20
):
21
"""
22
Initialize MLClient for Azure ML operations.
23
24
Parameters:
25
- credential: Azure credential (DefaultAzureCredential, ClientSecretCredential, etc.)
26
- subscription_id: Azure subscription ID
27
- resource_group_name: Resource group containing the workspace
28
- workspace_name: Azure ML workspace name
29
- registry_name: Registry name (for registry operations)
30
- cloud: Cloud environment ("AzureCloud", "AzureChinaCloud", etc.)
31
- **kwargs: Additional configuration options
32
"""
33
```
34
35
#### Usage Example
36
37
```python
38
from azure.ai.ml import MLClient
39
from azure.identity import DefaultAzureCredential, ClientSecretCredential
40
41
# Using default credential (recommended for development)
42
ml_client = MLClient(
43
credential=DefaultAzureCredential(),
44
subscription_id="your-subscription-id",
45
resource_group_name="your-resource-group",
46
workspace_name="your-workspace"
47
)
48
49
# Using service principal authentication
50
credential = ClientSecretCredential(
51
tenant_id="your-tenant-id",
52
client_id="your-client-id",
53
client_secret="your-client-secret"
54
)
55
56
ml_client = MLClient(
57
credential=credential,
58
subscription_id="your-subscription-id",
59
resource_group_name="your-resource-group",
60
workspace_name="your-workspace"
61
)
62
63
# For registry operations
64
registry_client = MLClient(
65
credential=DefaultAzureCredential(),
66
subscription_id="your-subscription-id",
67
resource_group_name="your-resource-group",
68
registry_name="your-registry"
69
)
70
```
71
72
### Operation Groups
73
74
MLClient organizes functionality into operation groups for different resource types.
75
76
```python { .api }
77
class MLClient:
78
@property
79
def jobs(self) -> JobOperations: ...
80
81
@property
82
def models(self) -> ModelOperations: ...
83
84
@property
85
def data(self) -> DataOperations: ...
86
87
@property
88
def environments(self) -> EnvironmentOperations: ...
89
90
@property
91
def components(self) -> ComponentOperations: ...
92
93
@property
94
def compute(self) -> ComputeOperations: ...
95
96
@property
97
def datastores(self) -> DatastoreOperations: ...
98
99
@property
100
def workspaces(self) -> WorkspaceOperations: ...
101
102
@property
103
def online_endpoints(self) -> OnlineEndpointOperations: ...
104
105
@property
106
def batch_endpoints(self) -> BatchEndpointOperations: ...
107
108
@property
109
def online_deployments(self) -> OnlineDeploymentOperations: ...
110
111
@property
112
def batch_deployments(self) -> BatchDeploymentOperations: ...
113
114
@property
115
def schedules(self) -> ScheduleOperations: ...
116
117
@property
118
def connections(self) -> WorkspaceConnectionsOperations: ...
119
120
@property
121
def registries(self) -> RegistryOperations: ...
122
123
@property
124
def feature_sets(self) -> FeatureSetOperations: ...
125
126
@property
127
def feature_stores(self) -> FeatureStoreOperations: ...
128
129
@property
130
def feature_store_entities(self) -> FeatureStoreEntityOperations: ...
131
132
@property
133
def indexes(self) -> IndexOperations: ...
134
135
@property
136
def serverless_endpoints(self) -> ServerlessEndpointOperations: ...
137
138
@property
139
def marketplace_subscriptions(self) -> MarketplaceSubscriptionOperations: ...
140
```
141
142
#### Usage Example
143
144
```python
145
from azure.ai.ml import MLClient
146
from azure.identity import DefaultAzureCredential
147
148
ml_client = MLClient(
149
credential=DefaultAzureCredential(),
150
subscription_id="your-subscription-id",
151
resource_group_name="your-resource-group",
152
workspace_name="your-workspace"
153
)
154
155
# Access different operation groups
156
jobs = ml_client.jobs.list()
157
models = ml_client.models.list()
158
compute_targets = ml_client.compute.list()
159
environments = ml_client.environments.list()
160
```
161
162
### Load Functions
163
164
Utility functions for loading Azure ML entities from YAML files.
165
166
```python { .api }
167
def load_job(source: str) -> Job:
168
"""Load job from YAML file."""
169
170
def load_model(source: str) -> Model:
171
"""Load model from YAML file."""
172
173
def load_data(source: str) -> Data:
174
"""Load data asset from YAML file."""
175
176
def load_environment(source: str) -> Environment:
177
"""Load environment from YAML file."""
178
179
def load_component(source: str) -> Component:
180
"""Load component from YAML file."""
181
182
def load_compute(source: str) -> Compute:
183
"""Load compute target from YAML file."""
184
185
def load_datastore(source: str) -> Datastore:
186
"""Load datastore from YAML file."""
187
188
def load_workspace(source: str) -> Workspace:
189
"""Load workspace from YAML file."""
190
191
def load_online_endpoint(source: str) -> OnlineEndpoint:
192
"""Load online endpoint from YAML file."""
193
194
def load_batch_endpoint(source: str) -> BatchEndpoint:
195
"""Load batch endpoint from YAML file."""
196
197
def load_online_deployment(source: str) -> OnlineDeployment:
198
"""Load online deployment from YAML file."""
199
200
def load_batch_deployment(source: str) -> BatchDeployment:
201
"""Load batch deployment from YAML file."""
202
203
def load_connection(source: str) -> WorkspaceConnection:
204
"""Load workspace connection from YAML file."""
205
206
def load_registry(source: str) -> Registry:
207
"""Load registry from YAML file."""
208
209
def load_feature_set(source: str) -> FeatureSet:
210
"""Load feature set from YAML file."""
211
212
def load_feature_store(source: str) -> FeatureStore:
213
"""Load feature store from YAML file."""
214
215
def load_feature_store_entity(source: str) -> FeatureStoreEntity:
216
"""Load feature store entity from YAML file."""
217
218
def load_index(source: str) -> Index:
219
"""Load index from YAML file."""
220
221
def load_serverless_endpoint(source: str) -> ServerlessEndpoint:
222
"""Load serverless endpoint from YAML file."""
223
224
def load_marketplace_subscription(source: str) -> MarketplaceSubscription:
225
"""Load marketplace subscription from YAML file."""
226
227
def load_capability_host(source: str) -> CapabilityHost:
228
"""Load capability host from YAML file."""
229
230
def load_model_package(source: str) -> ModelPackage:
231
"""Load model package from YAML file."""
232
233
def load_workspace_connection(source: str) -> WorkspaceConnection:
234
"""Load workspace connection from YAML file."""
235
```
236
237
#### Usage Example
238
239
```python
240
from azure.ai.ml import load_job, load_model, load_environment
241
242
# Load entities from YAML files
243
job = load_job("./job.yml")
244
model = load_model("./model.yml")
245
environment = load_environment("./environment.yml")
246
247
# Submit the loaded job
248
submitted_job = ml_client.jobs.create_or_update(job)
249
```
250
251
## Types
252
253
```python { .api }
254
class ValidationException(Exception):
255
"""Exception raised for validation errors."""
256
257
class ErrorCategory:
258
USER_ERROR = "UserError"
259
SYSTEM_ERROR = "SystemError"
260
UNKNOWN = "Unknown"
261
262
class ErrorTarget:
263
"""Error target constants for exception handling."""
264
265
class ValidationErrorType:
266
INVALID_VALUE = "INVALID VALUE"
267
UNKNOWN_FIELD = "UNKNOWN FIELD"
268
MISSING_FIELD = "MISSING FIELD"
269
FILE_OR_FOLDER_NOT_FOUND = "FILE OR FOLDER NOT FOUND"
270
CANNOT_SERIALIZE = "CANNOT DUMP"
271
CANNOT_PARSE = "CANNOT PARSE"
272
RESOURCE_NOT_FOUND = "RESOURCE NOT FOUND"
273
GENERIC = "GENERIC"
274
```