or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

artifact-config.mdartifacts.mdclient.mdconfig.mdenums.mdexceptions.mdhooks.mdindex.mdintegrations.mdmaterializers.mdmetadata-tags.mdmodels.mdpipelines-and-steps.mdpydantic-models.mdservices.mdstack-components.mdstacks.mdtypes.mdutilities.md

stack-components.mddocs/

0

# Stack Components

1

2

Base classes and implementations for ZenML stack components. Stack components are the building blocks of a ZenML stack, each providing specific infrastructure functionality.

3

4

## Component Types

5

6

ZenML provides 13 types of stack components, each serving a specific purpose in the ML infrastructure.

7

8

### Orchestrators

9

10

Orchestrators manage the execution of pipeline steps.

11

12

```python { .api }

13

class BaseOrchestrator:

14

"""

15

Abstract base class for orchestrators.

16

17

Orchestrators control where and how pipeline steps are executed.

18

"""

19

20

class LocalOrchestrator(BaseOrchestrator):

21

"""Orchestrator for local execution."""

22

23

class LocalDockerOrchestrator(BaseOrchestrator):

24

"""Orchestrator for local Docker execution."""

25

```

26

27

Import from:

28

29

```python

30

from zenml.orchestrators import (

31

BaseOrchestrator,

32

LocalOrchestrator,

33

LocalDockerOrchestrator

34

)

35

```

36

37

### Artifact Stores

38

39

Artifact stores handle storage and retrieval of artifacts.

40

41

```python { .api }

42

class BaseArtifactStore:

43

"""

44

Abstract base class for artifact stores.

45

46

Provides filesystem-like interface for artifact storage.

47

"""

48

49

class LocalArtifactStore(BaseArtifactStore):

50

"""Artifact store for local filesystem."""

51

```

52

53

Import from:

54

55

```python

56

from zenml.artifact_stores import (

57

BaseArtifactStore,

58

LocalArtifactStore

59

)

60

```

61

62

### Container Registries

63

64

Container registries store Docker images.

65

66

```python { .api }

67

class BaseContainerRegistry:

68

"""Abstract base class for container registries."""

69

70

class DefaultContainerRegistryFlavor:

71

"""Default/generic container registry flavor."""

72

73

class AzureContainerRegistryFlavor:

74

"""Flavor for Azure Container Registry."""

75

76

class DockerHubContainerRegistryFlavor:

77

"""Flavor for Docker Hub."""

78

79

class GCPContainerRegistryFlavor:

80

"""Flavor for Google Container Registry."""

81

82

class GitHubContainerRegistryFlavor:

83

"""Flavor for GitHub Container Registry."""

84

```

85

86

Import from:

87

88

```python

89

from zenml.container_registries import (

90

BaseContainerRegistry,

91

DefaultContainerRegistryFlavor

92

)

93

```

94

95

### Image Builders

96

97

Image builders create container images for pipeline execution.

98

99

```python { .api }

100

class BaseImageBuilder:

101

"""Abstract base class for image builders."""

102

103

class LocalImageBuilder(BaseImageBuilder):

104

"""Image builder for local Docker builds."""

105

106

class BuildContext:

107

"""Context information for building container images."""

108

```

109

110

Import from:

111

112

```python

113

from zenml.image_builders import (

114

BaseImageBuilder,

115

LocalImageBuilder,

116

BuildContext

117

)

118

```

119

120

### Step Operators

121

122

Step operators enable remote execution of individual steps.

123

124

```python { .api }

125

class BaseStepOperator:

126

"""

127

Abstract base class for step operators.

128

129

Step operators execute specific steps on remote infrastructure

130

(e.g., SageMaker, Vertex AI) while the orchestrator manages

131

the overall pipeline flow.

132

"""

133

```

134

135

Import from:

136

137

```python

138

from zenml.step_operators import BaseStepOperator

139

```

140

141

### Experiment Trackers

142

143

Experiment trackers log metrics, parameters, and artifacts.

144

145

```python { .api }

146

class BaseExperimentTracker:

147

"""

148

Abstract base class for experiment trackers.

149

150

Integrates with experiment tracking platforms like MLflow,

151

Weights & Biases, Neptune, etc.

152

"""

153

```

154

155

Import from:

156

157

```python

158

from zenml.experiment_trackers import BaseExperimentTracker

159

```

160

161

### Model Deployers

162

163

Model deployers handle model serving and deployment.

164

165

```python { .api }

166

class BaseModelDeployer:

167

"""

168

Abstract base class for model deployers.

169

170

Manages deployment of trained models to serving infrastructure.

171

"""

172

```

173

174

Import from:

175

176

```python

177

from zenml.model_deployers import BaseModelDeployer

178

```

179

180

### Model Registries

181

182

Model registries store and version trained models.

183

184

```python { .api }

185

class BaseModelRegistry:

186

"""

187

Abstract base class for model registries.

188

189

Provides versioned model storage separate from artifact stores.

190

"""

191

```

192

193

Import from:

194

195

```python

196

from zenml.model_registries import BaseModelRegistry

197

```

198

199

### Feature Stores

200

201

Feature stores manage feature data for ML models.

202

203

```python { .api }

204

class BaseFeatureStore:

205

"""

206

Abstract base class for feature stores.

207

208

Integrates with feature stores like Feast for feature management.

209

"""

210

```

211

212

Import from:

213

214

```python

215

from zenml.feature_stores import BaseFeatureStore

216

```

217

218

### Data Validators

219

220

Data validators perform data quality checks.

221

222

```python { .api }

223

class BaseDataValidator:

224

"""

225

Abstract base class for data validators.

226

227

Integrates with data validation frameworks like Great Expectations,

228

Deepchecks, Evidently, etc.

229

"""

230

```

231

232

Import from:

233

234

```python

235

from zenml.data_validators import BaseDataValidator

236

```

237

238

### Alerters

239

240

Alerters send notifications about pipeline events.

241

242

```python { .api }

243

class BaseAlerter:

244

"""

245

Abstract base class for alerters.

246

247

Sends notifications via Slack, Discord, email, etc.

248

"""

249

```

250

251

Import from:

252

253

```python

254

from zenml.alerter import BaseAlerter

255

```

256

257

### Annotators

258

259

Annotators integrate data annotation tools.

260

261

```python { .api }

262

class BaseAnnotator:

263

"""

264

Abstract base class for data annotation tools.

265

266

Integrates with annotation platforms like Label Studio, Argilla, etc.

267

"""

268

```

269

270

Import from:

271

272

```python

273

from zenml.annotators import BaseAnnotator

274

```

275

276

### Deployers

277

278

Deployers manage pipeline deployment to production.

279

280

```python { .api }

281

class BaseDeployer:

282

"""

283

Abstract base class for pipeline deployers.

284

285

Manages deployment of entire pipelines to production environments.

286

"""

287

288

class DockerDeployer(BaseDeployer):

289

"""Deployer for Docker-based pipeline deployments."""

290

```

291

292

Import from:

293

294

```python

295

from zenml.deployers import BaseDeployer, DockerDeployer

296

```

297

298

## Usage Examples

299

300

### Creating Custom Orchestrator

301

302

```python

303

from zenml.orchestrators import BaseOrchestrator, BaseOrchestratorConfig

304

from zenml.stack import StackComponentConfig

305

306

class MyOrchestratorConfig(BaseOrchestratorConfig):

307

"""Configuration for custom orchestrator."""

308

api_endpoint: str

309

api_key: str

310

311

class MyOrchestrator(BaseOrchestrator):

312

"""Custom orchestrator implementation."""

313

314

@property

315

def config(self) -> MyOrchestratorConfig:

316

"""Get typed configuration."""

317

return self._config

318

319

def prepare_pipeline_deployment(self, deployment, stack):

320

"""Prepare pipeline for execution."""

321

# Custom preparation logic

322

pass

323

324

def run(self, deployment, stack):

325

"""Execute the pipeline."""

326

# Custom execution logic

327

print(f"Running on {self.config.api_endpoint}")

328

```

329

330

### Using Stack Components via Client

331

332

```python

333

from zenml.client import Client

334

from zenml.enums import StackComponentType

335

336

client = Client()

337

338

# List orchestrators

339

orchestrators = client.list_stack_components(

340

type=StackComponentType.ORCHESTRATOR

341

)

342

343

for orch in orchestrators:

344

print(f"Orchestrator: {orch.name} ({orch.flavor})")

345

346

# Get artifact store details

347

artifact_store = client.get_stack_component(

348

name_or_id="s3_store",

349

component_type=StackComponentType.ARTIFACT_STORE

350

)

351

352

print(f"Artifact Store: {artifact_store.name}")

353

print(f"Configuration: {artifact_store.configuration}")

354

```

355

356

### Accessing Active Stack Components

357

358

```python

359

from zenml.client import Client

360

361

client = Client()

362

stack = client.active_stack

363

364

# Access orchestrator

365

print(f"Orchestrator: {stack.orchestrator.name}")

366

print(f"Flavor: {stack.orchestrator.flavor}")

367

368

# Access artifact store

369

print(f"Artifact Store: {stack.artifact_store.name}")

370

371

# Check for optional components

372

if stack.experiment_tracker:

373

print(f"Experiment Tracker: {stack.experiment_tracker.name}")

374

375

if stack.model_deployer:

376

print(f"Model Deployer: {stack.model_deployer.name}")

377

```

378

379

### Creating Stack with Components

380

381

```python

382

from zenml.client import Client

383

from zenml.enums import StackComponentType

384

385

client = Client()

386

387

# Create components

388

client.create_stack_component(

389

name="local_orch",

390

flavor="local",

391

component_type=StackComponentType.ORCHESTRATOR,

392

configuration={}

393

)

394

395

client.create_stack_component(

396

name="local_store",

397

flavor="local",

398

component_type=StackComponentType.ARTIFACT_STORE,

399

configuration={"path": "/tmp/zenml"}

400

)

401

402

client.create_stack_component(

403

name="mlflow_tracker",

404

flavor="mlflow",

405

component_type=StackComponentType.EXPERIMENT_TRACKER,

406

configuration={"tracking_uri": "http://localhost:5000"}

407

)

408

409

# Create stack

410

stack = client.create_stack(

411

name="ml_stack",

412

components={

413

"orchestrator": "local_orch",

414

"artifact_store": "local_store",

415

"experiment_tracker": "mlflow_tracker"

416

}

417

)

418

```

419

420

### Component Configuration Types

421

422

```python

423

from zenml.client import Client

424

425

client = Client()

426

427

# Get component with full config

428

component = client.get_stack_component(

429

name_or_id="sagemaker_orch",

430

component_type="orchestrator"

431

)

432

433

# Access configuration

434

config = component.configuration

435

print(f"Execution role: {config.get('execution_role')}")

436

print(f"Region: {config.get('region')}")

437

print(f"Instance type: {config.get('instance_type')}")

438

```

439