Skip to content

Models

zenml.models

Pydantic models for the various concepts in ZenML.

Attributes

__all__ = ['BaseRequest', 'BaseResponse', 'BaseUpdate', 'BaseIdentifiedResponse', 'BaseResponseBody', 'BaseResponseMetadata', 'BaseResponseResources', 'BaseDatedResponseBody', 'BaseZenModel', 'BasePluginFlavorResponse', 'UserScopedRequest', 'UserScopedFilter', 'UserScopedResponse', 'UserScopedResponseBody', 'UserScopedResponseMetadata', 'WorkspaceScopedRequest', 'WorkspaceScopedFilter', 'WorkspaceScopedResponse', 'WorkspaceScopedResponseBody', 'WorkspaceScopedResponseMetadata', 'WorkspaceScopedResponseResources', 'WorkspaceScopedFilter', 'BaseFilter', 'StrFilter', 'BoolFilter', 'NumericFilter', 'UUIDFilter', 'TaggableFilter', 'Page', 'ActionFilter', 'ActionRequest', 'ActionResponse', 'ActionResponseBody', 'ActionResponseMetadata', 'ActionResponseResources', 'ActionUpdate', 'ActionFlavorResponse', 'ActionFlavorResponseBody', 'ActionFlavorResponseMetadata', 'ActionFlavorResponseResources', 'APIKey', 'APIKeyRequest', 'APIKeyUpdate', 'APIKeyFilter', 'APIKeyResponse', 'APIKeyResponseBody', 'APIKeyResponseMetadata', 'APIKeyInternalResponse', 'APIKeyInternalUpdate', 'APIKeyRotateRequest', 'ArtifactFilter', 'ArtifactRequest', 'ArtifactResponse', 'ArtifactResponseBody', 'ArtifactResponseMetadata', 'ArtifactUpdate', 'ArtifactVersionRequest', 'ArtifactVersionFilter', 'ArtifactVersionResponse', 'ArtifactVersionResponseBody', 'ArtifactVersionResponseMetadata', 'ArtifactVersionUpdate', 'ArtifactVisualizationRequest', 'ArtifactVisualizationResponse', 'ArtifactVisualizationResponseBody', 'ArtifactVisualizationResponseMetadata', 'CodeReferenceRequest', 'CodeReferenceResponse', 'CodeReferenceResponseBody', 'CodeReferenceResponseMetadata', 'CodeRepositoryUpdate', 'CodeRepositoryFilter', 'CodeRepositoryRequest', 'CodeRepositoryResponse', 'CodeRepositoryResponseBody', 'CodeRepositoryResponseMetadata', 'ComponentBase', 'ComponentRequest', 'ComponentUpdate', 'ComponentFilter', 'ComponentResponse', 'ComponentResponseBody', 'ComponentResponseMetadata', 'ComponentResponseResources', 'EventSourceFlavorResponse', 'EventSourceFlavorResponseBody', 'EventSourceFlavorResponseMetadata', 'EventSourceFlavorResponseResources', 'FlavorRequest', 'FlavorUpdate', 'FlavorFilter', 'FlavorResponse', 'FlavorResponseBody', 'FlavorResponseMetadata', 'LogsRequest', 'LogsResponse', 'LogsResponseBody', 'LogsResponseMetadata', 'ModelFilter', 'ModelRequest', 'ModelResponse', 'ModelResponseBody', 'ModelResponseMetadata', 'ModelUpdate', 'ModelVersionFilter', 'ModelVersionRequest', 'ModelVersionResponse', 'ModelVersionResponseBody', 'ModelVersionResponseMetadata', 'ModelVersionResponseResources', 'ModelVersionUpdate', 'ModelVersionArtifactFilter', 'ModelVersionArtifactRequest', 'ModelVersionArtifactResponse', 'ModelVersionArtifactResponseBody', 'ModelVersionPipelineRunFilter', 'ModelVersionPipelineRunRequest', 'ModelVersionPipelineRunResponse', 'ModelVersionPipelineRunResponseBody', 'OAuthDeviceUpdate', 'OAuthDeviceFilter', 'OAuthDeviceResponse', 'OAuthDeviceResponseBody', 'OAuthDeviceResponseMetadata', 'OAuthDeviceInternalRequest', 'OAuthDeviceInternalUpdate', 'OAuthDeviceInternalResponse', 'PipelineRequest', 'PipelineUpdate', 'PipelineFilter', 'PipelineResponse', 'PipelineResponseBody', 'PipelineResponseMetadata', 'PipelineResponseResources', 'PipelineBuildBase', 'PipelineBuildRequest', 'PipelineBuildFilter', 'PipelineBuildResponse', 'PipelineBuildResponseBody', 'PipelineBuildResponseMetadata', 'PipelineDeploymentBase', 'PipelineDeploymentRequest', 'PipelineDeploymentFilter', 'PipelineDeploymentResponse', 'PipelineDeploymentResponseBody', 'PipelineDeploymentResponseMetadata', 'PipelineRunRequest', 'PipelineRunUpdate', 'PipelineRunFilter', 'PipelineRunResponse', 'PipelineRunResponseBody', 'PipelineRunResponseMetadata', 'PipelineRunResponseResources', 'RunTemplateRequest', 'RunTemplateUpdate', 'RunTemplateResponse', 'RunTemplateResponseBody', 'RunTemplateResponseMetadata', 'RunTemplateResponseResources', 'RunTemplateFilter', 'RunMetadataRequest', 'ScheduleRequest', 'ScheduleUpdate', 'ScheduleFilter', 'ScheduleResponse', 'ScheduleResponseBody', 'ScheduleResponseMetadata', 'SecretFilter', 'SecretRequest', 'SecretResponse', 'SecretResponseBody', 'SecretResponseMetadata', 'SecretUpdate', 'ServiceResponse', 'ServiceResponseBody', 'ServiceResponseMetadata', 'ServiceUpdate', 'ServiceFilter', 'ServiceRequest', 'ServiceResponseResources', 'ServerActivationRequest', 'ServerSettingsResponse', 'ServerSettingsResponseResources', 'ServerSettingsResponseBody', 'ServerSettingsResponseMetadata', 'ServerSettingsUpdate', 'ServiceAccountFilter', 'ServiceAccountResponseBody', 'ServiceAccountResponseMetadata', 'ServiceAccountUpdate', 'ServiceAccountRequest', 'ServiceAccountResponse', 'ServiceConnectorRequest', 'ServiceConnectorUpdate', 'ServiceConnectorFilter', 'ServiceConnectorResponse', 'ServiceConnectorResponseBody', 'ServiceConnectorResponseMetadata', 'StackRequest', 'StackUpdate', 'StackFilter', 'StackResponse', 'StackResponseBody', 'StackResponseMetadata', 'StepRunRequest', 'StepRunUpdate', 'StepRunFilter', 'StepRunResponse', 'StepRunResponseBody', 'StepRunResponseMetadata', 'StepRunResponseResources', 'TagFilter', 'TagResourceResponse', 'TagResourceResponseBody', 'TagResourceRequest', 'TagResponse', 'TagResponseBody', 'TagRequest', 'TagUpdate', 'TriggerResponse', 'TriggerRequest', 'TriggerFilter', 'TriggerUpdate', 'TriggerResponseBody', 'TriggerResponseMetadata', 'TriggerResponseResources', 'TriggerExecutionRequest', 'TriggerExecutionFilter', 'TriggerExecutionResponse', 'TriggerExecutionResponseBody', 'TriggerExecutionResponseMetadata', 'TriggerExecutionResponseResources', 'EventSourceResponse', 'EventSourceRequest', 'EventSourceFilter', 'EventSourceUpdate', 'EventSourceResponseBody', 'EventSourceResponseMetadata', 'EventSourceResponseResources', 'UserRequest', 'UserUpdate', 'UserFilter', 'UserResponse', 'UserResponseBody', 'UserResponseMetadata', 'WorkspaceRequest', 'WorkspaceUpdate', 'WorkspaceFilter', 'WorkspaceResponse', 'WorkspaceResponseBody', 'WorkspaceResponseMetadata', 'AuthenticationMethodModel', 'DeployedStack', 'ServiceConnectorResourcesModel', 'ServiceConnectorTypeModel', 'ServiceConnectorTypedResourcesModel', 'ServiceConnectorRequirements', 'ResourceTypeModel', 'UserAuthModel', 'ExternalUserModel', 'BuildItem', 'LoadedVisualization', 'ServerLoadInfo', 'ServerModel', 'ServerDatabaseType', 'ServerDeploymentType', 'StackDeploymentConfig', 'StackDeploymentInfo', 'OAuthDeviceAuthorizationRequest', 'OAuthDeviceAuthorizationResponse', 'OAuthDeviceTokenRequest', 'OAuthDeviceUserAgentHeader', 'OAuthDeviceVerificationRequest', 'OAuthRedirectResponse', 'OAuthTokenResponse', 'ComponentInfo', 'ServiceConnectorInfo', 'ServiceConnectorResourcesInfo', 'ResourcesInfo', 'RunMetadataEntry', 'RunMetadataResource'] module-attribute

Classes

APIKey

Bases: BaseModel

Encoded model for API keys.

Functions
decode_api_key(encoded_key: str) -> APIKey classmethod

Decodes an API key from a base64 string.

Parameters:

Name Type Description Default
encoded_key str

The encoded API key.

required

Returns:

Type Description
APIKey

The decoded API key.

Raises:

Type Description
ValueError

If the key is not valid.

Source code in src/zenml/models/v2/core/api_key.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@classmethod
def decode_api_key(cls, encoded_key: str) -> "APIKey":
    """Decodes an API key from a base64 string.

    Args:
        encoded_key: The encoded API key.

    Returns:
        The decoded API key.

    Raises:
        ValueError: If the key is not valid.
    """
    if encoded_key.startswith(ZENML_API_KEY_PREFIX):
        encoded_key = encoded_key[len(ZENML_API_KEY_PREFIX) :]
    try:
        json_key = b64_decode(encoded_key)
        return cls.model_validate_json(json_key)
    except Exception:
        raise ValueError("Invalid API key.")
encode() -> str

Encodes the API key in a base64 string that includes the key ID and prefix.

Returns:

Type Description
str

The encoded API key.

Source code in src/zenml/models/v2/core/api_key.py
72
73
74
75
76
77
78
79
def encode(self) -> str:
    """Encodes the API key in a base64 string that includes the key ID and prefix.

    Returns:
        The encoded API key.
    """
    encoded_key = b64_encode(self.model_dump_json())
    return f"{ZENML_API_KEY_PREFIX}{encoded_key}"

APIKeyFilter

Bases: BaseFilter

Filter model for API keys.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to apply the service account scope as an additional filter.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/api_key.py
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to apply the service account scope as an additional filter.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self.service_account:
        scope_filter = (
            getattr(table, "service_account_id") == self.service_account
        )
        query = query.where(scope_filter)

    return query
set_service_account(service_account_id: UUID) -> None

Set the service account by which to scope this query.

Parameters:

Name Type Description Default
service_account_id UUID

The service account ID.

required
Source code in src/zenml/models/v2/core/api_key.py
377
378
379
380
381
382
383
def set_service_account(self, service_account_id: UUID) -> None:
    """Set the service account by which to scope this query.

    Args:
        service_account_id: The service account ID.
    """
    self.service_account = service_account_id

APIKeyInternalResponse

Bases: APIKeyResponse

Response model for API keys used internally.

Functions
verify_key(key: str) -> bool

Verifies a given key against the stored (hashed) key(s).

Parameters:

Name Type Description Default
key str

Input key to be verified.

required

Returns:

Type Description
bool

True if the keys match.

Source code in src/zenml/models/v2/core/api_key.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def verify_key(
    self,
    key: str,
) -> bool:
    """Verifies a given key against the stored (hashed) key(s).

    Args:
        key: Input key to be verified.

    Returns:
        True if the keys match.
    """
    # even when the hashed key is not set, we still want to execute
    # the hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    key_hash: Optional[str] = None
    context = CryptContext(schemes=["bcrypt"], deprecated="auto")
    if self.key is not None and self.active:
        key_hash = self.key
    result = context.verify(key, key_hash)

    # same for the previous key, if set and if it's still valid
    key_hash = None
    if (
        self.previous_key is not None
        and self.last_rotated is not None
        and self.active
        and self.retain_period_minutes > 0
    ):
        # check if the previous key is still valid
        if utc_now(
            tz_aware=self.last_rotated
        ) - self.last_rotated < timedelta(
            minutes=self.retain_period_minutes
        ):
            key_hash = self.previous_key
    previous_result = context.verify(key, key_hash)

    return result or previous_result

APIKeyInternalUpdate

Bases: APIKeyUpdate

Update model for API keys used internally.

APIKeyRequest

Bases: BaseRequest

Request model for API keys.

APIKeyResponse

Bases: BaseIdentifiedResponse[APIKeyResponseBody, APIKeyResponseMetadata, APIKeyResponseResources]

Response model for API keys.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

key: Optional[str] property

The key property.

Returns:

Type Description
Optional[str]

the value of the property.

last_login: Optional[datetime] property

The last_login property.

Returns:

Type Description
Optional[datetime]

the value of the property.

last_rotated: Optional[datetime] property

The last_rotated property.

Returns:

Type Description
Optional[datetime]

the value of the property.

retain_period_minutes: int property

The retain_period_minutes property.

Returns:

Type Description
int

the value of the property.

service_account: ServiceAccountResponse property

The service_account property.

Returns:

Type Description
ServiceAccountResponse

the value of the property.

Functions
get_hydrated_version() -> APIKeyResponse

Get the hydrated version of this API key.

Returns:

Type Description
APIKeyResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/api_key.py
198
199
200
201
202
203
204
205
206
207
208
209
def get_hydrated_version(self) -> "APIKeyResponse":
    """Get the hydrated version of this API key.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_api_key(
        service_account_id=self.service_account.id,
        api_key_name_or_id=self.id,
    )
set_key(key: str) -> None

Sets the API key and encodes it.

Parameters:

Name Type Description Default
key str

The API key value to be set.

required
Source code in src/zenml/models/v2/core/api_key.py
212
213
214
215
216
217
218
def set_key(self, key: str) -> None:
    """Sets the API key and encodes it.

    Args:
        key: The API key value to be set.
    """
    self.get_body().key = APIKey(id=self.id, key=key).encode()

APIKeyResponseBody

Bases: BaseDatedResponseBody

Response body for API keys.

APIKeyResponseMetadata

Bases: BaseResponseMetadata

Response metadata for API keys.

APIKeyRotateRequest

Bases: BaseModel

Request model for API key rotation.

APIKeyUpdate

Bases: BaseUpdate

Update model for API keys.

ActionFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all actions.

ActionFlavorResponse

Bases: BasePluginFlavorResponse[ActionFlavorResponseBody, ActionFlavorResponseMetadata, ActionFlavorResponseResources]

Response model for Action Flavors.

Attributes
config_schema: Dict[str, Any] property

The source_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

ActionFlavorResponseBody

Bases: BasePluginResponseBody

Response body for action flavors.

ActionFlavorResponseMetadata

Bases: BasePluginResponseMetadata

Response metadata for action flavors.

ActionFlavorResponseResources

Bases: BasePluginResponseResources

Response resources for action flavors.

ActionRequest

Bases: WorkspaceScopedRequest

Model for creating a new action.

ActionResponse

Bases: WorkspaceScopedResponse[ActionResponseBody, ActionResponseMetadata, ActionResponseResources]

Response model for actions.

Attributes
auth_window: int property

The auth_window property.

Returns:

Type Description
int

the value of the property.

configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

flavor: str property

The flavor property.

Returns:

Type Description
str

the value of the property.

plugin_subtype: PluginSubType property

The plugin_subtype property.

Returns:

Type Description
PluginSubType

the value of the property.

service_account: UserResponse property

The service_account property.

Returns:

Type Description
UserResponse

the value of the property.

Functions
get_hydrated_version() -> ActionResponse

Get the hydrated version of this action.

Returns:

Type Description
ActionResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/action.py
184
185
186
187
188
189
190
191
192
def get_hydrated_version(self) -> "ActionResponse":
    """Get the hydrated version of this action.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_action(self.id)
set_configuration(configuration: Dict[str, Any]) -> None

Set the configuration property.

Parameters:

Name Type Description Default
configuration Dict[str, Any]

The value to set.

required
Source code in src/zenml/models/v2/core/action.py
240
241
242
243
244
245
246
def set_configuration(self, configuration: Dict[str, Any]) -> None:
    """Set the `configuration` property.

    Args:
        configuration: The value to set.
    """
    self.get_metadata().configuration = configuration

ActionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for actions.

ActionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for actions.

ActionResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the action entity.

ActionUpdate

Bases: BaseUpdate

Update model for actions.

Functions
from_response(response: ActionResponse) -> ActionUpdate classmethod

Create an update model from a response model.

Parameters:

Name Type Description Default
response ActionResponse

The response model to create the update model from.

required

Returns:

Type Description
ActionUpdate

The update model.

Source code in src/zenml/models/v2/core/action.py
116
117
118
119
120
121
122
123
124
125
126
127
128
@classmethod
def from_response(cls, response: "ActionResponse") -> "ActionUpdate":
    """Create an update model from a response model.

    Args:
        response: The response model to create the update model from.

    Returns:
        The update model.
    """
    return ActionUpdate(
        configuration=copy.deepcopy(response.configuration),
    )

ArtifactFilter

Bases: TaggableFilter

Model to enable advanced filtering of artifacts.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query for Artifacts.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/artifact.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query for Artifacts.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == SORT_BY_LATEST_VERSION_KEY:
        # Subquery to find the latest version per artifact
        latest_version_subquery = (
            select(
                ArtifactSchema.id,
                case(
                    (
                        func.max(ArtifactVersionSchema.created).is_(None),
                        ArtifactSchema.created,
                    ),
                    else_=func.max(ArtifactVersionSchema.created),
                ).label("latest_version_created"),
            )
            .outerjoin(
                ArtifactVersionSchema,
                ArtifactSchema.id == ArtifactVersionSchema.artifact_id,  # type: ignore[arg-type]
            )
            .group_by(col(ArtifactSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_version_subquery.c.latest_version_created,
        ).where(ArtifactSchema.id == latest_version_subquery.c.id)

        # Apply sorting based on the operand
        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_version_subquery.c.latest_version_created),
                asc(ArtifactSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_version_subquery.c.latest_version_created),
                desc(ArtifactSchema.id),
            )
        return query

    # For other sorting cases, delegate to the parent class
    return super().apply_sorting(query=query, table=table)

ArtifactRequest

Bases: BaseRequest

Artifact request model.

ArtifactResponse

Bases: BaseIdentifiedResponse[ArtifactResponseBody, ArtifactResponseMetadata, ArtifactResponseResources]

Artifact response model.

Attributes
has_custom_name: bool property

The has_custom_name property.

Returns:

Type Description
bool

the value of the property.

latest_version_id: Optional[UUID] property

The latest_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_version_name: Optional[str] property

The latest_version_name property.

Returns:

Type Description
Optional[str]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

versions: Dict[str, ArtifactVersionResponse] property

Get a list of all versions of this artifact.

Returns:

Type Description
Dict[str, ArtifactVersionResponse]

A list of all versions of this artifact.

Functions
get_hydrated_version() -> ArtifactResponse

Get the hydrated version of this artifact.

Returns:

Type Description
ArtifactResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact.py
117
118
119
120
121
122
123
124
125
def get_hydrated_version(self) -> "ArtifactResponse":
    """Get the hydrated version of this artifact.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact(self.id)

ArtifactResponseBody

Bases: BaseDatedResponseBody

Response body for artifacts.

ArtifactResponseMetadata

Bases: BaseResponseMetadata

Response metadata for artifacts.

ArtifactUpdate

Bases: BaseModel

Artifact update model.

ArtifactVersionFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of artifact versions.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[Union[ColumnElement[bool]]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[Union[ColumnElement[bool]]]

A list of custom filters.

Source code in src/zenml/models/v2/core/artifact_version.py
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List[Union["ColumnElement[bool]"]]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, or_, select

    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
        ModelSchema,
        ModelVersionArtifactSchema,
        ModelVersionSchema,
        PipelineRunSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        StepRunInputArtifactSchema,
        StepRunOutputArtifactSchema,
        StepRunSchema,
    )

    if self.name:
        value, filter_operator = self._resolve_operator(self.name)
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        artifact_name_filter = and_(
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            filter_.generate_query_conditions(ArtifactSchema),
        )
        custom_filters.append(artifact_name_filter)

    if self.only_unused:
        unused_filter = and_(
            ArtifactVersionSchema.id.notin_(  # type: ignore[attr-defined]
                select(StepRunOutputArtifactSchema.artifact_id)
            ),
            ArtifactVersionSchema.id.notin_(  # type: ignore[attr-defined]
                select(StepRunInputArtifactSchema.artifact_id)
            ),
        )
        custom_filters.append(unused_filter)

    if self.model_version_id:
        value, operator = self._resolve_operator(self.model_version_id)

        model_version_filter = and_(
            ArtifactVersionSchema.id
            == ModelVersionArtifactSchema.artifact_version_id,
            ModelVersionArtifactSchema.model_version_id
            == ModelVersionSchema.id,
            FilterGenerator(ModelVersionSchema)
            .define_filter(column="id", value=value, operator=operator)
            .generate_query_conditions(ModelVersionSchema),
        )
        custom_filters.append(model_version_filter)

    if self.has_custom_name is not None:
        custom_name_filter = and_(
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            ArtifactSchema.has_custom_name == self.has_custom_name,
        )
        custom_filters.append(custom_name_filter)

    if self.model:
        model_filter = and_(
            ArtifactVersionSchema.id
            == ModelVersionArtifactSchema.artifact_version_id,
            ModelVersionArtifactSchema.model_version_id
            == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)

    if self.pipeline_run:
        pipeline_run_filter = and_(
            or_(
                and_(
                    ArtifactVersionSchema.id
                    == StepRunOutputArtifactSchema.artifact_id,
                    StepRunOutputArtifactSchema.step_id
                    == StepRunSchema.id,
                ),
                and_(
                    ArtifactVersionSchema.id
                    == StepRunInputArtifactSchema.artifact_id,
                    StepRunInputArtifactSchema.step_id == StepRunSchema.id,
                ),
            ),
            StepRunSchema.pipeline_run_id == PipelineRunSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline_run, table=PipelineRunSchema
            ),
        )
        custom_filters.append(pipeline_run_filter)

    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == ArtifactVersionSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.ARTIFACT_VERSION.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters

ArtifactVersionRequest

Bases: WorkspaceScopedRequest

Request model for artifact versions.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum str length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/artifact_version.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
@field_validator("version")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum str length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value

ArtifactVersionResponse

Bases: WorkspaceScopedResponse[ArtifactVersionResponseBody, ArtifactVersionResponseMetadata, ArtifactVersionResponseResources]

Response model for artifact versions.

Attributes
artifact: ArtifactResponse property

The artifact property.

Returns:

Type Description
ArtifactResponse

the value of the property.

artifact_store_id: Optional[UUID] property

The artifact_store_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

data_type: Source property

The data_type property.

Returns:

Type Description
Source

the value of the property.

materializer: Source property

The materializer property.

Returns:

Type Description
Source

the value of the property.

name: str property

The name property.

Returns:

Type Description
str

the value of the property.

producer_pipeline_run_id: Optional[UUID] property

The producer_pipeline_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

producer_step_run_id: Optional[UUID] property

The producer_step_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

run: PipelineRunResponse property

Get the pipeline run that produced this artifact.

Returns:

Type Description
PipelineRunResponse

The pipeline run that produced this artifact.

run_metadata: Dict[str, MetadataType] property

The metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

save_type: ArtifactSaveType property

The save_type property.

Returns:

Type Description
ArtifactSaveType

the value of the property.

step: StepRunResponse property

Get the step that produced this artifact.

Returns:

Type Description
StepRunResponse

The step that produced this artifact.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

type: ArtifactType property

The type property.

Returns:

Type Description
ArtifactType

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

version: Union[str, int] property

The version property.

Returns:

Type Description
Union[str, int]

the value of the property.

visualizations: Optional[List[ArtifactVisualizationResponse]] property

The visualizations property.

Returns:

Type Description
Optional[List[ArtifactVisualizationResponse]]

the value of the property.

Functions
download_files(path: str, overwrite: bool = False) -> None

Downloads data for an artifact with no materializing.

Any artifacts will be saved as a zip file to the given path.

Parameters:

Name Type Description Default
path str

The path to save the binary data to.

required
overwrite bool

Whether to overwrite the file if it already exists.

False

Raises:

Type Description
ValueError

If the path does not end with '.zip'.

Source code in src/zenml/models/v2/core/artifact_version.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def download_files(self, path: str, overwrite: bool = False) -> None:
    """Downloads data for an artifact with no materializing.

    Any artifacts will be saved as a zip file to the given path.

    Args:
        path: The path to save the binary data to.
        overwrite: Whether to overwrite the file if it already exists.

    Raises:
        ValueError: If the path does not end with '.zip'.
    """
    if not path.endswith(".zip"):
        raise ValueError(
            "The path should end with '.zip' to save the binary data."
        )
    from zenml.artifacts.utils import (
        download_artifact_files_from_response,
    )

    download_artifact_files_from_response(
        self,
        path=path,
        overwrite=overwrite,
    )
get_hydrated_version() -> ArtifactVersionResponse

Get the hydrated version of this artifact version.

Returns:

Type Description
ArtifactVersionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact_version.py
261
262
263
264
265
266
267
268
269
def get_hydrated_version(self) -> "ArtifactVersionResponse":
    """Get the hydrated version of this artifact version.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact_version(self.id)
load() -> Any

Materializes (loads) the data stored in this artifact.

Returns:

Type Description
Any

The materialized data.

Source code in src/zenml/models/v2/core/artifact_version.py
423
424
425
426
427
428
429
430
431
def load(self) -> Any:
    """Materializes (loads) the data stored in this artifact.

    Returns:
        The materialized data.
    """
    from zenml.artifacts.utils import load_artifact_from_response

    return load_artifact_from_response(self)
visualize(title: Optional[str] = None) -> None

Visualize the artifact in notebook environments.

Parameters:

Name Type Description Default
title Optional[str]

Optional title to show before the visualizations.

None
Source code in src/zenml/models/v2/core/artifact_version.py
459
460
461
462
463
464
465
466
467
def visualize(self, title: Optional[str] = None) -> None:
    """Visualize the artifact in notebook environments.

    Args:
        title: Optional title to show before the visualizations.
    """
    from zenml.utils.visualization_utils import visualize_artifact

    visualize_artifact(self, title=title)

ArtifactVersionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for artifact versions.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum str length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/artifact_version.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@field_validator("version")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum str length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value

ArtifactVersionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for artifact versions.

ArtifactVersionUpdate

Bases: BaseModel

Artifact version update model.

ArtifactVisualizationRequest

Bases: BaseRequest

Request model for artifact visualization.

ArtifactVisualizationResponse

Bases: BaseIdentifiedResponse[ArtifactVisualizationResponseBody, ArtifactVisualizationResponseMetadata, ArtifactVisualizationResponseResources]

Response model for artifact visualizations.

Attributes
artifact_version_id: UUID property

The artifact_version_id property.

Returns:

Type Description
UUID

the value of the property.

type: VisualizationType property

The type property.

Returns:

Type Description
VisualizationType

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ArtifactVisualizationResponse

Get the hydrated version of this artifact visualization.

Returns:

Type Description
ArtifactVisualizationResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact_visualization.py
70
71
72
73
74
75
76
77
78
def get_hydrated_version(self) -> "ArtifactVisualizationResponse":
    """Get the hydrated version of this artifact visualization.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact_visualization(self.id)

ArtifactVisualizationResponseBody

Bases: BaseDatedResponseBody

Response body for artifact visualizations.

ArtifactVisualizationResponseMetadata

Bases: BaseResponseMetadata

Response metadata model for artifact visualizations.

AuthenticationMethodModel(config_class: Optional[Type[BaseModel]] = None, **values: Any)

Bases: BaseModel

Authentication method specification.

Describes the schema for the configuration and secrets that need to be provided to configure an authentication method.

Initialize the authentication method.

Parameters:

Name Type Description Default
config_class Optional[Type[BaseModel]]

The configuration class for the authentication method.

None
**values Any

The data to initialize the authentication method with.

{}
Source code in src/zenml/models/v2/misc/service_connector_type.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self, config_class: Optional[Type[BaseModel]] = None, **values: Any
):
    """Initialize the authentication method.

    Args:
        config_class: The configuration class for the authentication
            method.
        **values: The data to initialize the authentication method with.
    """
    if config_class:
        values["config_schema"] = config_class.model_json_schema()

    super().__init__(**values)
    self._config_class = config_class
Attributes
config_class: Optional[Type[BaseModel]] property

Get the configuration class for the authentication method.

Returns:

Type Description
Optional[Type[BaseModel]]

The configuration class for the authentication method.

Functions
supports_temporary_credentials() -> bool

Check if the authentication method supports temporary credentials.

Returns:

Type Description
bool

True if the authentication method supports temporary credentials,

bool

False otherwise.

Source code in src/zenml/models/v2/misc/service_connector_type.py
157
158
159
160
161
162
163
164
165
166
167
168
def supports_temporary_credentials(self) -> bool:
    """Check if the authentication method supports temporary credentials.

    Returns:
        True if the authentication method supports temporary credentials,
        False otherwise.
    """
    return (
        self.min_expiration_seconds is not None
        or self.max_expiration_seconds is not None
        or self.default_expiration_seconds is not None
    )
validate_expiration(expiration_seconds: Optional[int]) -> Optional[int]

Validate the expiration time.

Parameters:

Name Type Description Default
expiration_seconds Optional[int]

The expiration time in seconds. If None, the default expiration time is used, if applicable.

required

Returns:

Type Description
Optional[int]

The expiration time in seconds or None if not applicable.

Raises:

Type Description
ValueError

If the expiration time is not valid.

Source code in src/zenml/models/v2/misc/service_connector_type.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def validate_expiration(
    self, expiration_seconds: Optional[int]
) -> Optional[int]:
    """Validate the expiration time.

    Args:
        expiration_seconds: The expiration time in seconds. If None, the
            default expiration time is used, if applicable.

    Returns:
        The expiration time in seconds or None if not applicable.

    Raises:
        ValueError: If the expiration time is not valid.
    """
    if not self.supports_temporary_credentials():
        if expiration_seconds is not None:
            # Expiration is not supported
            raise ValueError(
                "Expiration time is not supported for this authentication "
                f"method but a value was provided: {expiration_seconds}"
            )

        return None

    expiration_seconds = (
        expiration_seconds or self.default_expiration_seconds
    )

    if expiration_seconds is None:
        return None

    if self.min_expiration_seconds is not None:
        if expiration_seconds < self.min_expiration_seconds:
            raise ValueError(
                f"Expiration time must be at least "
                f"{self.min_expiration_seconds} seconds."
            )

    if self.max_expiration_seconds is not None:
        if expiration_seconds > self.max_expiration_seconds:
            raise ValueError(
                f"Expiration time must be at most "
                f"{self.max_expiration_seconds} seconds."
            )

    return expiration_seconds

BaseDatedResponseBody

Bases: BaseResponseBody

Base body model for entities that track a creation and update timestamp.

Used as a base class for all body models associated with responses. Features a creation and update timestamp.

BaseFilter

Bases: BaseModel

Class to unify all filter, paginate and sort request parameters.

This Model allows fine-grained filtering, sorting and pagination of resources.

Usage example for subclasses of this class:

ResourceListModel(
    name="contains:default",
    workspace="default"
    count_steps="gte:5"
    sort_by="created",
    page=2,
    size=20
)
Attributes
list_of_filters: List[Filter] property

Converts the class variables into a list of usable Filter Models.

Returns:

Type Description
List[Filter]

A list of Filter models.

offset: int property

Returns the offset needed for the query on the data persistence layer.

Returns:

Type Description
int

The offset for the query.

sorting_params: Tuple[str, SorterOps] property

Converts the class variables into a list of usable Filter Models.

Returns:

Type Description
Tuple[str, SorterOps]

A tuple of the column to sort by and the sorting operand.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/filter.py
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    rbac_filter = self.generate_rbac_filter(table=table)

    if rbac_filter is not None:
        query = query.where(rbac_filter)

    filters = self.generate_filter(table=table)

    if filters is not None:
        query = query.where(filters)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/filter.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    column, operand = self.sorting_params

    if operand == SorterOps.DESCENDING:
        sort_clause = desc(getattr(table, column))  # type: ignore[var-annotated]
    else:
        sort_clause = asc(getattr(table, column))

    # We always add the `id` column as a tiebreaker to ensure a stable,
    # repeatable order of items, otherwise subsequent pages might contain
    # the same items.
    query = query.order_by(sort_clause, asc(table.id))  # type: ignore[arg-type]

    return query
configure_rbac(authenticated_user_id: UUID, **column_allowed_ids: Optional[Set[UUID]]) -> None

Configure RBAC allowed column values.

Parameters:

Name Type Description Default
authenticated_user_id UUID

ID of the authenticated user. All entities owned by this user will be included.

required
column_allowed_ids Optional[Set[UUID]]

Set of IDs per column to limit the query to. If given, the remaining filters will be applied to entities within this set only. If None, the remaining filters will be applied to all entries in the table.

{}
Source code in src/zenml/models/v2/base/filter.py
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
def configure_rbac(
    self,
    authenticated_user_id: UUID,
    **column_allowed_ids: Optional[Set[UUID]],
) -> None:
    """Configure RBAC allowed column values.

    Args:
        authenticated_user_id: ID of the authenticated user. All entities
            owned by this user will be included.
        column_allowed_ids: Set of IDs per column to limit the query to.
            If given, the remaining filters will be applied to entities
            within this set only. If `None`, the remaining filters will
            be applied to all entries in the table.
    """
    self._rbac_configuration = (authenticated_user_id, column_allowed_ids)
filter_ops(data: Dict[str, Any]) -> Dict[str, Any] classmethod

Parse incoming filters to ensure all filters are legal.

Parameters:

Name Type Description Default
data Dict[str, Any]

The values of the class.

required

Returns:

Type Description
Dict[str, Any]

The values of the class.

Source code in src/zenml/models/v2/base/filter.py
532
533
534
535
536
537
538
539
540
541
542
543
544
545
@model_validator(mode="before")
@classmethod
@before_validator_handler
def filter_ops(cls, data: Dict[str, Any]) -> Dict[str, Any]:
    """Parse incoming filters to ensure all filters are legal.

    Args:
        data: The values of the class.

    Returns:
        The values of the class.
    """
    cls._generate_filter_list(data)
    return data
generate_custom_query_conditions_for_column(value: Any, table: Type[SQLModel], column: str, json_encode_value: bool = False) -> ColumnElement[bool] staticmethod

Generate custom filter conditions for a column of a table.

Parameters:

Name Type Description Default
value Any

The filter value.

required
table Type[SQLModel]

The table which contains the column.

required
column str

The column name.

required
json_encode_value bool

Whether to json encode the value.

False

Returns:

Type Description
ColumnElement[bool]

The query conditions.

Source code in src/zenml/models/v2/base/filter.py
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
@staticmethod
def generate_custom_query_conditions_for_column(
    value: Any,
    table: Type[SQLModel],
    column: str,
    json_encode_value: bool = False,
) -> "ColumnElement[bool]":
    """Generate custom filter conditions for a column of a table.

    Args:
        value: The filter value.
        table: The table which contains the column.
        column: The column name.
        json_encode_value: Whether to json encode the value.

    Returns:
        The query conditions.
    """
    value, operator = BaseFilter._resolve_operator(value)
    filter_ = FilterGenerator(table).define_filter(
        column=column, value=value, operator=operator
    )
    if isinstance(filter_, StrFilter):
        filter_.json_encode_value = json_encode_value

    return filter_.generate_query_conditions(table=table)
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Raises:

Type Description
RuntimeError

If a valid logical operator is not supplied.

Source code in src/zenml/models/v2/base/filter.py
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.

    Raises:
        RuntimeError: If a valid logical operator is not supplied.
    """
    from sqlmodel import and_, or_

    filters = []
    for column_filter in self.list_of_filters:
        filters.append(
            column_filter.generate_query_conditions(table=table)
        )
    for custom_filter in self.get_custom_filters(table):
        filters.append(custom_filter)
    if self.logical_operator == LogicalOperators.OR:
        return or_(False, *filters)
    elif self.logical_operator == LogicalOperators.AND:
        return and_(True, *filters)
    else:
        raise RuntimeError("No valid logical operator was supplied.")
generate_name_or_id_query_conditions(value: Union[UUID, str], table: Type[NamedSchema], additional_columns: Optional[List[str]] = None) -> ColumnElement[bool]

Generate filter conditions for name or id of a table.

Parameters:

Name Type Description Default
value Union[UUID, str]

The filter value.

required
table Type[NamedSchema]

The table to filter.

required
additional_columns Optional[List[str]]

Additional table columns that should also filtered for the given value as part of the or condition.

None

Returns:

Type Description
ColumnElement[bool]

The query conditions.

Source code in src/zenml/models/v2/base/filter.py
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
def generate_name_or_id_query_conditions(
    self,
    value: Union[UUID, str],
    table: Type["NamedSchema"],
    additional_columns: Optional[List[str]] = None,
) -> "ColumnElement[bool]":
    """Generate filter conditions for name or id of a table.

    Args:
        value: The filter value.
        table: The table to filter.
        additional_columns: Additional table columns that should also
            filtered for the given value as part of the or condition.

    Returns:
        The query conditions.
    """
    from sqlmodel import or_

    value, operator = BaseFilter._resolve_operator(value)
    value = str(value)

    conditions = []

    filter_ = FilterGenerator(table).define_filter(
        column="id", value=value, operator=operator
    )
    conditions.append(filter_.generate_query_conditions(table=table))

    filter_ = FilterGenerator(table).define_filter(
        column="name", value=value, operator=operator
    )
    conditions.append(filter_.generate_query_conditions(table=table))

    for column in additional_columns or []:
        filter_ = FilterGenerator(table).define_filter(
            column=column, value=value, operator=operator
        )
        conditions.append(filter_.generate_query_conditions(table=table))

    return or_(*conditions)
generate_rbac_filter(table: Type[AnySchema]) -> Optional[ColumnElement[bool]]

Generates an optional RBAC filter.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
Optional[ColumnElement[bool]]

The RBAC filter.

Source code in src/zenml/models/v2/base/filter.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
def generate_rbac_filter(
    self,
    table: Type["AnySchema"],
) -> Optional["ColumnElement[bool]"]:
    """Generates an optional RBAC filter.

    Args:
        table: The query table.

    Returns:
        The RBAC filter.
    """
    from sqlmodel import or_

    if not self._rbac_configuration:
        return None

    expressions = []

    for column_name, allowed_ids in self._rbac_configuration[1].items():
        if allowed_ids is not None:
            expression = getattr(table, column_name).in_(allowed_ids)
            expressions.append(expression)

    if expressions and hasattr(table, "user_id"):
        # If `expressions` is not empty, we do not have full access to all
        # rows of the table. In this case, we also include rows which the
        # user owns.

        # Unowned entities are considered server-owned and can be seen
        # by anyone
        expressions.append(getattr(table, "user_id").is_(None))
        # The authenticated user owns this entity
        expressions.append(
            getattr(table, "user_id") == self._rbac_configuration[0]
        )

    if expressions:
        return or_(*expressions)
    else:
        return None
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

This can be overridden by subclasses to define custom filters that are not based on the columns of the underlying table.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/filter.py
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    This can be overridden by subclasses to define custom filters that are
    not based on the columns of the underlying table.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    return []
validate_sort_by(value: Any) -> Any classmethod

Validate that the sort_column is a valid column with a valid operand.

Parameters:

Name Type Description Default
value Any

The sort_by field value.

required

Returns:

Type Description
Any

The validated sort_by field value.

Raises:

Type Description
ValidationError

If the sort_by field is not a string.

ValueError

If the resource can't be sorted by this field.

Source code in src/zenml/models/v2/base/filter.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
@field_validator("sort_by", mode="before")
@classmethod
def validate_sort_by(cls, value: Any) -> Any:
    """Validate that the sort_column is a valid column with a valid operand.

    Args:
        value: The sort_by field value.

    Returns:
        The validated sort_by field value.

    Raises:
        ValidationError: If the sort_by field is not a string.
        ValueError: If the resource can't be sorted by this field.
    """
    # Somehow pydantic allows you to pass in int values, which will be
    #  interpreted as string, however within the validator they are still
    #  integers, which don't have a .split() method
    if not isinstance(value, str):
        raise ValidationError(
            f"str type expected for the sort_by field. "
            f"Received a {type(value)}"
        )
    column = value
    split_value = value.split(":", 1)
    if len(split_value) == 2:
        column = split_value[1]

        if split_value[0] not in SorterOps.values():
            logger.warning(
                "Invalid operand used for column sorting. "
                "Only the following operands are supported `%s`. "
                "Defaulting to 'asc' on column `%s`.",
                SorterOps.values(),
                column,
            )
            value = column

    if column in cls.CUSTOM_SORTING_OPTIONS:
        return value
    elif column in cls.FILTER_EXCLUDE_FIELDS:
        raise ValueError(
            f"This resource can not be sorted by this field: '{value}'"
        )
    if column in cls.model_fields:
        return value
    else:
        raise ValueError(
            "You can only sort by valid fields of this resource"
        )

BaseIdentifiedResponse

Bases: BaseResponse[AnyDatedBody, AnyMetadata, AnyResources], Generic[AnyDatedBody, AnyMetadata, AnyResources]

Base domain model for resources with DB representation.

Attributes
created: datetime property

The created property.

Returns:

Type Description
datetime

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for base response models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/base.py
457
458
459
460
461
462
463
464
465
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for base response models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["entity_id"] = self.id
    return metadata
get_body() -> AnyDatedBody

Fetch the body of the entity.

Returns:

Type Description
AnyDatedBody

The body field of the response.

Raises:

Type Description
IllegalOperationError

If the user lacks permission to access the entity represented by this response.

Source code in src/zenml/models/v2/base/base.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
def get_body(self) -> "AnyDatedBody":
    """Fetch the body of the entity.

    Returns:
        The body field of the response.

    Raises:
        IllegalOperationError: If the user lacks permission to access the
            entity represented by this response.
    """
    if self.permission_denied:
        raise IllegalOperationError(
            f"Missing permissions to access {type(self).__name__} with "
            f"ID {self.id}."
        )

    return super().get_body()
get_hydrated_version() -> BaseIdentifiedResponse[AnyDatedBody, AnyMetadata, AnyResources]

Abstract method to fetch the hydrated version of the model.

Raises:

Type Description
NotImplementedError

in case the method is not implemented.

Source code in src/zenml/models/v2/base/base.py
407
408
409
410
411
412
413
414
415
416
417
418
def get_hydrated_version(
    self,
) -> "BaseIdentifiedResponse[AnyDatedBody, AnyMetadata, AnyResources]":
    """Abstract method to fetch the hydrated version of the model.

    Raises:
        NotImplementedError: in case the method is not implemented.
    """
    raise NotImplementedError(
        "Please implement a `get_hydrated_version` method before "
        "using/hydrating the model."
    )
get_metadata() -> AnyMetadata

Fetch the metadata of the entity.

Returns:

Type Description
AnyMetadata

The metadata field of the response.

Raises:

Type Description
IllegalOperationError

If the user lacks permission to access this entity represented by this response.

Source code in src/zenml/models/v2/base/base.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
def get_metadata(self) -> "AnyMetadata":
    """Fetch the metadata of the entity.

    Returns:
        The metadata field of the response.

    Raises:
        IllegalOperationError: If the user lacks permission to access this
            entity represented by this response.
    """
    if self.permission_denied:
        raise IllegalOperationError(
            f"Missing permissions to access {type(self).__name__} with "
            f"ID {self.id}."
        )

    return super().get_metadata()

BasePluginFlavorResponse

Bases: BaseResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources], Generic[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Base response for all Plugin Flavors.

Functions
get_hydrated_version() -> BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Abstract method to fetch the hydrated version of the model.

Returns:

Type Description
BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Hydrated version of the PluginFlavorResponse

Source code in src/zenml/models/v2/base/base_plugin_flavor.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def get_hydrated_version(
    self,
) -> "BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]":
    """Abstract method to fetch the hydrated version of the model.

    Returns:
        Hydrated version of the PluginFlavorResponse
    """
    # TODO: shouldn't this call the Zen store ? The client should not have
    #  to know about the plugin flavor registry
    from zenml.zen_server.utils import plugin_flavor_registry

    plugin_flavor = plugin_flavor_registry().get_flavor_class(
        name=self.name, _type=self.type, subtype=self.subtype
    )
    return plugin_flavor.get_flavor_response_model(hydrate=True)

BaseRequest

Bases: BaseZenModel

Base request model.

Used as a base class for all request models.

BaseResponse

Bases: BaseZenModel, Generic[AnyBody, AnyMetadata, AnyResources]

Base domain model for all responses.

Functions
get_body() -> AnyBody

Fetch the body of the entity.

Returns:

Type Description
AnyBody

The body field of the response.

Raises:

Type Description
RuntimeError

If the body was not included in the response.

Source code in src/zenml/models/v2/base/base.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def get_body(self) -> "AnyBody":
    """Fetch the body of the entity.

    Returns:
        The body field of the response.

    Raises:
        RuntimeError: If the body was not included in the response.
    """
    if not self.body:
        raise RuntimeError(
            f"Missing response body for {type(self).__name__}."
        )

    return self.body
get_hydrated_version() -> BaseResponse[AnyBody, AnyMetadata, AnyResources]

Abstract method to fetch the hydrated version of the model.

Raises:

Type Description
NotImplementedError

in case the method is not implemented.

Source code in src/zenml/models/v2/base/base.py
226
227
228
229
230
231
232
233
234
235
236
237
def get_hydrated_version(
    self,
) -> "BaseResponse[AnyBody, AnyMetadata, AnyResources]":
    """Abstract method to fetch the hydrated version of the model.

    Raises:
        NotImplementedError: in case the method is not implemented.
    """
    raise NotImplementedError(
        "Please implement a `get_hydrated_version` method before "
        "using/hydrating the model."
    )
get_metadata() -> AnyMetadata

Fetch the metadata of the entity.

Returns:

Type Description
AnyMetadata

The metadata field of the response.

Source code in src/zenml/models/v2/base/base.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def get_metadata(self) -> "AnyMetadata":
    """Fetch the metadata of the entity.

    Returns:
        The metadata field of the response.
    """
    if self.metadata is None:
        # If the metadata is not there, check the class first.
        metadata_annotation = self.model_fields["metadata"].annotation
        assert metadata_annotation is not None, (
            "For each response model, an annotated metadata"
            "field should exist."
        )

        # metadata is defined as:
        #   metadata: Optional[....ResponseMetadata] = Field(default=None)
        # We need to find the actual class inside the Optional annotation.
        from zenml.utils.typing_utils import get_args

        metadata_type = get_args(metadata_annotation)[0]
        assert issubclass(metadata_type, BaseResponseMetadata)

        if len(metadata_type.model_fields):
            # If the metadata class defines any fields, fetch the metadata
            # through the hydrated version.
            self.hydrate()
        else:
            # Otherwise, use the metadata class to create an empty metadata
            # object.
            self.metadata = metadata_type()

    assert self.metadata is not None

    return self.metadata
get_resources() -> AnyResources

Fetch the resources related to this entity.

Returns:

Type Description
AnyResources

The resources field of the response.

Raises:

Type Description
RuntimeError

If the resources field was not included in the response.

Source code in src/zenml/models/v2/base/base.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def get_resources(self) -> "AnyResources":
    """Fetch the resources related to this entity.

    Returns:
        The resources field of the response.

    Raises:
        RuntimeError: If the resources field was not included in the response.
    """
    if self.resources is None:
        # If the resources are not there, check the class first.
        resources_annotation = self.model_fields["resources"].annotation
        assert resources_annotation is not None, (
            "For each response model, an annotated resources"
            "field should exist."
        )

        # resources is defined as:
        #   resources: Optional[....ResponseResources] = Field(default=None)
        # We need to find the actual class inside the Optional annotation.
        from zenml.utils.typing_utils import get_args

        resources_type = get_args(resources_annotation)[0]
        assert issubclass(resources_type, BaseResponseResources)

        if len(resources_type.model_fields):
            # If the resources class defines any fields, fetch the resources
            # through the hydrated version.
            self.hydrate()
        else:
            # Otherwise, use the resources class to create an empty
            # resources object.
            self.resources = resources_type()

    if self.resources is None:
        raise RuntimeError(
            f"Missing response resources for {type(self).__name__}."
        )

    return self.resources
hydrate() -> None

Hydrate the response.

Source code in src/zenml/models/v2/base/base.py
218
219
220
221
222
223
224
def hydrate(self) -> None:
    """Hydrate the response."""
    hydrated_version = self.get_hydrated_version()
    self._validate_hydrated_version(hydrated_version)

    self.resources = hydrated_version.resources
    self.metadata = hydrated_version.metadata

BaseResponseBody

Bases: BaseZenModel

Base body model.

BaseResponseMetadata

Bases: BaseZenModel

Base metadata model.

Used as a base class for all metadata models associated with responses.

BaseResponseResources

Bases: BaseZenModel

Base resources model.

Used as a base class for all resource models associated with responses.

BaseUpdate

Bases: BaseZenModel

Base update model.

Used as a base class for all update models.

BaseZenModel

Bases: YAMLSerializationMixin, AnalyticsTrackedModelMixin

Base model class for all ZenML models.

This class is used as a base class for all ZenML models. It provides functionality for tracking analytics events.

BoolFilter

Bases: Filter

Filter for all Boolean fields.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a boolean column.

Parameters:

Name Type Description Default
column Any

The boolean column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
156
157
158
159
160
161
162
163
164
165
166
167
168
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a boolean column.

    Args:
        column: The boolean column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != self.value

    return column == self.value

BuildItem

Bases: BaseModel

Pipeline build item.

Attributes:

Name Type Description
image str

The image name or digest.

dockerfile Optional[str]

The contents of the Dockerfile used to build the image.

requirements Optional[str]

The pip requirements installed in the image. This is a string consisting of multiple concatenated requirements.txt files.

settings_checksum Optional[str]

Checksum of the settings used for the build.

contains_code bool

Whether the image contains user files.

requires_code_download bool

Whether the image needs to download files.

CodeReferenceRequest

Bases: BaseRequest

Request model for code references.

CodeReferenceResponse

Bases: BaseIdentifiedResponse[CodeReferenceResponseBody, CodeReferenceResponseMetadata, CodeReferenceResponseResources]

Response model for code references.

Attributes
code_repository: CodeRepositoryResponse property

The code_repository property.

Returns:

Type Description
CodeRepositoryResponse

the value of the property.

commit: str property

The commit property.

Returns:

Type Description
str

the value of the property.

subdirectory: str property

The subdirectory property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> CodeReferenceResponse

Get the hydrated version of this code reference.

Returns:

Type Description
CodeReferenceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/code_reference.py
85
86
87
88
89
90
91
92
93
def get_hydrated_version(self) -> "CodeReferenceResponse":
    """Get the hydrated version of this code reference.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_code_reference(self.id)

CodeReferenceResponseBody

Bases: BaseDatedResponseBody

Response body for code references.

CodeReferenceResponseMetadata

Bases: BaseResponseMetadata

Response metadata for code references.

CodeRepositoryFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all code repositories.

CodeRepositoryRequest

Bases: WorkspaceScopedRequest

Request model for code repositories.

CodeRepositoryResponse

Bases: WorkspaceScopedResponse[CodeRepositoryResponseBody, CodeRepositoryResponseMetadata, CodeRepositoryResponseResources]

Response model for code repositories.

Attributes
config: Dict[str, Any] property

The config property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

source: Source property

The source property.

Returns:

Type Description
Source

the value of the property.

Functions
get_hydrated_version() -> CodeRepositoryResponse

Get the hydrated version of this code repository.

Returns:

Type Description
CodeRepositoryResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/code_repository.py
133
134
135
136
137
138
139
140
141
def get_hydrated_version(self) -> "CodeRepositoryResponse":
    """Get the hydrated version of this code repository.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_code_repository(self.id)

CodeRepositoryResponseBody

Bases: WorkspaceScopedResponseBody

Response body for code repositories.

CodeRepositoryResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for code repositories.

CodeRepositoryUpdate

Bases: BaseUpdate

Update model for code repositories.

ComponentBase

Bases: BaseModel

Base model for components.

ComponentFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all ComponentModels.

The Component Model needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Stack components can be scoped by type to narrow the search.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Source code in src/zenml/models/v2/core/component.py
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Stack components can be scoped by type to narrow the search.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.
    """
    from sqlmodel import and_, or_

    from zenml.zen_stores.schemas import (
        StackComponentSchema,
        StackCompositionSchema,
    )

    base_filter = super().generate_filter(table)
    if self.scope_type:
        type_filter = getattr(table, "type") == self.scope_type
        return and_(base_filter, type_filter)

    if self.stack_id:
        operator = (
            or_ if self.logical_operator == LogicalOperators.OR else and_
        )

        stack_filter = and_(
            StackCompositionSchema.stack_id == self.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
        )
        base_filter = operator(base_filter, stack_filter)

    return base_filter
set_scope_type(component_type: str) -> None

Set the type of component on which to perform the filtering to scope the response.

Parameters:

Name Type Description Default
component_type str

The type of component to scope the query to.

required
Source code in src/zenml/models/v2/core/component.py
394
395
396
397
398
399
400
def set_scope_type(self, component_type: str) -> None:
    """Set the type of component on which to perform the filtering to scope the response.

    Args:
        component_type: The type of component to scope the query to.
    """
    self.scope_type = component_type

ComponentInfo

Bases: BaseModel

Information about each stack components when creating a full stack.

ComponentRequest

Bases: ComponentBase, WorkspaceScopedRequest

Request model for components.

Functions
name_cant_be_a_secret_reference(name: str) -> str classmethod

Validator to ensure that the given name is not a secret reference.

Parameters:

Name Type Description Default
name str

The name to validate.

required

Returns:

Type Description
str

The name if it is not a secret reference.

Raises:

Type Description
ValueError

If the name is a secret reference.

Source code in src/zenml/models/v2/core/component.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@field_validator("name")
@classmethod
def name_cant_be_a_secret_reference(cls, name: str) -> str:
    """Validator to ensure that the given name is not a secret reference.

    Args:
        name: The name to validate.

    Returns:
        The name if it is not a secret reference.

    Raises:
        ValueError: If the name is a secret reference.
    """
    if secret_utils.is_secret_reference(name):
        raise ValueError(
            "Passing the `name` attribute of a stack component as a "
            "secret reference is not allowed."
        )
    return name

ComponentResponse

Bases: WorkspaceScopedResponse[ComponentResponseBody, ComponentResponseMetadata, ComponentResponseResources]

Response model for components.

Attributes
configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector: Optional[ServiceConnectorResponse] property

The connector property.

Returns:

Type Description
Optional[ServiceConnectorResponse]

the value of the property.

connector_resource_id: Optional[str] property

The connector_resource_id property.

Returns:

Type Description
Optional[str]

the value of the property.

flavor: FlavorResponse property

The flavor property.

Returns:

Type Description
FlavorResponse

the value of the property.

flavor_name: str property

The flavor_name property.

Returns:

Type Description
str

the value of the property.

integration: Optional[str] property

The integration property.

Returns:

Type Description
Optional[str]

the value of the property.

labels: Optional[Dict[str, Any]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

type: StackComponentType property

The type property.

Returns:

Type Description
StackComponentType

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the component labels to analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/component.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the component labels to analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    if self.labels is not None:
        metadata.update(
            {
                label[6:]: value
                for label, value in self.labels.items()
                if label.startswith("zenml:")
            }
        )
    metadata["flavor"] = self.flavor_name

    return metadata
get_hydrated_version() -> ComponentResponse

Get the hydrated version of this component.

Returns:

Type Description
ComponentResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/component.py
253
254
255
256
257
258
259
260
261
def get_hydrated_version(self) -> "ComponentResponse":
    """Get the hydrated version of this component.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_stack_component(self.id)

ComponentResponseBody

Bases: WorkspaceScopedResponseBody

Response body for components.

ComponentResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for components.

ComponentResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the component entity.

ComponentUpdate

Bases: BaseUpdate

Update model for stack components.

DeployedStack

Bases: BaseModel

Information about a deployed stack.

EventSourceFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all EventSourceModels.

EventSourceFlavorResponse

Bases: BasePluginFlavorResponse[EventSourceFlavorResponseBody, EventSourceFlavorResponseMetadata, EventSourceFlavorResponseResources]

Response model for Event Source Flavors.

Attributes
filter_config_schema: Dict[str, Any] property

The filter_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

source_config_schema: Dict[str, Any] property

The source_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

EventSourceFlavorResponseBody

Bases: BasePluginResponseBody

Response body for event flavors.

EventSourceFlavorResponseMetadata

Bases: BasePluginResponseMetadata

Response metadata for event flavors.

EventSourceFlavorResponseResources

Bases: BasePluginResponseResources

Response resources for event source flavors.

EventSourceRequest

Bases: WorkspaceScopedRequest

BaseModel for all event sources.

EventSourceResponse

Bases: WorkspaceScopedResponse[EventSourceResponseBody, EventSourceResponseMetadata, EventSourceResponseResources]

Response model for event sources.

Attributes
configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

flavor: str property

The flavor property.

Returns:

Type Description
str

the value of the property.

is_active: bool property

The is_active property.

Returns:

Type Description
bool

the value of the property.

plugin_subtype: PluginSubType property

The plugin_subtype property.

Returns:

Type Description
PluginSubType

the value of the property.

Functions
get_hydrated_version() -> EventSourceResponse

Get the hydrated version of this event source.

Returns:

Type Description
EventSourceResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/event_source.py
161
162
163
164
165
166
167
168
169
def get_hydrated_version(self) -> "EventSourceResponse":
    """Get the hydrated version of this event source.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_event_source(self.id)
set_configuration(configuration: Dict[str, Any]) -> None

Set the configuration property.

Parameters:

Name Type Description Default
configuration Dict[str, Any]

The value to set.

required
Source code in src/zenml/models/v2/core/event_source.py
217
218
219
220
221
222
223
def set_configuration(self, configuration: Dict[str, Any]) -> None:
    """Set the `configuration` property.

    Args:
        configuration: The value to set.
    """
    self.get_metadata().configuration = configuration

EventSourceResponseBody

Bases: WorkspaceScopedResponseBody

ResponseBody for event sources.

EventSourceResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for event sources.

EventSourceResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the code repository entity.

EventSourceUpdate

Bases: BaseZenModel

Update model for event sources.

Functions
from_response(response: EventSourceResponse) -> EventSourceUpdate classmethod

Create an update model from a response model.

Parameters:

Name Type Description Default
response EventSourceResponse

The response model to create the update model from.

required

Returns:

Type Description
EventSourceUpdate

The update model.

Source code in src/zenml/models/v2/core/event_source.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def from_response(
    cls, response: "EventSourceResponse"
) -> "EventSourceUpdate":
    """Create an update model from a response model.

    Args:
        response: The response model to create the update model from.

    Returns:
        The update model.
    """
    return EventSourceUpdate(
        name=response.name,
        description=response.description,
        configuration=copy.deepcopy(response.configuration),
        is_active=response.is_active,
    )

ExternalUserModel

Bases: BaseModel

External user model.

FlavorFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Flavors.

FlavorRequest

Bases: UserScopedRequest

Request model for flavors.

FlavorResponse

Bases: UserScopedResponse[FlavorResponseBody, FlavorResponseMetadata, FlavorResponseResources]

Response model for flavors.

Attributes
config_schema: Dict[str, Any] property

The config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector_requirements: Optional[ServiceConnectorRequirements] property

Returns the connector requirements for the flavor.

Returns:

Type Description
Optional[ServiceConnectorRequirements]

The connector requirements for the flavor.

connector_resource_id_attr: Optional[str] property

The connector_resource_id_attr property.

Returns:

Type Description
Optional[str]

the value of the property.

connector_resource_type: Optional[str] property

The connector_resource_type property.

Returns:

Type Description
Optional[str]

the value of the property.

connector_type: Optional[str] property

The connector_type property.

Returns:

Type Description
Optional[str]

the value of the property.

docs_url: Optional[str] property

The docs_url property.

Returns:

Type Description
Optional[str]

the value of the property.

integration: Optional[str] property

The integration property.

Returns:

Type Description
Optional[str]

the value of the property.

is_custom: bool property

The is_custom property.

Returns:

Type Description
bool

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

sdk_docs_url: Optional[str] property

The sdk_docs_url property.

Returns:

Type Description
Optional[str]

the value of the property.

source: str property

The source property.

Returns:

Type Description
str

the value of the property.

type: StackComponentType property

The type property.

Returns:

Type Description
StackComponentType

the value of the property.

workspace: Optional[WorkspaceResponse] property

The workspace property.

Returns:

Type Description
Optional[WorkspaceResponse]

the value of the property.

Functions
get_hydrated_version() -> FlavorResponse

Get the hydrated version of the flavor.

Returns:

Type Description
FlavorResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/flavor.py
270
271
272
273
274
275
276
277
278
def get_hydrated_version(self) -> "FlavorResponse":
    """Get the hydrated version of the flavor.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_flavor(self.id)

FlavorResponseBody

Bases: UserScopedResponseBody

Response body for flavor.

FlavorResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for flavors.

FlavorUpdate

Bases: BaseUpdate

Update model for flavors.

LazyArtifactVersionResponse

Bases: ArtifactVersionResponse

Lazy artifact version response.

Used if the artifact version is accessed from the model in a pipeline context available only during pipeline compilation.

Attributes
run_metadata: Dict[str, MetadataType] property

The metadata property in lazy loading mode.

Returns:

Type Description
Dict[str, MetadataType]

getter of lazy responses for internal use.

Functions
get_body() -> None

Protects from misuse of the lazy loader.

Raises:

Type Description
RuntimeError

always

Source code in src/zenml/models/v2/core/artifact_version.py
722
723
724
725
726
727
728
def get_body(self) -> None:  # type: ignore[override]
    """Protects from misuse of the lazy loader.

    Raises:
        RuntimeError: always
    """
    raise RuntimeError("Cannot access artifact body before pipeline runs.")
get_metadata() -> None

Protects from misuse of the lazy loader.

Raises:

Type Description
RuntimeError

always

Source code in src/zenml/models/v2/core/artifact_version.py
730
731
732
733
734
735
736
737
738
def get_metadata(self) -> None:  # type: ignore[override]
    """Protects from misuse of the lazy loader.

    Raises:
        RuntimeError: always
    """
    raise RuntimeError(
        "Cannot access artifact metadata before pipeline runs."
    )

LoadedVisualization

Bases: BaseModel

Model for loaded visualizations.

LogsRequest

Bases: BaseRequest

Request model for logs.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@field_validator("artifact_store_id")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value
text_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@field_validator("uri")
@classmethod
def text_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < TEXT_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {TEXT_FIELD_MAX_LENGTH}"
    )
    return value

LogsResponse

Bases: BaseIdentifiedResponse[LogsResponseBody, LogsResponseMetadata, LogsResponseResources]

Response model for logs.

Attributes
artifact_store_id: Union[str, UUID] property

The artifact_store_id property.

Returns:

Type Description
Union[str, UUID]

the value of the property.

pipeline_run_id: Optional[Union[str, UUID]] property

The pipeline_run_id property.

Returns:

Type Description
Optional[Union[str, UUID]]

the value of the property.

step_run_id: Optional[Union[str, UUID]] property

The step_run_id property.

Returns:

Type Description
Optional[Union[str, UUID]]

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> LogsResponse

Get the hydrated version of these logs.

Returns:

Type Description
LogsResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/logs.py
152
153
154
155
156
157
158
159
160
def get_hydrated_version(self) -> "LogsResponse":
    """Get the hydrated version of these logs.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_logs(self.id)

LogsResponseBody

Bases: BaseDatedResponseBody

Response body for logs.

LogsResponseMetadata

Bases: BaseResponseMetadata

Response metadata for logs.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@field_validator("artifact_store_id")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH
    return value

ModelFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of all Workspaces.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query for Models.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/model.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query for Models.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == SORT_BY_LATEST_VERSION_KEY:
        # Subquery to find the latest version per model
        latest_version_subquery = (
            select(
                ModelSchema.id,
                case(
                    (
                        func.max(ModelVersionSchema.created).is_(None),
                        ModelSchema.created,
                    ),
                    else_=func.max(ModelVersionSchema.created),
                ).label("latest_version_created"),
            )
            .outerjoin(
                ModelVersionSchema,
                ModelSchema.id == ModelVersionSchema.model_id,  # type: ignore[arg-type]
            )
            .group_by(col(ModelSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_version_subquery.c.latest_version_created,
        ).where(ModelSchema.id == latest_version_subquery.c.id)

        # Apply sorting based on the operand
        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_version_subquery.c.latest_version_created),
                asc(ModelSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_version_subquery.c.latest_version_created),
                desc(ModelSchema.id),
            )
        return query

    # For other sorting cases, delegate to the parent class
    return super().apply_sorting(query=query, table=table)

ModelRequest

Bases: WorkspaceScopedRequest

Request model for models.

ModelResponse

Bases: WorkspaceScopedResponse[ModelResponseBody, ModelResponseMetadata, ModelResponseResources]

Response model for models.

Attributes
audience: Optional[str] property

The audience property.

Returns:

Type Description
Optional[str]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

ethics: Optional[str] property

The ethics property.

Returns:

Type Description
Optional[str]

the value of the property.

latest_version_id: Optional[UUID] property

The latest_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_version_name: Optional[str] property

The latest_version_name property.

Returns:

Type Description
Optional[str]

the value of the property.

license: Optional[str] property

The license property.

Returns:

Type Description
Optional[str]

the value of the property.

limitations: Optional[str] property

The limitations property.

Returns:

Type Description
Optional[str]

the value of the property.

save_models_to_registry: bool property

The save_models_to_registry property.

Returns:

Type Description
bool

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

trade_offs: Optional[str] property

The trade_offs property.

Returns:

Type Description
Optional[str]

the value of the property.

use_cases: Optional[str] property

The use_cases property.

Returns:

Type Description
Optional[str]

the value of the property.

versions: List[Model] property

List all versions of the model.

Returns:

Type Description
List[Model]

The list of all model version.

Functions
get_hydrated_version() -> ModelResponse

Get the hydrated version of this model.

Returns:

Type Description
ModelResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/model.py
193
194
195
196
197
198
199
200
201
def get_hydrated_version(self) -> "ModelResponse":
    """Get the hydrated version of this model.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_model(self.id)

ModelResponseBody

Bases: WorkspaceScopedResponseBody

Response body for models.

ModelResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for models.

ModelUpdate

Bases: BaseModel

Update model for models.

ModelVersionArtifactFilter

Bases: BaseFilter

Model version pipeline run links filter model.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[Union[ColumnElement[bool]]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[Union[ColumnElement[bool]]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version_artifact.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List[Union["ColumnElement[bool]"]]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, col

    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
        ModelVersionArtifactSchema,
        UserSchema,
    )

    if self.artifact_name:
        value, filter_operator = self._resolve_operator(self.artifact_name)
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        artifact_name_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            filter_.generate_query_conditions(ArtifactSchema),
        )
        custom_filters.append(artifact_name_filter)

    if self.only_data_artifacts:
        data_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            col(ArtifactVersionSchema.type).not_in(
                ["ServiceArtifact", "ModelArtifact"]
            ),
        )
        custom_filters.append(data_artifact_filter)

    if self.only_model_artifacts:
        model_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.type == "ModelArtifact",
        )
        custom_filters.append(model_artifact_filter)

    if self.only_deployment_artifacts:
        deployment_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.type == "ServiceArtifact",
        )
        custom_filters.append(deployment_artifact_filter)

    if self.has_custom_name is not None:
        custom_name_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            ArtifactSchema.has_custom_name == self.has_custom_name,
        )
        custom_filters.append(custom_name_filter)

    if self.user:
        user_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.user_id == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters

ModelVersionArtifactRequest

Bases: BaseRequest

Request model for links between model versions and artifacts.

ModelVersionArtifactResponse

Bases: BaseIdentifiedResponse[ModelVersionArtifactResponseBody, BaseResponseMetadata, ModelVersionArtifactResponseResources]

Response model for links between model versions and artifacts.

Attributes
artifact_version: ArtifactVersionResponse property

The artifact_version property.

Returns:

Type Description
ArtifactVersionResponse

the value of the property.

model_version: UUID property

The model_version property.

Returns:

Type Description
UUID

the value of the property.

ModelVersionArtifactResponseBody

Bases: BaseDatedResponseBody

Response body for links between model versions and artifacts.

ModelVersionFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Filter model for model versions.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/model_version.py
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self._model_id:
        query = query.where(getattr(table, "model_id") == self._model_id)

    return query
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version.py
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelVersionSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
    )

    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == ModelVersionSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.MODEL_VERSION,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters
set_scope_model(model_name_or_id: Union[str, UUID]) -> None

Set the model to scope this response.

Parameters:

Name Type Description Default
model_name_or_id Union[str, UUID]

The model to scope this response to.

required
Source code in src/zenml/models/v2/core/model_version.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
def set_scope_model(self, model_name_or_id: Union[str, UUID]) -> None:
    """Set the model to scope this response.

    Args:
        model_name_or_id: The model to scope this response to.
    """
    try:
        model_id = UUID(str(model_name_or_id))
    except ValueError:
        from zenml.client import Client

        model_id = Client().get_model(model_name_or_id).id

    self._model_id = model_id

ModelVersionPipelineRunFilter

Bases: BaseFilter

Model version pipeline run links filter model.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version_pipeline_run.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelVersionPipelineRunSchema,
        PipelineRunSchema,
        UserSchema,
    )

    if self.pipeline_run_name:
        value, filter_operator = self._resolve_operator(
            self.pipeline_run_name
        )
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        pipeline_run_name_filter = and_(
            ModelVersionPipelineRunSchema.pipeline_run_id
            == PipelineRunSchema.id,
            filter_.generate_query_conditions(PipelineRunSchema),
        )
        custom_filters.append(pipeline_run_name_filter)

    if self.user:
        user_filter = and_(
            ModelVersionPipelineRunSchema.pipeline_run_id
            == PipelineRunSchema.id,
            PipelineRunSchema.user_id == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters

ModelVersionPipelineRunRequest

Bases: BaseRequest

Request model for links between model versions and pipeline runs.

ModelVersionPipelineRunResponse

Bases: BaseIdentifiedResponse[ModelVersionPipelineRunResponseBody, BaseResponseMetadata, ModelVersionPipelineRunResponseResources]

Response model for links between model versions and pipeline runs.

Attributes
model_version: UUID property

The model_version property.

Returns:

Type Description
UUID

the value of the property.

pipeline_run: PipelineRunResponse property

The pipeline_run property.

Returns:

Type Description
PipelineRunResponse

the value of the property.

ModelVersionPipelineRunResponseBody

Bases: BaseDatedResponseBody

Response body for links between model versions and pipeline runs.

ModelVersionRequest

Bases: WorkspaceScopedRequest

Request model for model versions.

ModelVersionResponse

Bases: WorkspaceScopedResponse[ModelVersionResponseBody, ModelVersionResponseMetadata, ModelVersionResponseResources]

Response model for model versions.

Attributes
data_artifact_ids: Dict[str, Dict[str, UUID]] property

The data_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

data_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all data artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of data artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

deployment_artifact_ids: Dict[str, Dict[str, UUID]] property

The deployment_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

deployment_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all deployment artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of deployment artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

model: ModelResponse property

The model property.

Returns:

Type Description
ModelResponse

the value of the property.

model_artifact_ids: Dict[str, Dict[str, UUID]] property

The model_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

model_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all model artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of model artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

number: int property

The number property.

Returns:

Type Description
int

the value of the property.

pipeline_run_ids: Dict[str, UUID] property

The pipeline_run_ids property.

Returns:

Type Description
Dict[str, UUID]

the value of the property.

pipeline_runs: Dict[str, PipelineRunResponse] property

Get all pipeline runs linked to this version.

Returns:

Type Description
Dict[str, PipelineRunResponse]

Dictionary of Pipeline Runs as PipelineRunResponseModel

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

stage: Optional[str] property

The stage property.

Returns:

Type Description
Optional[str]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the artifact to retrieve.

required
version Optional[str]

The version of the artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of an artifact or None

Source code in src/zenml/models/v2/core/model_version.py
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
def get_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the artifact linked to this model version.

    Args:
        name: The name of the artifact to retrieve.
        version: The version of the artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of an artifact or None
    """
    return self._get_linked_object(name, version)
get_data_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the data artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the data artifact to retrieve.

required
version Optional[str]

The version of the data artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the data artifact or None

Source code in src/zenml/models/v2/core/model_version.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
def get_data_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the data artifact linked to this model version.

    Args:
        name: The name of the data artifact to retrieve.
        version: The version of the data artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the data artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.DATA)
get_deployment_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the deployment artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the deployment artifact to retrieve.

required
version Optional[str]

The version of the deployment artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the deployment artifact or None

Source code in src/zenml/models/v2/core/model_version.py
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
def get_deployment_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the deployment artifact linked to this model version.

    Args:
        name: The name of the deployment artifact to retrieve.
        version: The version of the deployment artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the deployment artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.SERVICE)
get_hydrated_version() -> ModelVersionResponse

Get the hydrated version of this model version.

Returns:

Type Description
ModelVersionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/model_version.py
310
311
312
313
314
315
316
317
318
def get_hydrated_version(self) -> "ModelVersionResponse":
    """Get the hydrated version of this model version.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_model_version(self.id)
get_model_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the model artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the model artifact to retrieve.

required
version Optional[str]

The version of the model artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the model artifact or None

Source code in src/zenml/models/v2/core/model_version.py
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
def get_model_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the model artifact linked to this model version.

    Args:
        name: The name of the model artifact to retrieve.
        version: The version of the model artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the model artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.MODEL)
get_pipeline_run(name: str) -> PipelineRunResponse

Get pipeline run linked to this version.

Parameters:

Name Type Description Default
name str

The name of the pipeline run to retrieve.

required

Returns:

Type Description
PipelineRunResponse

PipelineRun as PipelineRunResponseModel

Source code in src/zenml/models/v2/core/model_version.py
528
529
530
531
532
533
534
535
536
537
538
539
def get_pipeline_run(self, name: str) -> "PipelineRunResponse":
    """Get pipeline run linked to this version.

    Args:
        name: The name of the pipeline run to retrieve.

    Returns:
        PipelineRun as PipelineRunResponseModel
    """
    from zenml.client import Client

    return Client().get_pipeline_run(self.pipeline_run_ids[name])
set_stage(stage: Union[str, ModelStages], force: bool = False) -> None

Sets this Model Version to a desired stage.

Parameters:

Name Type Description Default
stage Union[str, ModelStages]

the target stage for model version.

required
force bool

whether to force archiving of current model version in target stage or raise.

False

Raises:

Type Description
ValueError

if model_stage is not valid.

Source code in src/zenml/models/v2/core/model_version.py
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
def set_stage(
    self, stage: Union[str, ModelStages], force: bool = False
) -> None:
    """Sets this Model Version to a desired stage.

    Args:
        stage: the target stage for model version.
        force: whether to force archiving of current model version in
            target stage or raise.

    Raises:
        ValueError: if model_stage is not valid.
    """
    from zenml.client import Client

    stage = getattr(stage, "value", stage)
    if stage not in [stage.value for stage in ModelStages]:
        raise ValueError(f"`{stage}` is not a valid model stage.")

    Client().update_model_version(
        model_name_or_id=self.model.id,
        version_name_or_id=self.id,
        stage=stage,
        force=force,
    )
to_model_class(suppress_class_validation_warnings: bool = True) -> Model

Convert response model to Model object.

Parameters:

Name Type Description Default
suppress_class_validation_warnings bool

internally used to suppress repeated warnings.

True

Returns:

Type Description
Model

Model object

Source code in src/zenml/models/v2/core/model_version.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def to_model_class(
    self,
    suppress_class_validation_warnings: bool = True,
) -> "Model":
    """Convert response model to Model object.

    Args:
        suppress_class_validation_warnings: internally used to suppress
            repeated warnings.

    Returns:
        Model object
    """
    from zenml.model.model import Model

    mv = Model(
        name=self.model.name,
        license=self.model.license,
        description=self.description,
        audience=self.model.audience,
        use_cases=self.model.use_cases,
        limitations=self.model.limitations,
        trade_offs=self.model.trade_offs,
        ethics=self.model.ethics,
        tags=[t.name for t in self.tags],
        version=self.name,
        suppress_class_validation_warnings=suppress_class_validation_warnings,
        model_version_id=self.id,
    )

    return mv

ModelVersionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for model versions.

ModelVersionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for model versions.

ModelVersionResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the model version entity.

ModelVersionUpdate

Bases: BaseModel

Update model for model versions.

NumericFilter

Bases: Filter

Filter for all numeric fields.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a numeric column.

Parameters:

Name Type Description Default
column Any

The numeric column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a numeric column.

    Args:
        column: The numeric column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    if self.operation == GenericFilterOps.GTE:
        return column >= self.value
    if self.operation == GenericFilterOps.GT:
        return column > self.value
    if self.operation == GenericFilterOps.LTE:
        return column <= self.value
    if self.operation == GenericFilterOps.LT:
        return column < self.value
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != self.value
    return column == self.value

OAuthDeviceAuthorizationRequest

Bases: BaseModel

OAuth2 device authorization grant request.

OAuthDeviceAuthorizationResponse

Bases: BaseModel

OAuth2 device authorization grant response.

OAuthDeviceFilter

Bases: UserScopedFilter

Model to enable advanced filtering of OAuth2 devices.

OAuthDeviceInternalRequest

Bases: BaseRequest

Internal request model for OAuth2 devices.

OAuthDeviceInternalResponse

Bases: OAuthDeviceResponse

OAuth2 device response model used internally for authentication.

Functions
verify_device_code(device_code: str) -> bool

Verifies a given device code against the stored (hashed) device code.

Parameters:

Name Type Description Default
device_code str

The device code to verify.

required

Returns:

Type Description
bool

True if the device code is valid, False otherwise.

Source code in src/zenml/models/v2/core/device.py
421
422
423
424
425
426
427
428
429
430
431
432
433
def verify_device_code(
    self,
    device_code: str,
) -> bool:
    """Verifies a given device code against the stored (hashed) device code.

    Args:
        device_code: The device code to verify.

    Returns:
        True if the device code is valid, False otherwise.
    """
    return self._verify_code(device_code, self.device_code)
verify_user_code(user_code: str) -> bool

Verifies a given user code against the stored (hashed) user code.

Parameters:

Name Type Description Default
user_code str

The user code to verify.

required

Returns:

Type Description
bool

True if the user code is valid, False otherwise.

Source code in src/zenml/models/v2/core/device.py
407
408
409
410
411
412
413
414
415
416
417
418
419
def verify_user_code(
    self,
    user_code: str,
) -> bool:
    """Verifies a given user code against the stored (hashed) user code.

    Args:
        user_code: The user code to verify.

    Returns:
        True if the user code is valid, False otherwise.
    """
    return self._verify_code(user_code, self.user_code)

OAuthDeviceInternalUpdate

Bases: OAuthDeviceUpdate

OAuth2 device update model used internally for authentication.

OAuthDeviceResponse

Bases: UserScopedResponse[OAuthDeviceResponseBody, OAuthDeviceResponseMetadata, OAuthDeviceResponseResources]

Response model for OAuth2 devices.

Attributes
city: Optional[str] property

The city property.

Returns:

Type Description
Optional[str]

the value of the property.

client_id: UUID property

The client_id property.

Returns:

Type Description
UUID

the value of the property.

country: Optional[str] property

The country property.

Returns:

Type Description
Optional[str]

the value of the property.

expires: Optional[datetime] property

The expires property.

Returns:

Type Description
Optional[datetime]

the value of the property.

failed_auth_attempts: int property

The failed_auth_attempts property.

Returns:

Type Description
int

the value of the property.

hostname: Optional[str] property

The hostname property.

Returns:

Type Description
Optional[str]

the value of the property.

ip_address: Optional[str] property

The ip_address property.

Returns:

Type Description
Optional[str]

the value of the property.

last_login: Optional[datetime] property

The last_login property.

Returns:

Type Description
Optional[datetime]

the value of the property.

os: Optional[str] property

The os property.

Returns:

Type Description
Optional[str]

the value of the property.

python_version: Optional[str] property

The python_version property.

Returns:

Type Description
Optional[str]

the value of the property.

region: Optional[str] property

The region property.

Returns:

Type Description
Optional[str]

the value of the property.

status: OAuthDeviceStatus property

The status property.

Returns:

Type Description
OAuthDeviceStatus

the value of the property.

trusted_device: bool property

The trusted_device property.

Returns:

Type Description
bool

the value of the property.

zenml_version: Optional[str] property

The zenml_version property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_hydrated_version() -> OAuthDeviceResponse

Get the hydrated version of this OAuth2 device.

Returns:

Type Description
OAuthDeviceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/device.py
240
241
242
243
244
245
246
247
248
def get_hydrated_version(self) -> "OAuthDeviceResponse":
    """Get the hydrated version of this OAuth2 device.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_authorized_device(self.id)

OAuthDeviceResponseBody

Bases: UserScopedResponseBody

Response body for OAuth2 devices.

OAuthDeviceResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for OAuth2 devices.

OAuthDeviceTokenRequest

Bases: BaseModel

OAuth2 device authorization grant request.

OAuthDeviceUpdate

Bases: BaseModel

OAuth2 device update model.

OAuthDeviceUserAgentHeader

Bases: BaseModel

OAuth2 device user agent header.

Functions
decode(header_str: str) -> OAuthDeviceUserAgentHeader classmethod

Decode the user agent header.

Parameters:

Name Type Description Default
header_str str

The user agent header string value.

required

Returns:

Type Description
OAuthDeviceUserAgentHeader

The decoded user agent header.

Source code in src/zenml/models/v2/misc/auth_models.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@classmethod
def decode(cls, header_str: str) -> "OAuthDeviceUserAgentHeader":
    """Decode the user agent header.

    Args:
        header_str: The user agent header string value.

    Returns:
        The decoded user agent header.
    """
    header = cls()
    properties = header_str.strip().split(" ")
    for property in properties:
        try:
            key, value = property.split("/", maxsplit=1)
        except ValueError:
            continue
        if key == "Host":
            header.hostname = value
        elif key == "ZenML":
            header.zenml_version = value
        elif key == "Python":
            header.python_version = value
        elif key == "OS":
            header.os = value
    return header
encode() -> str

Encode the user agent header.

Returns:

Type Description
str

The encoded user agent header.

Source code in src/zenml/models/v2/misc/auth_models.py
85
86
87
88
89
90
91
92
93
94
95
96
def encode(self) -> str:
    """Encode the user agent header.

    Returns:
        The encoded user agent header.
    """
    return (
        f"Host/{self.hostname} "
        f"ZenML/{self.zenml_version} "
        f"Python/{self.python_version} "
        f"OS/{self.os}"
    )

OAuthDeviceVerificationRequest

Bases: BaseModel

OAuth2 device authorization verification request.

OAuthRedirectResponse

Bases: BaseModel

Redirect response.

OAuthTokenResponse

Bases: BaseModel

OAuth2 device authorization token response.

Page

Bases: BaseModel, Generic[B]

Return Model for List Models to accommodate pagination.

Attributes
size: int property

Return the item count of the page.

Returns:

Type Description
int

The amount of items in the page.

PipelineBuildBase

Bases: BaseZenModel

Base model for pipeline builds.

Attributes
requires_code_download: bool property

Whether the build requires code download.

Returns:

Type Description
bool

Whether the build requires code download.

Functions
get_image(component_key: str, step: Optional[str] = None) -> str

Get the image built for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the image.

required
step Optional[str]

The pipeline step for which to get the image. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
str

The image name or digest.

Source code in src/zenml/models/v2/core/pipeline_build.py
104
105
106
107
108
109
110
111
112
113
114
115
116
def get_image(self, component_key: str, step: Optional[str] = None) -> str:
    """Get the image built for a specific key.

    Args:
        component_key: The key for which to get the image.
        step: The pipeline step for which to get the image. If no image
            exists for this step, will fall back to the pipeline image for
            the same key.

    Returns:
        The image name or digest.
    """
    return self._get_item(component_key=component_key, step=step).image
get_image_key(component_key: str, step: Optional[str] = None) -> str staticmethod

Get the image key.

Parameters:

Name Type Description Default
component_key str

The component key.

required
step Optional[str]

The pipeline step for which the image was built.

None

Returns:

Type Description
str

The image key.

Source code in src/zenml/models/v2/core/pipeline_build.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@staticmethod
def get_image_key(component_key: str, step: Optional[str] = None) -> str:
    """Get the image key.

    Args:
        component_key: The component key.
        step: The pipeline step for which the image was built.

    Returns:
        The image key.
    """
    if step:
        return f"{step}.{component_key}"
    else:
        return component_key
get_settings_checksum(component_key: str, step: Optional[str] = None) -> Optional[str]

Get the settings checksum for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the checksum.

required
step Optional[str]

The pipeline step for which to get the checksum. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
Optional[str]

The settings checksum.

Source code in src/zenml/models/v2/core/pipeline_build.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def get_settings_checksum(
    self, component_key: str, step: Optional[str] = None
) -> Optional[str]:
    """Get the settings checksum for a specific key.

    Args:
        component_key: The key for which to get the checksum.
        step: The pipeline step for which to get the checksum. If no
            image exists for this step, will fall back to the pipeline image
            for the same key.

    Returns:
        The settings checksum.
    """
    return self._get_item(
        component_key=component_key, step=step
    ).settings_checksum

PipelineBuildFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all pipeline builds.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/pipeline_build.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
def get_custom_filters(
    self,
    table: Type["AnySchema"],
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.enums import StackComponentType
    from zenml.zen_stores.schemas import (
        PipelineBuildSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.container_registry_id:
        container_registry_filter = and_(
            PipelineBuildSchema.stack_id == StackSchema.id,
            StackSchema.id == StackCompositionSchema.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            StackComponentSchema.type
            == StackComponentType.CONTAINER_REGISTRY.value,
            StackComponentSchema.id == self.container_registry_id,
        )
        custom_filters.append(container_registry_filter)

    return custom_filters

PipelineBuildRequest

Bases: PipelineBuildBase, WorkspaceScopedRequest

Request model for pipelines builds.

PipelineBuildResponse

Bases: WorkspaceScopedResponse[PipelineBuildResponseBody, PipelineBuildResponseMetadata, PipelineBuildResponseResources]

Response model for pipeline builds.

Attributes
checksum: Optional[str] property

The checksum property.

Returns:

Type Description
Optional[str]

the value of the property.

contains_code: bool property

The contains_code property.

Returns:

Type Description
bool

the value of the property.

images: Dict[str, BuildItem] property

The images property.

Returns:

Type Description
Dict[str, BuildItem]

the value of the property.

is_local: bool property

The is_local property.

Returns:

Type Description
bool

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

python_version: Optional[str] property

The python_version property.

Returns:

Type Description
Optional[str]

the value of the property.

requires_code_download: bool property

Whether the build requires code download.

Returns:

Type Description
bool

Whether the build requires code download.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

stack_checksum: Optional[str] property

The stack_checksum property.

Returns:

Type Description
Optional[str]

the value of the property.

zenml_version: Optional[str] property

The zenml_version property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_hydrated_version() -> PipelineBuildResponse

Return the hydrated version of this pipeline build.

Returns:

Type Description
PipelineBuildResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_build.py
241
242
243
244
245
246
247
248
249
def get_hydrated_version(self) -> "PipelineBuildResponse":
    """Return the hydrated version of this pipeline build.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_build(self.id)
get_image(component_key: str, step: Optional[str] = None) -> str

Get the image built for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the image.

required
step Optional[str]

The pipeline step for which to get the image. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
str

The image name or digest.

Source code in src/zenml/models/v2/core/pipeline_build.py
309
310
311
312
313
314
315
316
317
318
319
320
321
def get_image(self, component_key: str, step: Optional[str] = None) -> str:
    """Get the image built for a specific key.

    Args:
        component_key: The key for which to get the image.
        step: The pipeline step for which to get the image. If no image
            exists for this step, will fall back to the pipeline image for
            the same key.

    Returns:
        The image name or digest.
    """
    return self._get_item(component_key=component_key, step=step).image
get_image_key(component_key: str, step: Optional[str] = None) -> str staticmethod

Get the image key.

Parameters:

Name Type Description Default
component_key str

The component key.

required
step Optional[str]

The pipeline step for which the image was built.

None

Returns:

Type Description
str

The image key.

Source code in src/zenml/models/v2/core/pipeline_build.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
@staticmethod
def get_image_key(component_key: str, step: Optional[str] = None) -> str:
    """Get the image key.

    Args:
        component_key: The component key.
        step: The pipeline step for which the image was built.

    Returns:
        The image key.
    """
    if step:
        return f"{step}.{component_key}"
    else:
        return component_key
get_settings_checksum(component_key: str, step: Optional[str] = None) -> Optional[str]

Get the settings checksum for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the checksum.

required
step Optional[str]

The pipeline step for which to get the checksum. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
Optional[str]

The settings checksum.

Source code in src/zenml/models/v2/core/pipeline_build.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
def get_settings_checksum(
    self, component_key: str, step: Optional[str] = None
) -> Optional[str]:
    """Get the settings checksum for a specific key.

    Args:
        component_key: The key for which to get the checksum.
        step: The pipeline step for which to get the checksum. If no
            image exists for this step, will fall back to the pipeline image
            for the same key.

    Returns:
        The settings checksum.
    """
    return self._get_item(
        component_key=component_key, step=step
    ).settings_checksum
to_yaml() -> Dict[str, Any]

Create a yaml representation of the pipeline build.

Create a yaml representation of the pipeline build that can be used to create a PipelineBuildBase instance.

Returns:

Type Description
Dict[str, Any]

The yaml representation of the pipeline build.

Source code in src/zenml/models/v2/core/pipeline_build.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def to_yaml(self) -> Dict[str, Any]:
    """Create a yaml representation of the pipeline build.

    Create a yaml representation of the pipeline build that can be used
    to create a PipelineBuildBase instance.

    Returns:
        The yaml representation of the pipeline build.
    """
    # Get the base attributes
    yaml_dict: Dict[str, Any] = json.loads(
        self.model_dump_json(
            exclude={
                "body",
                "metadata",
            }
        )
    )
    images = json.loads(
        self.get_metadata().model_dump_json(
            exclude={
                "pipeline",
                "stack",
                "workspace",
            }
        )
    )
    yaml_dict.update(images)
    return yaml_dict

PipelineBuildResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline builds.

PipelineBuildResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline builds.

PipelineDeploymentBase

Bases: BaseZenModel

Base model for pipeline deployments.

Attributes
should_prevent_build_reuse: bool property

Whether the deployment prevents a build reuse.

Returns:

Type Description
bool

Whether the deployment prevents a build reuse.

PipelineDeploymentFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all pipeline deployments.

PipelineDeploymentRequest

Bases: PipelineDeploymentBase, WorkspaceScopedRequest

Request model for pipeline deployments.

PipelineDeploymentResponse

Bases: WorkspaceScopedResponse[PipelineDeploymentResponseBody, PipelineDeploymentResponseMetadata, PipelineDeploymentResponseResources]

Response model for pipeline deployments.

Attributes
build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

client_environment: Dict[str, str] property

The client_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

client_version: Optional[str] property

The client_version property.

Returns:

Type Description
Optional[str]

the value of the property.

code_path: Optional[str] property

The code_path property.

Returns:

Type Description
Optional[str]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The code_reference property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

pipeline_configuration: PipelineConfiguration property

The pipeline_configuration property.

Returns:

Type Description
PipelineConfiguration

the value of the property.

pipeline_spec: Optional[PipelineSpec] property

The pipeline_spec property.

Returns:

Type Description
Optional[PipelineSpec]

the value of the property.

pipeline_version_hash: Optional[str] property

The pipeline_version_hash property.

Returns:

Type Description
Optional[str]

the value of the property.

run_name_template: str property

The run_name_template property.

Returns:

Type Description
str

the value of the property.

schedule: Optional[ScheduleResponse] property

The schedule property.

Returns:

Type Description
Optional[ScheduleResponse]

the value of the property.

server_version: Optional[str] property

The server_version property.

Returns:

Type Description
Optional[str]

the value of the property.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

step_configurations: Dict[str, Step] property

The step_configurations property.

Returns:

Type Description
Dict[str, Step]

the value of the property.

template_id: Optional[UUID] property

The template_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

Functions
get_hydrated_version() -> PipelineDeploymentResponse

Return the hydrated version of this pipeline deployment.

Returns:

Type Description
PipelineDeploymentResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_deployment.py
208
209
210
211
212
213
214
215
216
def get_hydrated_version(self) -> "PipelineDeploymentResponse":
    """Return the hydrated version of this pipeline deployment.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_deployment(self.id)

PipelineDeploymentResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline deployments.

PipelineDeploymentResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline deployments.

PipelineDeploymentResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline deployment entity.

PipelineFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Pipeline filter model.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/pipeline.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def apply_filter(
    self, query: AnyQuery, table: Type["AnySchema"]
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query, table)

    from sqlmodel import and_, col, func, select

    from zenml.zen_stores.schemas import PipelineRunSchema, PipelineSchema

    if self.latest_run_status:
        latest_pipeline_run_subquery = (
            select(
                PipelineRunSchema.pipeline_id,
                func.max(PipelineRunSchema.created).label("created"),
            )
            .where(col(PipelineRunSchema.pipeline_id).is_not(None))
            .group_by(col(PipelineRunSchema.pipeline_id))
            .subquery()
        )

        query = (
            query.join(
                PipelineRunSchema,
                PipelineSchema.id == PipelineRunSchema.pipeline_id,
            )
            .join(
                latest_pipeline_run_subquery,
                and_(
                    PipelineRunSchema.pipeline_id
                    == latest_pipeline_run_subquery.c.pipeline_id,
                    PipelineRunSchema.created
                    == latest_pipeline_run_subquery.c.created,
                ),
            )
            .where(
                self.generate_custom_query_conditions_for_column(
                    value=self.latest_run_status,
                    table=PipelineRunSchema,
                    column="status",
                )
            )
        )

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/pipeline.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import PipelineRunSchema, PipelineSchema

    sort_by, operand = self.sorting_params

    if sort_by == SORT_PIPELINES_BY_LATEST_RUN_KEY:
        # Subquery to find the latest run per pipeline
        latest_run_subquery = (
            select(
                PipelineSchema.id,
                case(
                    (
                        func.max(PipelineRunSchema.created).is_(None),
                        PipelineSchema.created,
                    ),
                    else_=func.max(PipelineRunSchema.created),
                ).label("latest_run"),
            )
            .outerjoin(
                PipelineRunSchema,
                PipelineSchema.id == PipelineRunSchema.pipeline_id,  # type: ignore[arg-type]
            )
            .group_by(col(PipelineSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_run_subquery.c.latest_run,
        ).where(PipelineSchema.id == latest_run_subquery.c.id)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_run_subquery.c.latest_run),
                asc(PipelineSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_run_subquery.c.latest_run),
                desc(PipelineSchema.id),
            )
        return query
    else:
        return super().apply_sorting(query=query, table=table)

PipelineRequest

Bases: WorkspaceScopedRequest

Request model for pipelines.

PipelineResponse

Bases: WorkspaceScopedResponse[PipelineResponseBody, PipelineResponseMetadata, PipelineResponseResources]

Response model for pipelines.

Attributes
last_run: PipelineRunResponse property

Returns the last run of this pipeline.

Returns:

Type Description
PipelineRunResponse

The last run of this pipeline.

Raises:

Type Description
RuntimeError

If no runs were found for this pipeline.

last_successful_run: PipelineRunResponse property

Returns the last successful run of this pipeline.

Returns:

Type Description
PipelineRunResponse

The last successful run of this pipeline.

Raises:

Type Description
RuntimeError

If no successful runs were found for this pipeline.

latest_run_id: Optional[UUID] property

The latest_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_run_status: Optional[ExecutionStatus] property

The latest_run_status property.

Returns:

Type Description
Optional[ExecutionStatus]

the value of the property.

num_runs: int property

Returns the number of runs of this pipeline.

Returns:

Type Description
int

The number of runs of this pipeline.

runs: List[PipelineRunResponse] property

Returns the 20 most recent runs of this pipeline in descending order.

Returns:

Type Description
List[PipelineRunResponse]

The 20 most recent runs of this pipeline in descending order.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_hydrated_version() -> PipelineResponse

Get the hydrated version of this pipeline.

Returns:

Type Description
PipelineResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline.py
146
147
148
149
150
151
152
153
154
def get_hydrated_version(self) -> "PipelineResponse":
    """Get the hydrated version of this pipeline.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_pipeline(self.id)
get_runs(**kwargs: Any) -> List[PipelineRunResponse]

Get runs of this pipeline.

Can be used to fetch runs other than self.runs and supports fine-grained filtering and pagination.

Parameters:

Name Type Description Default
**kwargs Any

Further arguments for filtering or pagination that are passed to client.list_pipeline_runs().

{}

Returns:

Type Description
List[PipelineRunResponse]

List of runs of this pipeline.

Source code in src/zenml/models/v2/core/pipeline.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def get_runs(self, **kwargs: Any) -> List["PipelineRunResponse"]:
    """Get runs of this pipeline.

    Can be used to fetch runs other than `self.runs` and supports
    fine-grained filtering and pagination.

    Args:
        **kwargs: Further arguments for filtering or pagination that are
            passed to `client.list_pipeline_runs()`.

    Returns:
        List of runs of this pipeline.
    """
    from zenml.client import Client

    return Client().list_pipeline_runs(pipeline_id=self.id, **kwargs).items

PipelineResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipelines.

PipelineResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipelines.

PipelineResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline entity.

PipelineRunFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of all Workspaces.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/pipeline_run.py
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
        PipelineDeploymentSchema,
        PipelineRunSchema,
        PipelineSchema,
        StackSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == "pipeline":
        query = query.outerjoin(
            PipelineSchema,
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
        )
        column = PipelineSchema.name
    elif sort_by == "stack":
        query = query.outerjoin(
            PipelineDeploymentSchema,
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
        ).outerjoin(
            StackSchema,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
        )
        column = StackSchema.name
    elif sort_by == "model":
        query = query.outerjoin(
            ModelVersionSchema,
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
        ).outerjoin(
            ModelSchema,
            ModelVersionSchema.model_id == ModelSchema.id,
        )
        column = ModelSchema.name
    elif sort_by == "model_version":
        query = query.outerjoin(
            ModelVersionSchema,
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
        )
        column = ModelVersionSchema.name
    else:
        return super().apply_sorting(query=query, table=table)

    query = query.add_columns(column)

    if operand == SorterOps.ASCENDING:
        query = query.order_by(asc(column))
    else:
        query = query.order_by(desc(column))

    return query
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/pipeline_run.py
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
def get_custom_filters(
    self,
    table: Type["AnySchema"],
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, col, or_

    from zenml.zen_stores.schemas import (
        CodeReferenceSchema,
        CodeRepositorySchema,
        ModelSchema,
        ModelVersionSchema,
        PipelineBuildSchema,
        PipelineDeploymentSchema,
        PipelineRunSchema,
        PipelineSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        ScheduleSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.unlisted is not None:
        if self.unlisted is True:
            unlisted_filter = PipelineRunSchema.pipeline_id.is_(None)  # type: ignore[union-attr]
        else:
            unlisted_filter = PipelineRunSchema.pipeline_id.is_not(None)  # type: ignore[union-attr]
        custom_filters.append(unlisted_filter)

    if self.code_repository_id:
        code_repo_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == self.code_repository_id,
        )
        custom_filters.append(code_repo_filter)

    if self.stack_id:
        stack_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            StackSchema.id == self.stack_id,
        )
        custom_filters.append(stack_filter)

    if self.schedule_id:
        schedule_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.schedule_id == ScheduleSchema.id,
            ScheduleSchema.id == self.schedule_id,
        )
        custom_filters.append(schedule_filter)

    if self.build_id:
        pipeline_build_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.build_id == PipelineBuildSchema.id,
            PipelineBuildSchema.id == self.build_id,
        )
        custom_filters.append(pipeline_build_filter)

    if self.template_id:
        run_template_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.template_id == self.template_id,
        )
        custom_filters.append(run_template_filter)

    if self.pipeline:
        pipeline_filter = and_(
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline, table=PipelineSchema
            ),
        )
        custom_filters.append(pipeline_filter)

    if self.stack:
        stack_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack,
                table=StackSchema,
            ),
        )
        custom_filters.append(stack_filter)

    if self.code_repository:
        code_repo_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == CodeRepositorySchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.code_repository,
                table=CodeRepositorySchema,
            ),
        )
        custom_filters.append(code_repo_filter)

    if self.model:
        model_filter = and_(
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)

    if self.stack_component:
        component_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            StackSchema.id == StackCompositionSchema.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack_component,
                table=StackComponentSchema,
            ),
        )
        custom_filters.append(component_filter)

    if self.pipeline_name:
        pipeline_name_filter = and_(
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
            self.generate_custom_query_conditions_for_column(
                value=self.pipeline_name,
                table=PipelineSchema,
                column="name",
            ),
        )
        custom_filters.append(pipeline_name_filter)

    if self.templatable is not None:
        if self.templatable is True:
            templatable_filter = and_(
                # The following condition is not perfect as it does not
                # consider stacks with custom flavor components or local
                # components, but the best we can do currently with our
                # table columns.
                PipelineRunSchema.deployment_id
                == PipelineDeploymentSchema.id,
                PipelineDeploymentSchema.build_id
                == PipelineBuildSchema.id,
                col(PipelineBuildSchema.is_local).is_(False),
                col(PipelineBuildSchema.stack_id).is_not(None),
            )
        else:
            templatable_filter = or_(
                col(PipelineRunSchema.deployment_id).is_(None),
                and_(
                    PipelineRunSchema.deployment_id
                    == PipelineDeploymentSchema.id,
                    col(PipelineDeploymentSchema.build_id).is_(None),
                ),
                and_(
                    PipelineRunSchema.deployment_id
                    == PipelineDeploymentSchema.id,
                    PipelineDeploymentSchema.build_id
                    == PipelineBuildSchema.id,
                    or_(
                        col(PipelineBuildSchema.is_local).is_(True),
                        col(PipelineBuildSchema.stack_id).is_(None),
                    ),
                ),
            )

        custom_filters.append(templatable_filter)
    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == PipelineRunSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.PIPELINE_RUN.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters

PipelineRunRequest

Bases: WorkspaceScopedRequest

Request model for pipeline runs.

PipelineRunResponse

Bases: WorkspaceScopedResponse[PipelineRunResponseBody, PipelineRunResponseMetadata, PipelineRunResponseResources]

Response model for pipeline runs.

Attributes
artifact_versions: List[ArtifactVersionResponse] property

Get all artifact versions that are outputs of steps of this run.

Returns:

Type Description
List[ArtifactVersionResponse]

All output artifact versions of this run (including cached ones).

build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

client_environment: Dict[str, str] property

The client_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

code_path: Optional[str] property

The code_path property.

Returns:

Type Description
Optional[str]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The schedule property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

config: PipelineConfiguration property

The config property.

Returns:

Type Description
PipelineConfiguration

the value of the property.

deployment_id: Optional[UUID] property

The deployment_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

is_templatable: bool property

The is_templatable property.

Returns:

Type Description
bool

the value of the property.

model_version: Optional[ModelVersionResponse] property

The model_version property.

Returns:

Type Description
Optional[ModelVersionResponse]

the value of the property.

model_version_id: Optional[UUID] property

The model_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

orchestrator_environment: Dict[str, str] property

The orchestrator_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

orchestrator_run_id: Optional[str] property

The orchestrator_run_id property.

Returns:

Type Description
Optional[str]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

produced_artifact_versions: List[ArtifactVersionResponse] property

Get all artifact versions produced during this pipeline run.

Returns:

Type Description
List[ArtifactVersionResponse]

A list of all artifact versions produced during this pipeline run.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

schedule: Optional[ScheduleResponse] property

The schedule property.

Returns:

Type Description
Optional[ScheduleResponse]

the value of the property.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

status: ExecutionStatus property

The status property.

Returns:

Type Description
ExecutionStatus

the value of the property.

step_substitutions: Dict[str, Dict[str, str]] property

The step_substitutions property.

Returns:

Type Description
Dict[str, Dict[str, str]]

the value of the property.

steps: Dict[str, StepRunResponse] property

The steps property.

Returns:

Type Description
Dict[str, StepRunResponse]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

template_id: Optional[UUID] property

The template_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

trigger_execution: Optional[TriggerExecutionResponse] property

The trigger_execution property.

Returns:

Type Description
Optional[TriggerExecutionResponse]

the value of the property.

Functions
get_hydrated_version() -> PipelineRunResponse

Get the hydrated version of this pipeline run.

Returns:

Type Description
PipelineRunResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_run.py
286
287
288
289
290
291
292
293
294
def get_hydrated_version(self) -> "PipelineRunResponse":
    """Get the hydrated version of this pipeline run.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_run(self.id)
refresh_run_status() -> PipelineRunResponse

Method to refresh the status of a run if it is initializing/running.

Returns:

Type Description
PipelineRunResponse

The updated pipeline.

Raises:

Type Description
ValueError

If the stack of the run response is None.

Source code in src/zenml/models/v2/core/pipeline_run.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def refresh_run_status(self) -> "PipelineRunResponse":
    """Method to refresh the status of a run if it is initializing/running.

    Returns:
        The updated pipeline.

    Raises:
        ValueError: If the stack of the run response is None.
    """
    if self.status in [
        ExecutionStatus.INITIALIZING,
        ExecutionStatus.RUNNING,
    ]:
        # Check if the stack still accessible
        if self.stack is None:
            raise ValueError(
                "The stack that this pipeline run response was executed on"
                "has been deleted."
            )

        # Create the orchestrator instance
        from zenml.enums import StackComponentType
        from zenml.orchestrators.base_orchestrator import BaseOrchestrator
        from zenml.stack.stack_component import StackComponent

        # Check if the stack still accessible
        orchestrator_list = self.stack.components.get(
            StackComponentType.ORCHESTRATOR, []
        )
        if len(orchestrator_list) == 0:
            raise ValueError(
                "The orchestrator that this pipeline run response was "
                "executed with has been deleted."
            )

        orchestrator = cast(
            BaseOrchestrator,
            StackComponent.from_model(
                component_model=orchestrator_list[0]
            ),
        )

        # Fetch the status
        status = orchestrator.fetch_status(run=self)

        # If it is different from the current status, update it
        if status != self.status:
            from zenml.client import Client
            from zenml.models import PipelineRunUpdate

            client = Client()
            return client.zen_store.update_run(
                run_id=self.id,
                run_update=PipelineRunUpdate(status=status),
            )

    return self

PipelineRunResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline runs.

PipelineRunResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline runs.

PipelineRunResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline run entity.

PipelineRunUpdate

Bases: BaseModel

Pipeline run update model.

PipelineUpdate

Bases: BaseUpdate

Update model for pipelines.

ResourceTypeModel

Bases: BaseModel

Resource type specification.

Describes the authentication methods and resource instantiation model for one or more resource types.

Attributes
emojified_resource_type: str property

Get the emojified resource type.

Returns:

Type Description
str

The emojified resource type.

ResourcesInfo

Bases: BaseModel

Information about the resources needed for CLI and UI.

RunMetadataEntry

Bases: BaseModel

Utility class to sort/list run metadata entries.

RunMetadataRequest

Bases: WorkspaceScopedRequest

Request model for run metadata.

Functions
validate_values_keys() -> RunMetadataRequest

Validates if the keys in the metadata are properly defined.

Returns:

Type Description
RunMetadataRequest

self

Raises:

Type Description
ValueError

if one of the key in the metadata contains :

Source code in src/zenml/models/v2/core/run_metadata.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@model_validator(mode="after")
def validate_values_keys(self) -> "RunMetadataRequest":
    """Validates if the keys in the metadata are properly defined.

    Returns:
        self

    Raises:
        ValueError: if one of the key in the metadata contains `:`
    """
    invalid_keys = [key for key in self.values.keys() if ":" in key]
    if invalid_keys:
        raise ValueError(
            "You can not use colons (`:`) in the key names when you "
            "are creating metadata for your ZenML objects. Please change "
            f"the following keys: {invalid_keys}"
        )
    return self

RunMetadataResource

Bases: BaseModel

Utility class to help identify resources to tag metadata to.

RunTemplateFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model for filtering of run templates.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/run_template.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        CodeReferenceSchema,
        PipelineDeploymentSchema,
        PipelineSchema,
        RunTemplateSchema,
        StackSchema,
    )

    if self.code_repository_id:
        code_repo_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == self.code_repository_id,
        )
        custom_filters.append(code_repo_filter)

    if self.stack_id:
        stack_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == self.stack_id,
        )
        custom_filters.append(stack_filter)

    if self.build_id:
        build_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.build_id == self.build_id,
        )
        custom_filters.append(build_filter)

    if self.pipeline_id:
        pipeline_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.pipeline_id == self.pipeline_id,
        )
        custom_filters.append(pipeline_filter)

    if self.pipeline:
        pipeline_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.pipeline_id == PipelineSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline,
                table=PipelineSchema,
            ),
        )
        custom_filters.append(pipeline_filter)

    if self.stack:
        stack_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack,
                table=StackSchema,
            ),
        )
        custom_filters.append(stack_filter)

    return custom_filters

RunTemplateRequest

Bases: WorkspaceScopedRequest

Request model for run templates.

RunTemplateResponse

Bases: WorkspaceScopedResponse[RunTemplateResponseBody, RunTemplateResponseMetadata, RunTemplateResponseResources]

Response model for run templates.

Attributes
build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The code_reference property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

config_schema: Optional[Dict[str, Any]] property

The config_schema property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

config_template: Optional[Dict[str, Any]] property

The config_template property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

latest_run_id: Optional[UUID] property

The latest_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_run_status: Optional[ExecutionStatus] property

The latest_run_status property.

Returns:

Type Description
Optional[ExecutionStatus]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

pipeline_spec: Optional[PipelineSpec] property

The pipeline_spec property.

Returns:

Type Description
Optional[PipelineSpec]

the value of the property.

runnable: bool property

The runnable property.

Returns:

Type Description
bool

the value of the property.

source_deployment: Optional[PipelineDeploymentResponse] property

The source_deployment property.

Returns:

Type Description
Optional[PipelineDeploymentResponse]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_hydrated_version() -> RunTemplateResponse

Return the hydrated version of this run template.

Returns:

Type Description
RunTemplateResponse

The hydrated run template.

Source code in src/zenml/models/v2/core/run_template.py
186
187
188
189
190
191
192
193
194
195
196
def get_hydrated_version(self) -> "RunTemplateResponse":
    """Return the hydrated version of this run template.

    Returns:
        The hydrated run template.
    """
    from zenml.client import Client

    return Client().zen_store.get_run_template(
        template_id=self.id, hydrate=True
    )

RunTemplateResponseBody

Bases: WorkspaceScopedResponseBody

Response body for run templates.

RunTemplateResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for run templates.

RunTemplateResponseResources

Bases: WorkspaceScopedResponseResources

All resource models associated with the run template.

RunTemplateUpdate

Bases: BaseUpdate

Run template update model.

ScheduleFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Users.

ScheduleRequest

Bases: WorkspaceScopedRequest

Request model for schedules.

ScheduleResponse

Bases: WorkspaceScopedResponse[ScheduleResponseBody, ScheduleResponseMetadata, ScheduleResponseResources]

Response model for schedules.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

catchup: bool property

The catchup property.

Returns:

Type Description
bool

the value of the property.

cron_expression: Optional[str] property

The cron_expression property.

Returns:

Type Description
Optional[str]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

interval_second: Optional[timedelta] property

The interval_second property.

Returns:

Type Description
Optional[timedelta]

the value of the property.

orchestrator_id: Optional[UUID] property

The orchestrator_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

pipeline_id: Optional[UUID] property

The pipeline_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

run_once_start_time: Optional[datetime] property

The run_once_start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

utc_end_time: Optional[str] property

Optional ISO-formatted string of the UTC end time.

Returns:

Type Description
Optional[str]

Optional ISO-formatted string of the UTC end time.

utc_start_time: Optional[str] property

Optional ISO-formatted string of the UTC start time.

Returns:

Type Description
Optional[str]

Optional ISO-formatted string of the UTC start time.

Functions
get_hydrated_version() -> ScheduleResponse

Get the hydrated version of this schedule.

Returns:

Type Description
ScheduleResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/schedule.py
186
187
188
189
190
191
192
193
194
def get_hydrated_version(self) -> "ScheduleResponse":
    """Get the hydrated version of this schedule.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_schedule(self.id)

ScheduleResponseBody

Bases: WorkspaceScopedResponseBody

Response body for schedules.

ScheduleResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for schedules.

ScheduleUpdate

Bases: BaseUpdate

Update model for schedules.

SecretFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Secrets.

Functions
secret_matches(secret: SecretResponse) -> bool

Checks if a secret matches the filter criteria.

Parameters:

Name Type Description Default
secret SecretResponse

The secret to check.

required

Returns:

Type Description
bool

True if the secret matches the filter criteria, False otherwise.

Source code in src/zenml/models/v2/core/secret.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
def secret_matches(self, secret: SecretResponse) -> bool:
    """Checks if a secret matches the filter criteria.

    Args:
        secret: The secret to check.

    Returns:
        True if the secret matches the filter criteria, False otherwise.
    """
    for filter in self.list_of_filters:
        column_value: Optional[Any] = None
        if filter.column == "workspace_id":
            column_value = secret.workspace.id
        elif filter.column == "user_id":
            column_value = secret.user.id if secret.user else None
        else:
            column_value = getattr(secret, filter.column)

        # Convert the values to strings for lexicographical comparison.
        str_column_value = self._get_filtering_value(column_value)
        str_filter_value = self._get_filtering_value(filter.value)

        # Compare the lexicographical values according to the operation.
        if filter.operation == GenericFilterOps.EQUALS:
            result = str_column_value == str_filter_value
        elif filter.operation == GenericFilterOps.CONTAINS:
            result = str_filter_value in str_column_value
        elif filter.operation == GenericFilterOps.STARTSWITH:
            result = str_column_value.startswith(str_filter_value)
        elif filter.operation == GenericFilterOps.ENDSWITH:
            result = str_column_value.endswith(str_filter_value)
        elif filter.operation == GenericFilterOps.GT:
            result = str_column_value > str_filter_value
        elif filter.operation == GenericFilterOps.GTE:
            result = str_column_value >= str_filter_value
        elif filter.operation == GenericFilterOps.LT:
            result = str_column_value < str_filter_value
        elif filter.operation == GenericFilterOps.LTE:
            result = str_column_value <= str_filter_value

        # Exit early if the result is False for AND, and True for OR
        if self.logical_operator == LogicalOperators.AND:
            if not result:
                return False
        else:
            if result:
                return True

    # If we get here, all filters have been checked and the result is
    # True for AND, and False for OR
    if self.logical_operator == LogicalOperators.AND:
        return True
    else:
        return False
sort_secrets(secrets: List[SecretResponse]) -> List[SecretResponse]

Sorts a list of secrets according to the filter criteria.

Parameters:

Name Type Description Default
secrets List[SecretResponse]

The list of secrets to sort.

required

Returns:

Type Description
List[SecretResponse]

The sorted list of secrets.

Source code in src/zenml/models/v2/core/secret.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def sort_secrets(
    self, secrets: List[SecretResponse]
) -> List[SecretResponse]:
    """Sorts a list of secrets according to the filter criteria.

    Args:
        secrets: The list of secrets to sort.

    Returns:
        The sorted list of secrets.
    """
    column, sort_op = self.sorting_params
    sorted_secrets = sorted(
        secrets,
        key=lambda secret: self._get_filtering_value(
            getattr(secret, column)
        ),
        reverse=sort_op == SorterOps.DESCENDING,
    )

    return sorted_secrets

SecretRequest

Bases: WorkspaceScopedRequest

Request models for secrets.

Attributes
secret_values: Dict[str, str] property

A dictionary with all un-obfuscated values stored in this secret.

The values are returned as strings, not SecretStr. If a value is None, it is not included in the returned dictionary. This is to enable the use of None values in the update model to indicate that a secret value should be deleted.

Returns:

Type Description
Dict[str, str]

A dictionary containing the secret's values.

SecretResponse

Bases: WorkspaceScopedResponse[SecretResponseBody, SecretResponseMetadata, SecretResponseResources]

Response model for secrets.

Attributes
has_missing_values: bool property

Returns True if the secret has missing values (i.e. None).

Values can be missing from a secret for example if the user retrieves a secret but does not have the permission to view the secret values.

Returns:

Type Description
bool

True if the secret has any values set to None.

scope: SecretScope property

The scope property.

Returns:

Type Description
SecretScope

the value of the property.

secret_values: Dict[str, str] property

A dictionary with all un-obfuscated values stored in this secret.

The values are returned as strings, not SecretStr. If a value is None, it is not included in the returned dictionary. This is to enable the use of None values in the update model to indicate that a secret value should be deleted.

Returns:

Type Description
Dict[str, str]

A dictionary containing the secret's values.

values: Dict[str, Optional[SecretStr]] property

The values property.

Returns:

Type Description
Dict[str, Optional[SecretStr]]

the value of the property.

Functions
add_secret(key: str, value: str) -> None

Adds a secret value to the secret.

Parameters:

Name Type Description Default
key str

The key of the secret value.

required
value str

The secret value.

required
Source code in src/zenml/models/v2/core/secret.py
210
211
212
213
214
215
216
217
def add_secret(self, key: str, value: str) -> None:
    """Adds a secret value to the secret.

    Args:
        key: The key of the secret value.
        value: The secret value.
    """
    self.get_body().values[key] = SecretStr(value)
get_hydrated_version() -> SecretResponse

Get the hydrated version of this workspace.

Returns:

Type Description
SecretResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/secret.py
149
150
151
152
153
154
155
156
157
def get_hydrated_version(self) -> "SecretResponse":
    """Get the hydrated version of this workspace.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_secret(self.id)
remove_secret(key: str) -> None

Removes a secret value from the secret.

Parameters:

Name Type Description Default
key str

The key of the secret value.

required
Source code in src/zenml/models/v2/core/secret.py
219
220
221
222
223
224
225
def remove_secret(self, key: str) -> None:
    """Removes a secret value from the secret.

    Args:
        key: The key of the secret value.
    """
    del self.get_body().values[key]
remove_secrets() -> None

Removes all secret values from the secret but keep the keys.

Source code in src/zenml/models/v2/core/secret.py
227
228
229
def remove_secrets(self) -> None:
    """Removes all secret values from the secret but keep the keys."""
    self.get_body().values = {k: None for k in self.values.keys()}
set_secrets(values: Dict[str, str]) -> None

Sets the secret values of the secret.

Parameters:

Name Type Description Default
values Dict[str, str]

The secret values to set.

required
Source code in src/zenml/models/v2/core/secret.py
231
232
233
234
235
236
237
def set_secrets(self, values: Dict[str, str]) -> None:
    """Sets the secret values of the secret.

    Args:
        values: The secret values to set.
    """
    self.get_body().values = {k: SecretStr(v) for k, v in values.items()}

SecretResponseBody

Bases: WorkspaceScopedResponseBody

Response body for secrets.

SecretResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for secrets.

SecretUpdate

Bases: BaseUpdate

Secret update model.

Functions
get_secret_values_update() -> Dict[str, Optional[str]]

Returns a dictionary with the secret values to update.

Returns:

Type Description
Dict[str, Optional[str]]

A dictionary with the secret values to update.

Source code in src/zenml/models/v2/core/secret.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def get_secret_values_update(self) -> Dict[str, Optional[str]]:
    """Returns a dictionary with the secret values to update.

    Returns:
        A dictionary with the secret values to update.
    """
    if self.values is not None:
        return {
            k: v.get_secret_value() if v is not None else None
            for k, v in self.values.items()
        }

    return {}

ServerActivationRequest

Bases: ServerSettingsUpdate

Model for activating the server.

ServerDatabaseType

Bases: StrEnum

Enum for server database types.

ServerDeploymentType

Bases: StrEnum

Enum for server deployment types.

ServerLoadInfo

Bases: BaseModel

Domain model for ZenML server load information.

ServerModel

Bases: BaseModel

Domain model for ZenML servers.

Functions
is_local() -> bool

Return whether the server is running locally.

Returns:

Type Description
bool

True if the server is running locally, False otherwise.

Source code in src/zenml/models/v2/misc/server_models.py
146
147
148
149
150
151
152
153
154
155
156
def is_local(self) -> bool:
    """Return whether the server is running locally.

    Returns:
        True if the server is running locally, False otherwise.
    """
    from zenml.config.global_config import GlobalConfiguration

    # Local ZenML servers are identifiable by the fact that their
    # server ID is the same as the local client (user) ID.
    return self.id == GlobalConfiguration().user_id
is_pro_server() -> bool

Return whether the server is a ZenML Pro server.

Returns:

Type Description
bool

True if the server is a ZenML Pro server, False otherwise.

Source code in src/zenml/models/v2/misc/server_models.py
158
159
160
161
162
163
164
def is_pro_server(self) -> bool:
    """Return whether the server is a ZenML Pro server.

    Returns:
        True if the server is a ZenML Pro server, False otherwise.
    """
    return self.deployment_type == ServerDeploymentType.CLOUD

ServerSettingsResponse

Bases: BaseResponse[ServerSettingsResponseBody, ServerSettingsResponseMetadata, ServerSettingsResponseResources]

Response model for server settings.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

display_announcements: Optional[bool] property

The display_announcements property.

Returns:

Type Description
Optional[bool]

the value of the property.

display_updates: Optional[bool] property

The display_updates property.

Returns:

Type Description
Optional[bool]

the value of the property.

enable_analytics: bool property

The enable_analytics property.

Returns:

Type Description
bool

the value of the property.

last_user_activity: datetime property

The last_user_activity property.

Returns:

Type Description
datetime

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

server_id: UUID property

The server_id property.

Returns:

Type Description
UUID

the value of the property.

server_name: str property

The server_name property.

Returns:

Type Description
str

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_hydrated_version() -> ServerSettingsResponse

Get the hydrated version of the server settings.

Returns:

Type Description
ServerSettingsResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/server_settings.py
110
111
112
113
114
115
116
117
118
def get_hydrated_version(self) -> "ServerSettingsResponse":
    """Get the hydrated version of the server settings.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_server_settings(hydrate=True)

ServerSettingsResponseBody

Bases: BaseResponseBody

Response body for server settings.

ServerSettingsResponseMetadata

Bases: BaseResponseMetadata

Response metadata for server settings.

ServerSettingsResponseResources

Bases: BaseResponseResources

Response resources for server settings.

ServerSettingsUpdate

Bases: BaseZenModel

Model for updating server settings.

ServiceAccountFilter

Bases: BaseFilter

Model to enable advanced filtering of service accounts.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to filter out user accounts from the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/service_account.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to filter out user accounts from the query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)
    query = query.where(
        getattr(table, "is_service_account") == True  # noqa: E712
    )

    return query

ServiceAccountRequest

Bases: BaseRequest

Request model for service accounts.

ServiceAccountResponse

Bases: BaseIdentifiedResponse[ServiceAccountResponseBody, ServiceAccountResponseMetadata, ServiceAccountResponseResources]

Response model for service accounts.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ServiceAccountResponse

Get the hydrated version of this service account.

Returns:

Type Description
ServiceAccountResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service_account.py
126
127
128
129
130
131
132
133
134
def get_hydrated_version(self) -> "ServiceAccountResponse":
    """Get the hydrated version of this service account.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service_account(self.id)
to_user_model() -> UserResponse

Converts the service account to a user model.

For now, a lot of code still relies on the active user and resource owners being a UserResponse object, which is a superset of the ServiceAccountResponse object. We need this method to convert the service account to a user.

Returns:

Type Description
UserResponse

The user model.

Source code in src/zenml/models/v2/core/service_account.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def to_user_model(self) -> "UserResponse":
    """Converts the service account to a user model.

    For now, a lot of code still relies on the active user and resource
    owners being a UserResponse object, which is a superset of the
    ServiceAccountResponse object. We need this method to convert the
    service account to a user.

    Returns:
        The user model.
    """
    from zenml.models.v2.core.user import (
        UserResponse,
        UserResponseBody,
        UserResponseMetadata,
    )

    return UserResponse(
        id=self.id,
        name=self.name,
        body=UserResponseBody(
            active=self.active,
            is_service_account=True,
            email_opted_in=False,
            created=self.created,
            updated=self.updated,
            is_admin=False,
        ),
        metadata=UserResponseMetadata(
            description=self.description,
        ),
    )

ServiceAccountResponseBody

Bases: BaseDatedResponseBody

Response body for service accounts.

ServiceAccountResponseMetadata

Bases: BaseResponseMetadata

Response metadata for service accounts.

ServiceAccountUpdate

Bases: BaseUpdate

Update model for service accounts.

ServiceConnectorFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of service connectors.

Functions
validate_labels() -> ServiceConnectorFilter

Parse the labels string into a label dictionary and vice-versa.

Returns:

Type Description
ServiceConnectorFilter

The validated values.

Source code in src/zenml/models/v2/core/service_connector.py
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
@model_validator(mode="after")
def validate_labels(self) -> "ServiceConnectorFilter":
    """Parse the labels string into a label dictionary and vice-versa.

    Returns:
        The validated values.
    """
    if self.labels_str is not None:
        try:
            self.labels = json.loads(self.labels_str)
        except json.JSONDecodeError:
            # Interpret as comma-separated values instead
            self.labels = {
                label.split("=", 1)[0]: label.split("=", 1)[1]
                if "=" in label
                else None
                for label in self.labels_str.split(",")
            }
    elif self.labels is not None:
        self.labels_str = json.dumps(self.labels)

    return self

ServiceConnectorInfo

Bases: BaseModel

Information about the service connector when creating a full stack.

ServiceConnectorRequest

Bases: WorkspaceScopedRequest

Request model for service connectors.

Attributes
emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector type.

Returns:

Type Description
List[str]

The emojified connector type.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
get_analytics_metadata() -> Dict[str, Any]

Format the resource types in the analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
120
121
122
123
124
125
126
127
128
129
130
131
132
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Format the resource types in the analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    if len(self.resource_types) == 1:
        metadata["resource_types"] = self.resource_types[0]
    else:
        metadata["resource_types"] = ", ".join(self.resource_types)
    metadata["connector_type"] = self.type
    return metadata
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )

ServiceConnectorRequirements

Bases: BaseModel

Service connector requirements.

Describes requirements that a service connector consumer has for a service connector instance that it needs in order to access a resource.

Attributes:

Name Type Description
connector_type Optional[str]

The type of service connector that is required. If omitted, any service connector type can be used.

resource_type str

The type of resource that the service connector instance must be able to access.

resource_id_attr Optional[str]

The name of an attribute in the stack component configuration that contains the resource ID of the resource that the service connector instance must be able to access.

Functions
is_satisfied_by(connector: Union[ServiceConnectorResponse, ServiceConnectorRequest], component: Union[ComponentResponse, ComponentBase]) -> Tuple[bool, str]

Check if the requirements are satisfied by a connector.

Parameters:

Name Type Description Default
connector Union[ServiceConnectorResponse, ServiceConnectorRequest]

The connector to check.

required
component Union[ComponentResponse, ComponentBase]

The stack component that the connector is associated with.

required

Returns:

Type Description
bool

True if the requirements are satisfied, False otherwise, and a

str

message describing the reason for the failure.

Source code in src/zenml/models/v2/misc/service_connector_type.py
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
def is_satisfied_by(
    self,
    connector: Union[
        "ServiceConnectorResponse", "ServiceConnectorRequest"
    ],
    component: Union["ComponentResponse", "ComponentBase"],
) -> Tuple[bool, str]:
    """Check if the requirements are satisfied by a connector.

    Args:
        connector: The connector to check.
        component: The stack component that the connector is associated
            with.

    Returns:
        True if the requirements are satisfied, False otherwise, and a
        message describing the reason for the failure.
    """
    if self.connector_type and self.connector_type != connector.type:
        return (
            False,
            f"connector type '{connector.type}' does not match the "
            f"'{self.connector_type}' connector type specified in the "
            "stack component requirements",
        )
    if self.resource_type not in connector.resource_types:
        return False, (
            f"connector does not provide the '{self.resource_type}' "
            "resource type specified in the stack component requirements. "
            "Only the following resource types are supported: "
            f"{', '.join(connector.resource_types)}"
        )
    if self.resource_id_attr:
        resource_id = component.configuration.get(self.resource_id_attr)
        if not resource_id:
            return (
                False,
                f"the '{self.resource_id_attr}' stack component "
                f"configuration attribute plays the role of resource "
                f"identifier, but the stack component does not contain a "
                f"'{self.resource_id_attr}' attribute. Please add the "
                f"'{self.resource_id_attr}' attribute to the stack "
                "component configuration and try again.",
            )

    return True, ""

ServiceConnectorResourcesInfo

Bases: BaseModel

Information about the service connector resources needed for CLI and UI.

ServiceConnectorResourcesModel

Bases: BaseModel

Service connector resources list.

Lists the resource types and resource instances that a service connector can provide access to.

Attributes
emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

resource_types: List[str] property

Get the resource types.

Returns:

Type Description
List[str]

The resource types.

resources_dict: Dict[str, ServiceConnectorTypedResourcesModel] property

Get the resources as a dictionary indexed by resource type.

Returns:

Type Description
Dict[str, ServiceConnectorTypedResourcesModel]

The resources as a dictionary indexed by resource type.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
from_connector_model(connector_model: ServiceConnectorResponse, resource_type: Optional[str] = None) -> ServiceConnectorResourcesModel classmethod

Initialize a resource model from a connector model.

Parameters:

Name Type Description Default
connector_model ServiceConnectorResponse

The connector model.

required
resource_type Optional[str]

The resource type to set on the resource model. If omitted, the resource type is set according to the connector model.

None

Returns:

Type Description
ServiceConnectorResourcesModel

A resource list model instance.

Source code in src/zenml/models/v2/misc/service_connector_type.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
@classmethod
def from_connector_model(
    cls,
    connector_model: "ServiceConnectorResponse",
    resource_type: Optional[str] = None,
) -> "ServiceConnectorResourcesModel":
    """Initialize a resource model from a connector model.

    Args:
        connector_model: The connector model.
        resource_type: The resource type to set on the resource model. If
            omitted, the resource type is set according to the connector
            model.

    Returns:
        A resource list model instance.
    """
    resources = cls(
        id=connector_model.id,
        name=connector_model.name,
        connector_type=connector_model.type,
    )

    resource_types = resource_type or connector_model.resource_types
    for resource_type in resource_types:
        resources.resources.append(
            ServiceConnectorTypedResourcesModel(
                resource_type=resource_type,
                resource_ids=[connector_model.resource_id]
                if connector_model.resource_id
                else None,
            )
        )

    return resources
get_default_resource_id() -> Optional[str]

Get the default resource ID, if included in the resource list.

The default resource ID is a resource ID supplied by the connector implementation only for resource types that do not support multiple instances.

Returns:

Type Description
Optional[str]

The default resource ID, or None if no resource ID is set.

Source code in src/zenml/models/v2/misc/service_connector_type.py
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
def get_default_resource_id(self) -> Optional[str]:
    """Get the default resource ID, if included in the resource list.

    The default resource ID is a resource ID supplied by the connector
    implementation only for resource types that do not support multiple
    instances.

    Returns:
        The default resource ID, or None if no resource ID is set.
    """
    if len(self.resources) != 1:
        # multi-type connectors do not have a default resource ID
        return None

    if isinstance(self.connector_type, str):
        # can't determine default resource ID for unknown connector types
        return None

    resource_type_spec = self.connector_type.resource_type_dict[
        self.resources[0].resource_type
    ]
    if resource_type_spec.supports_instances:
        # resource types that support multiple instances do not have a
        # default resource ID
        return None

    resource_ids = self.resources[0].resource_ids

    if not resource_ids or len(resource_ids) != 1:
        return None

    return resource_ids[0]
get_emojified_resource_types(resource_type: Optional[str] = None) -> List[str]

Get the emojified resource type.

Parameters:

Name Type Description Default
resource_type Optional[str]

The resource type to get the emojified resource type for. If omitted, the emojified resource type for all resource types is returned.

None

Returns:

Type Description
List[str]

The list of emojified resource types.

Source code in src/zenml/models/v2/misc/service_connector_type.py
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
def get_emojified_resource_types(
    self, resource_type: Optional[str] = None
) -> List[str]:
    """Get the emojified resource type.

    Args:
        resource_type: The resource type to get the emojified resource type
            for. If omitted, the emojified resource type for all resource
            types is returned.


    Returns:
        The list of emojified resource types.
    """
    if not isinstance(self.connector_type, str):
        if resource_type:
            return [
                self.connector_type.resource_type_dict[
                    resource_type
                ].emojified_resource_type
            ]
        return [
            self.connector_type.resource_type_dict[
                resource_type
            ].emojified_resource_type
            for resource_type in self.resources_dict.keys()
        ]
    if resource_type:
        return [resource_type]
    return list(self.resources_dict.keys())
set_error(error: str, resource_type: Optional[str] = None) -> None

Set a global error message or an error for a single resource type.

Parameters:

Name Type Description Default
error str

The error message.

required
resource_type Optional[str]

The resource type to set the error message for. If omitted, or if there is only one resource type involved, the error message is (also) set globally.

None

Raises:

Type Description
KeyError

If the resource type is not found in the resources list.

Source code in src/zenml/models/v2/misc/service_connector_type.py
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
def set_error(
    self, error: str, resource_type: Optional[str] = None
) -> None:
    """Set a global error message or an error for a single resource type.

    Args:
        error: The error message.
        resource_type: The resource type to set the error message for. If
            omitted, or if there is only one resource type involved, the
            error message is (also) set globally.

    Raises:
        KeyError: If the resource type is not found in the resources list.
    """
    if resource_type:
        resource = self.resources_dict.get(resource_type)
        if not resource:
            raise KeyError(
                f"resource type '{resource_type}' not found in "
                "service connector resources list"
            )
        resource.error = error
        resource.resource_ids = None
        if len(self.resources) == 1:
            # If there is only one resource type involved, set the global
            # error message as well.
            self.error = error
    else:
        self.error = error
        for resource in self.resources:
            resource.error = error
            resource.resource_ids = None
set_resource_ids(resource_type: str, resource_ids: List[str]) -> None

Set the resource IDs for a resource type.

Parameters:

Name Type Description Default
resource_type str

The resource type to set the resource IDs for.

required
resource_ids List[str]

The resource IDs to set.

required

Raises:

Type Description
KeyError

If the resource type is not found in the resources list.

Source code in src/zenml/models/v2/misc/service_connector_type.py
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
def set_resource_ids(
    self, resource_type: str, resource_ids: List[str]
) -> None:
    """Set the resource IDs for a resource type.

    Args:
        resource_type: The resource type to set the resource IDs for.
        resource_ids: The resource IDs to set.

    Raises:
        KeyError: If the resource type is not found in the resources list.
    """
    resource = self.resources_dict.get(resource_type)
    if not resource:
        raise KeyError(
            f"resource type '{resource_type}' not found in "
            "service connector resources list"
        )
    resource.resource_ids = resource_ids
    resource.error = None

ServiceConnectorResponse

Bases: WorkspaceScopedResponse[ServiceConnectorResponseBody, ServiceConnectorResponseMetadata, ServiceConnectorResponseResources]

Response model for service connectors.

Attributes
auth_method: str property

The auth_method property.

Returns:

Type Description
str

the value of the property.

configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector_type: Union[str, ServiceConnectorTypeModel] property

The connector_type property.

Returns:

Type Description
Union[str, ServiceConnectorTypeModel]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector type.

Returns:

Type Description
List[str]

The emojified connector type.

expiration_seconds: Optional[int] property

The expiration_seconds property.

Returns:

Type Description
Optional[int]

the value of the property.

expires_at: Optional[datetime] property

The expires_at property.

Returns:

Type Description
Optional[datetime]

the value of the property.

expires_skew_tolerance: Optional[int] property

The expires_skew_tolerance property.

Returns:

Type Description
Optional[int]

the value of the property.

full_configuration: Dict[str, str] property

Get the full connector configuration, including secrets.

Returns:

Type Description
Dict[str, str]

The full connector configuration, including secrets.

is_multi_instance: bool property

Checks if the connector is multi-instance.

A multi-instance connector is configured to access multiple instances of the configured resource type.

Returns:

Type Description
bool

True if the connector is multi-instance, False otherwise.

is_multi_type: bool property

Checks if the connector is multi-type.

A multi-type connector can be used to access multiple types of resources.

Returns:

Type Description
bool

True if the connector is multi-type, False otherwise.

is_single_instance: bool property

Checks if the connector is single-instance.

A single-instance connector is configured to access only a single instance of the configured resource type or does not support multiple resource instances.

Returns:

Type Description
bool

True if the connector is single-instance, False otherwise.

labels: Dict[str, str] property

The labels property.

Returns:

Type Description
Dict[str, str]

the value of the property.

resource_id: Optional[str] property

The resource_id property.

Returns:

Type Description
Optional[str]

the value of the property.

resource_types: List[str] property

The resource_types property.

Returns:

Type Description
List[str]

the value of the property.

secret_id: Optional[UUID] property

The secret_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

secrets: Dict[str, Optional[SecretStr]] property

The secrets property.

Returns:

Type Description
Dict[str, Optional[SecretStr]]

the value of the property.

supports_instances: bool property

The supports_instances property.

Returns:

Type Description
bool

the value of the property.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the service connector labels to analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the service connector labels to analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    metadata.update(
        {
            label[6:]: value
            for label, value in self.labels.items()
            if label.startswith("zenml:")
        }
    )
    return metadata
get_hydrated_version() -> ServiceConnectorResponse

Get the hydrated version of this service connector.

Returns:

Type Description
ServiceConnectorResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service_connector.py
517
518
519
520
521
522
523
524
525
def get_hydrated_version(self) -> "ServiceConnectorResponse":
    """Get the hydrated version of this service connector.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service_connector(self.id)
set_connector_type(value: Union[str, ServiceConnectorTypeModel]) -> None

Auxiliary method to set the connector type.

Parameters:

Name Type Description Default
value Union[str, ServiceConnectorTypeModel]

the new value for the connector type.

required
Source code in src/zenml/models/v2/core/service_connector.py
622
623
624
625
626
627
628
629
630
def set_connector_type(
    self, value: Union[str, "ServiceConnectorTypeModel"]
) -> None:
    """Auxiliary method to set the connector type.

    Args:
        value: the new value for the connector type.
    """
    self.get_body().connector_type = value
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )

ServiceConnectorResponseBody

Bases: WorkspaceScopedResponseBody

Response body for service connectors.

ServiceConnectorResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for service connectors.

ServiceConnectorTypeModel

Bases: BaseModel

Service connector type specification.

Describes the types of resources to which the service connector can be used to gain access and the authentication methods that are supported by the service connector.

The connector type, resource types, resource IDs and authentication methods can all be used as search criteria to lookup and filter service connector instances that are compatible with the requirements of a consumer (e.g. a stack component).

Attributes
auth_method_dict: Dict[str, AuthenticationMethodModel] property

Returns a map of authentication methods to authentication method specifications.

Returns:

Type Description
Dict[str, AuthenticationMethodModel]

A map of authentication methods to authentication method

Dict[str, AuthenticationMethodModel]

specifications.

connector_class: Optional[Type[ServiceConnector]] property

Get the service connector class.

Returns:

Type Description
Optional[Type[ServiceConnector]]

The service connector class.

emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector types.

Returns:

Type Description
List[str]

The emojified connector types.

resource_type_dict: Dict[str, ResourceTypeModel] property

Returns a map of resource types to resource type specifications.

Returns:

Type Description
Dict[str, ResourceTypeModel]

A map of resource types to resource type specifications.

Functions
find_resource_specifications(auth_method: str, resource_type: Optional[str] = None) -> Tuple[AuthenticationMethodModel, Optional[ResourceTypeModel]]

Find the specifications for a configurable resource.

Validate the supplied connector configuration parameters against the connector specification and return the matching authentication method specification and resource specification.

Parameters:

Name Type Description Default
auth_method str

The name of the authentication method.

required
resource_type Optional[str]

The type of resource being configured.

None

Returns:

Type Description
AuthenticationMethodModel

The authentication method specification and resource specification

Optional[ResourceTypeModel]

for the specified authentication method and resource type.

Raises:

Type Description
KeyError

If the authentication method is not supported by the connector for the specified resource type and ID.

Source code in src/zenml/models/v2/misc/service_connector_type.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
def find_resource_specifications(
    self,
    auth_method: str,
    resource_type: Optional[str] = None,
) -> Tuple[AuthenticationMethodModel, Optional[ResourceTypeModel]]:
    """Find the specifications for a configurable resource.

    Validate the supplied connector configuration parameters against the
    connector specification and return the matching authentication method
    specification and resource specification.

    Args:
        auth_method: The name of the authentication method.
        resource_type: The type of resource being configured.

    Returns:
        The authentication method specification and resource specification
        for the specified authentication method and resource type.

    Raises:
        KeyError: If the authentication method is not supported by the
            connector for the specified resource type and ID.
    """
    # Verify the authentication method
    auth_method_dict = self.auth_method_dict
    if auth_method in auth_method_dict:
        # A match was found for the authentication method
        auth_method_spec = auth_method_dict[auth_method]
    else:
        # No match was found for the authentication method
        raise KeyError(
            f"connector type '{self.connector_type}' does not support the "
            f"'{auth_method}' authentication method. Supported "
            f"authentication methods are: {list(auth_method_dict.keys())}."
        )

    if resource_type is None:
        # No resource type was specified, so no resource type
        # specification can be returned.
        return auth_method_spec, None

    # Verify the resource type
    resource_type_dict = self.resource_type_dict
    if resource_type in resource_type_dict:
        resource_type_spec = resource_type_dict[resource_type]
    else:
        raise KeyError(
            f"connector type '{self.connector_type}' does not support "
            f"resource type '{resource_type}'. Supported resource types "
            f"are: {list(resource_type_dict.keys())}."
        )

    if auth_method not in resource_type_spec.auth_methods:
        raise KeyError(
            f"the '{self.connector_type}' connector type does not support "
            f"the '{auth_method}' authentication method for the "
            f"'{resource_type}' resource type. Supported authentication "
            f"methods are: {resource_type_spec.auth_methods}."
        )

    return auth_method_spec, resource_type_spec
set_connector_class(connector_class: Type[ServiceConnector]) -> None

Set the service connector class.

Parameters:

Name Type Description Default
connector_class Type[ServiceConnector]

The service connector class.

required
Source code in src/zenml/models/v2/misc/service_connector_type.py
321
322
323
324
325
326
327
328
329
def set_connector_class(
    self, connector_class: Type["ServiceConnector"]
) -> None:
    """Set the service connector class.

    Args:
        connector_class: The service connector class.
    """
    self._connector_class = connector_class
validate_auth_methods(values: List[AuthenticationMethodModel]) -> List[AuthenticationMethodModel] classmethod

Validate that the authentication methods are unique.

Parameters:

Name Type Description Default
values List[AuthenticationMethodModel]

The list of authentication methods.

required

Returns:

Type Description
List[AuthenticationMethodModel]

The list of authentication methods.

Raises:

Type Description
ValueError

If two or more authentication method specifications share the same authentication method value.

Source code in src/zenml/models/v2/misc/service_connector_type.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@field_validator("auth_methods")
@classmethod
def validate_auth_methods(
    cls, values: List[AuthenticationMethodModel]
) -> List[AuthenticationMethodModel]:
    """Validate that the authentication methods are unique.

    Args:
        values: The list of authentication methods.

    Returns:
        The list of authentication methods.

    Raises:
        ValueError: If two or more authentication method specifications
            share the same authentication method value.
    """
    # Gather all auth methods from the list of auth method
    # specifications.
    auth_methods = [a.auth_method for a in values]
    if len(auth_methods) != len(set(auth_methods)):
        raise ValueError(
            "Two or more authentication method specifications must not "
            "share the same authentication method value."
        )

    return values
validate_resource_types(values: List[ResourceTypeModel]) -> List[ResourceTypeModel] classmethod

Validate that the resource types are unique.

Parameters:

Name Type Description Default
values List[ResourceTypeModel]

The list of resource types.

required

Returns:

Type Description
List[ResourceTypeModel]

The list of resource types.

Raises:

Type Description
ValueError

If two or more resource type specifications list the same resource type.

Source code in src/zenml/models/v2/misc/service_connector_type.py
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@field_validator("resource_types")
@classmethod
def validate_resource_types(
    cls, values: List[ResourceTypeModel]
) -> List[ResourceTypeModel]:
    """Validate that the resource types are unique.

    Args:
        values: The list of resource types.

    Returns:
        The list of resource types.

    Raises:
        ValueError: If two or more resource type specifications list the
            same resource type.
    """
    # Gather all resource types from the list of resource type
    # specifications.
    resource_types = [r.resource_type for r in values]
    if len(resource_types) != len(set(resource_types)):
        raise ValueError(
            "Two or more resource type specifications must not list "
            "the same resource type."
        )

    return values

ServiceConnectorTypedResourcesModel

Bases: BaseModel

Service connector typed resources list.

Lists the resource instances that a service connector can provide access to.

ServiceConnectorUpdate

Bases: BaseUpdate

Model used for service connector updates.

Most fields in the update model are optional and will not be updated if omitted. However, the following fields are "special" and leaving them out will also cause the corresponding value to be removed from the service connector in the database:

  • the resource_id field
  • the expiration_seconds field

In addition to the above exceptions, the following rules apply:

  • the configuration and secrets fields together represent a full valid configuration update, not just a partial update. If either is set (i.e. not None) in the update, their values are merged together and will replace the existing configuration and secrets values.
  • the secret_id field value in the update is ignored, given that secrets are managed internally by the ZenML store.
  • the labels field is also a full labels update: if set (i.e. not None), all existing labels are removed and replaced by the new labels in the update.

NOTE: the attributes here override the ones in the base class, so they have a None default value.

Attributes
type: Optional[str] property

Get the connector type.

Returns:

Type Description
Optional[str]

The connector type.

Functions
convert_to_request() -> ServiceConnectorRequest

Method to generate a service connector request object from self.

For certain operations, the service connector update model need to adhere to the limitations set by the request model. In order to use update models in such situations, we need to be able to convert an update model into a request model.

Returns:

Type Description
ServiceConnectorRequest

The equivalent request model

Raises:

Type Description
RuntimeError

if the model can not be converted to a request model.

Source code in src/zenml/models/v2/core/service_connector.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def convert_to_request(self) -> "ServiceConnectorRequest":
    """Method to generate a service connector request object from self.

    For certain operations, the service connector update model need to
    adhere to the limitations set by the request model. In order to use
    update models in such situations, we need to be able to convert an
    update model into a request model.

    Returns:
        The equivalent request model

    Raises:
        RuntimeError: if the model can not be converted to a request model.
    """
    try:
        return ServiceConnectorRequest.model_validate(self.model_dump())
    except ValidationError as e:
        raise RuntimeError(
            "The service connector update model can not be converted into "
            f"an equivalent request model: {e}"
        )
get_analytics_metadata() -> Dict[str, Any]

Format the resource types in the analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Format the resource types in the analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    if self.resource_types is not None:
        if len(self.resource_types) == 1:
            metadata["resource_types"] = self.resource_types[0]
        else:
            metadata["resource_types"] = ", ".join(self.resource_types)

    if self.connector_type is not None:
        metadata["connector_type"] = self.type

    return metadata
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )

ServiceFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of services.

The Service needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Services can be scoped by type to narrow the search.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Source code in src/zenml/models/v2/core/service.py
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Services can be scoped by type to narrow the search.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.
    """
    from sqlmodel import and_

    base_filter = super().generate_filter(table)

    if self.type:
        type_filter = getattr(table, "type") == self.type
        base_filter = and_(base_filter, type_filter)

    if self.flavor:
        flavor_filter = getattr(table, "flavor") == self.flavor
        base_filter = and_(base_filter, flavor_filter)

    if self.pipeline_name:
        pipeline_name_filter = (
            getattr(table, "pipeline_name") == self.pipeline_name
        )
        base_filter = and_(base_filter, pipeline_name_filter)

    if self.pipeline_step_name:
        pipeline_step_name_filter = (
            getattr(table, "pipeline_step_name") == self.pipeline_step_name
        )
        base_filter = and_(base_filter, pipeline_step_name_filter)

    return base_filter
set_flavor(flavor: str) -> None

Set the flavor of the service.

Parameters:

Name Type Description Default
flavor str

The flavor of the service.

required
Source code in src/zenml/models/v2/core/service.py
436
437
438
439
440
441
442
def set_flavor(self, flavor: str) -> None:
    """Set the flavor of the service.

    Args:
        flavor: The flavor of the service.
    """
    self.flavor = flavor
set_type(type: str) -> None

Set the type of the service.

Parameters:

Name Type Description Default
type str

The type of the service.

required
Source code in src/zenml/models/v2/core/service.py
428
429
430
431
432
433
434
def set_type(self, type: str) -> None:
    """Set the type of the service.

    Args:
        type: The type of the service.
    """
    self.type = type

ServiceRequest

Bases: WorkspaceScopedRequest

Request model for services.

ServiceResponse

Bases: WorkspaceScopedResponse[ServiceResponseBody, ServiceResponseMetadata, ServiceResponseResources]

Response model for services.

Attributes
admin_state: Optional[ServiceState] property

The admin_state property.

Returns:

Type Description
Optional[ServiceState]

the value of the property.

config: Dict[str, Any] property

The config property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

created: datetime property

The created property.

Returns:

Type Description
datetime

the value of the property.

endpoint: Optional[Dict[str, Any]] property

The endpoint property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

health_check_url: Optional[str] property

The health_check_url property.

Returns:

Type Description
Optional[str]

the value of the property.

labels: Optional[Dict[str, str]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, str]]

the value of the property.

prediction_url: Optional[str] property

The prediction_url property.

Returns:

Type Description
Optional[str]

the value of the property.

service_source: Optional[str] property

The service_source property.

Returns:

Type Description
Optional[str]

the value of the property.

service_type: ServiceType property

The service_type property.

Returns:

Type Description
ServiceType

the value of the property.

state: Optional[ServiceState] property

The state property.

Returns:

Type Description
Optional[ServiceState]

the value of the property.

status: Optional[Dict[str, Any]] property

The status property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_hydrated_version() -> ServiceResponse

Get the hydrated version of this artifact.

Returns:

Type Description
ServiceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service.py
246
247
248
249
250
251
252
253
254
def get_hydrated_version(self) -> "ServiceResponse":
    """Get the hydrated version of this artifact.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service(self.id)

ServiceResponseBody

Bases: WorkspaceScopedResponseBody

Response body for services.

ServiceResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for services.

ServiceResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the service entity.

ServiceUpdate

Bases: BaseModel

Update model for stack components.

StackDeploymentConfig

Bases: BaseModel

Configuration about a stack deployment.

StackDeploymentInfo

Bases: BaseModel

Information about a stack deployment.

StackFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all StackModels.

The Stack Model needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/stack.py
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from zenml.zen_stores.schemas import (
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.component_id:
        component_id_filter = and_(
            StackCompositionSchema.stack_id == StackSchema.id,
            StackCompositionSchema.component_id == self.component_id,
        )
        custom_filters.append(component_id_filter)

    if self.component:
        component_filter = and_(
            StackCompositionSchema.stack_id == StackSchema.id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.component,
                table=StackComponentSchema,
            ),
        )
        custom_filters.append(component_filter)

    return custom_filters

StackRequest

Bases: BaseRequest

Request model for a stack.

Attributes
is_valid: bool property

Check if the stack is valid.

Returns:

Type Description
bool

True if the stack is valid, False otherwise.

StackResponse

Bases: WorkspaceScopedResponse[StackResponseBody, StackResponseMetadata, StackResponseResources]

Response model for stacks.

Attributes
components: Dict[StackComponentType, List[ComponentResponse]] property

The components property.

Returns:

Type Description
Dict[StackComponentType, List[ComponentResponse]]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

is_valid: bool property

Check if the stack is valid.

Returns:

Type Description
bool

True if the stack is valid, False otherwise.

labels: Optional[Dict[str, Any]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

stack_spec_path: Optional[str] property

The stack_spec_path property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the stack components to the stack analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/stack.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the stack components to the stack analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata.update(
        {ct: c[0].flavor_name for ct, c in self.components.items()}
    )

    if self.labels is not None:
        metadata.update(
            {
                label[6:]: value
                for label, value in self.labels.items()
                if label.startswith("zenml:")
            }
        )
    return metadata
get_hydrated_version() -> StackResponse

Get the hydrated version of this stack.

Returns:

Type Description
StackResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/stack.py
209
210
211
212
213
214
215
216
217
def get_hydrated_version(self) -> "StackResponse":
    """Get the hydrated version of this stack.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_stack(self.id)
to_yaml() -> Dict[str, Any]

Create yaml representation of the Stack Model.

Returns:

Type Description
Dict[str, Any]

The yaml representation of the Stack Model.

Source code in src/zenml/models/v2/core/stack.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def to_yaml(self) -> Dict[str, Any]:
    """Create yaml representation of the Stack Model.

    Returns:
        The yaml representation of the Stack Model.
    """
    component_data = {}
    for component_type, components_list in self.components.items():
        component = components_list[0]
        component_dict = dict(
            name=component.name,
            type=str(component.type),
            flavor=component.flavor_name,
        )
        configuration = json.loads(
            component.get_metadata().model_dump_json(
                include={"configuration"}
            )
        )
        component_dict.update(configuration)

        component_data[component_type.value] = component_dict

    # write zenml version and stack dict to YAML
    yaml_data = {
        "stack_name": self.name,
        "components": component_data,
    }

    return yaml_data

StackResponseBody

Bases: WorkspaceScopedResponseBody

Response body for stacks.

StackResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for stacks.

StackUpdate

Bases: BaseUpdate

Update model for stacks.

StepRunFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of step runs.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/step_run.py
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        StepRunSchema,
    )

    if self.model:
        model_filter = and_(
            StepRunSchema.model_version_id == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)
    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id == StepRunSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.STEP_RUN.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters

StepRunRequest

Bases: WorkspaceScopedRequest

Request model for step runs.

StepRunResponse

Bases: WorkspaceScopedResponse[StepRunResponseBody, StepRunResponseMetadata, StepRunResponseResources]

Response model for step runs.

Attributes
cache_key: Optional[str] property

The cache_key property.

Returns:

Type Description
Optional[str]

the value of the property.

code_hash: Optional[str] property

The code_hash property.

Returns:

Type Description
Optional[str]

the value of the property.

config: StepConfiguration property

The config property.

Returns:

Type Description
StepConfiguration

the value of the property.

deployment_id: UUID property

The deployment_id property.

Returns:

Type Description
UUID

the value of the property.

docstring: Optional[str] property

The docstring property.

Returns:

Type Description
Optional[str]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

input: ArtifactVersionResponse property

Returns the input artifact that was used to run this step.

Returns:

Type Description
ArtifactVersionResponse

The input artifact.

Raises:

Type Description
ValueError

If there were zero or multiple inputs to this step.

inputs: Dict[str, StepRunInputResponse] property

The inputs property.

Returns:

Type Description
Dict[str, StepRunInputResponse]

the value of the property.

logs: Optional[LogsResponse] property

The logs property.

Returns:

Type Description
Optional[LogsResponse]

the value of the property.

model_version: Optional[ModelVersionResponse] property

The model_version property.

Returns:

Type Description
Optional[ModelVersionResponse]

the value of the property.

model_version_id: Optional[UUID] property

The model_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

original_step_run_id: Optional[UUID] property

The original_step_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

output: ArtifactVersionResponse property

Returns the output artifact that was written by this step.

Returns:

Type Description
ArtifactVersionResponse

The output artifact.

Raises:

Type Description
ValueError

If there were zero or multiple step outputs.

outputs: Dict[str, List[ArtifactVersionResponse]] property

The outputs property.

Returns:

Type Description
Dict[str, List[ArtifactVersionResponse]]

the value of the property.

parent_step_ids: List[UUID] property

The parent_step_ids property.

Returns:

Type Description
List[UUID]

the value of the property.

pipeline_run_id: UUID property

The pipeline_run_id property.

Returns:

Type Description
UUID

the value of the property.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

source_code: Optional[str] property

The source_code property.

Returns:

Type Description
Optional[str]

the value of the property.

spec: StepSpec property

The spec property.

Returns:

Type Description
StepSpec

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

status: ExecutionStatus property

The status property.

Returns:

Type Description
ExecutionStatus

the value of the property.

Functions
get_hydrated_version() -> StepRunResponse

Get the hydrated version of this step run.

Returns:

Type Description
StepRunResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/step_run.py
291
292
293
294
295
296
297
298
299
def get_hydrated_version(self) -> "StepRunResponse":
    """Get the hydrated version of this step run.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_run_step(self.id)

StepRunResponseBody

Bases: WorkspaceScopedResponseBody

Response body for step runs.

StepRunResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for step runs.

StepRunResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the step run entity.

StepRunUpdate

Bases: BaseModel

Update model for step runs.

StrFilter

Bases: Filter

Filter for all string fields.

Functions
check_value_if_operation_oneof() -> StrFilter

Validator to check if value is a list if oneof operation is used.

Raises:

Type Description
ValueError

If the value is not a list

Returns:

Type Description
StrFilter

self

Source code in src/zenml/models/v2/base/filter.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@model_validator(mode="after")
def check_value_if_operation_oneof(self) -> "StrFilter":
    """Validator to check if value is a list if oneof operation is used.

    Raises:
        ValueError: If the value is not a list

    Returns:
        self
    """
    if self.operation == GenericFilterOps.ONEOF:
        if not isinstance(self.value, list):
            raise ValueError(ONEOF_ERROR)
    return self
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a string column.

Parameters:

Name Type Description Default
column Any

The string column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Raises:

Type Description
ValueError

the comparison of the column to a numeric value fails.

Source code in src/zenml/models/v2/base/filter.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a string column.

    Args:
        column: The string column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.

    Raises:
        ValueError: the comparison of the column to a numeric value fails.
    """
    if self.operation in {
        GenericFilterOps.GT,
        GenericFilterOps.LT,
        GenericFilterOps.GTE,
        GenericFilterOps.LTE,
    }:
        try:
            numeric_column = cast(column, Float)

            assert self.value is not None

            if self.operation == GenericFilterOps.GT:
                return and_(
                    numeric_column, numeric_column > float(self.value)
                )
            if self.operation == GenericFilterOps.LT:
                return and_(
                    numeric_column, numeric_column < float(self.value)
                )
            if self.operation == GenericFilterOps.GTE:
                return and_(
                    numeric_column, numeric_column >= float(self.value)
                )
            if self.operation == GenericFilterOps.LTE:
                return and_(
                    numeric_column, numeric_column <= float(self.value)
                )
        except Exception as e:
            raise ValueError(
                f"Failed to compare the column '{column}' to the "
                f"value '{self.value}' (must be numeric): {e}"
            )

    if self.operation == GenericFilterOps.ONEOF:
        assert isinstance(self.value, list)
        # Convert the list of values to a list of json strings
        json_list = (
            [json.dumps(v) for v in self.value]
            if self.json_encode_value
            else self.value
        )
        return column.in_(json_list)

    # Don't convert the value to a json string if the operation is contains
    # because the quotes around strings will mess with the comparison
    if self.operation == GenericFilterOps.CONTAINS:
        return column.like(f"%{self.value}%")

    json_value = (
        json.dumps(self.value) if self.json_encode_value else self.value
    )

    if self.operation == GenericFilterOps.STARTSWITH:
        return column.startswith(f"{json_value}")
    if self.operation == GenericFilterOps.ENDSWITH:
        return column.endswith(f"{json_value}")
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != json_value

    return column == json_value

TagFilter

Bases: BaseFilter

Model to enable advanced filtering of all tags.

TagRequest

Bases: BaseRequest

Request model for tags.

TagResourceRequest

Bases: BaseRequest

Request model for links between tags and resources.

TagResourceResponse

Bases: BaseIdentifiedResponse[TagResourceResponseBody, BaseResponseMetadata, TagResourceResponseResources]

Response model for the links between tags and resources.

Attributes
resource_id: UUID property

The resource_id property.

Returns:

Type Description
UUID

the value of the property.

resource_type: TaggableResourceTypes property

The resource_type property.

Returns:

Type Description
TaggableResourceTypes

the value of the property.

tag_id: UUID property

The tag_id property.

Returns:

Type Description
UUID

the value of the property.

TagResourceResponseBody

Bases: BaseDatedResponseBody

Response body for the links between tags and resources.

TagResponse

Bases: BaseIdentifiedResponse[TagResponseBody, BaseResponseMetadata, TagResponseResources]

Response model for tags.

Attributes
color: ColorVariants property

The color property.

Returns:

Type Description
ColorVariants

the value of the property.

tagged_count: int property

The tagged_count property.

Returns:

Type Description
int

the value of the property.

Functions
get_hydrated_version() -> TagResponse

Get the hydrated version of this tag.

Returns:

Type Description
TagResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/tag.py
89
90
91
92
93
94
95
96
97
def get_hydrated_version(self) -> "TagResponse":
    """Get the hydrated version of this tag.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_tag(self.id)

TagResponseBody

Bases: BaseDatedResponseBody

Response body for tags.

TagUpdate

Bases: BaseModel

Update model for tags.

TaggableFilter

Bases: BaseFilter

Model to enable filtering and sorting by tags.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    from zenml.zen_stores.schemas import TagResourceSchema, TagSchema

    query = super().apply_filter(query=query, table=table)
    if self.tag:
        query = query.join(
            TagResourceSchema,
            TagResourceSchema.resource_id == getattr(table, "id"),
        ).join(TagSchema, TagSchema.id == TagResourceSchema.tag_id)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    sort_by, operand = self.sorting_params

    if sort_by == "tags":
        from sqlmodel import asc, desc, func, select

        from zenml.enums import SorterOps, TaggableResourceTypes
        from zenml.zen_stores.schemas import (
            ArtifactSchema,
            ArtifactVersionSchema,
            ModelSchema,
            ModelVersionSchema,
            PipelineRunSchema,
            PipelineSchema,
            RunTemplateSchema,
            TagResourceSchema,
            TagSchema,
        )

        resource_type_mapping = {
            ArtifactSchema: TaggableResourceTypes.ARTIFACT,
            ArtifactVersionSchema: TaggableResourceTypes.ARTIFACT_VERSION,
            ModelSchema: TaggableResourceTypes.MODEL,
            ModelVersionSchema: TaggableResourceTypes.MODEL_VERSION,
            PipelineSchema: TaggableResourceTypes.PIPELINE,
            PipelineRunSchema: TaggableResourceTypes.PIPELINE_RUN,
            RunTemplateSchema: TaggableResourceTypes.RUN_TEMPLATE,
        }

        sorted_tags = (
            select(TagResourceSchema.resource_id, TagSchema.name)
            .join(TagSchema, TagResourceSchema.tag_id == TagSchema.id)  # type: ignore[arg-type]
            .filter(
                TagResourceSchema.resource_type  # type: ignore[arg-type]
                == resource_type_mapping[table]
            )
            .order_by(
                asc(TagResourceSchema.resource_id), asc(TagSchema.name)
            )
        ).alias("sorted_tags")

        tags_subquery = (
            select(
                sorted_tags.c.resource_id,
                func.group_concat(sorted_tags.c.name, ", ").label(
                    "tags_list"
                ),
            ).group_by(sorted_tags.c.resource_id)
        ).alias("tags_subquery")

        query = query.add_columns(tags_subquery.c.tags_list).outerjoin(
            tags_subquery, table.id == tags_subquery.c.resource_id
        )

        # Apply ordering based on the tags list
        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc("tags_list"))
        else:
            query = query.order_by(desc("tags_list"))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom tag filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom tag filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    from zenml.zen_stores.schemas import TagSchema

    custom_filters = super().get_custom_filters(table)
    if self.tag:
        custom_filters.append(
            self.generate_custom_query_conditions_for_column(
                value=self.tag, table=TagSchema, column="name"
            )
        )

    return custom_filters

TriggerExecutionFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all trigger executions.

TriggerExecutionRequest

Bases: BaseRequest

Model for creating a new Trigger execution.

TriggerExecutionResponse

Bases: BaseIdentifiedResponse[TriggerExecutionResponseBody, TriggerExecutionResponseMetadata, TriggerExecutionResponseResources]

Response model for trigger executions.

Attributes
event_metadata: Dict[str, Any] property

The event_metadata property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

trigger: TriggerResponse property

The trigger property.

Returns:

Type Description
TriggerResponse

the value of the property.

Functions
get_hydrated_version() -> TriggerExecutionResponse

Get the hydrated version of this trigger execution.

Returns:

Type Description
TriggerExecutionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/trigger_execution.py
78
79
80
81
82
83
84
85
86
def get_hydrated_version(self) -> "TriggerExecutionResponse":
    """Get the hydrated version of this trigger execution.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_trigger_execution(self.id)

TriggerExecutionResponseBody

Bases: BaseDatedResponseBody

Response body for trigger executions.

TriggerExecutionResponseMetadata

Bases: BaseResponseMetadata

Response metadata for trigger executions.

TriggerExecutionResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the trigger entity.

TriggerFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all triggers.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/trigger.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ActionSchema,
        EventSourceSchema,
        TriggerSchema,
    )

    custom_filters = super().get_custom_filters(table)

    if self.event_source_flavor:
        event_source_flavor_filter = and_(
            EventSourceSchema.id == TriggerSchema.event_source_id,
            EventSourceSchema.flavor == self.event_source_flavor,
        )
        custom_filters.append(event_source_flavor_filter)

    if self.event_source_subtype:
        event_source_subtype_filter = and_(
            EventSourceSchema.id == TriggerSchema.event_source_id,
            EventSourceSchema.plugin_subtype == self.event_source_subtype,
        )
        custom_filters.append(event_source_subtype_filter)

    if self.action_flavor:
        action_flavor_filter = and_(
            ActionSchema.id == TriggerSchema.action_id,
            ActionSchema.flavor == self.action_flavor,
        )
        custom_filters.append(action_flavor_filter)

    if self.action_subtype:
        action_subtype_filter = and_(
            ActionSchema.id == TriggerSchema.action_id,
            ActionSchema.plugin_subtype == self.action_subtype,
        )
        custom_filters.append(action_subtype_filter)

    return custom_filters

TriggerRequest

Bases: WorkspaceScopedRequest

Model for creating a new trigger.

TriggerResponse

Bases: WorkspaceScopedResponse[TriggerResponseBody, TriggerResponseMetadata, TriggerResponseResources]

Response model for models.

Attributes
action: ActionResponse property

The action property.

Returns:

Type Description
ActionResponse

the value of the property.

action_flavor: str property

The action_flavor property.

Returns:

Type Description
str

the value of the property.

action_subtype: str property

The action_subtype property.

Returns:

Type Description
str

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

event_filter: Optional[Dict[str, Any]] property

The event_filter property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

event_source: Optional[EventSourceResponse] property

The event_source property.

Returns:

Type Description
Optional[EventSourceResponse]

the value of the property.

event_source_flavor: Optional[str] property

The event_source_flavor property.

Returns:

Type Description
Optional[str]

the value of the property.

event_source_subtype: Optional[str] property

The event_source_subtype property.

Returns:

Type Description
Optional[str]

the value of the property.

executions: Page[TriggerExecutionResponse] property

The event_source property.

Returns:

Type Description
Page[TriggerExecutionResponse]

the value of the property.

is_active: bool property

The is_active property.

Returns:

Type Description
bool

the value of the property.

Functions
get_hydrated_version() -> TriggerResponse

Get the hydrated version of this trigger.

Returns:

Type Description
TriggerResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/trigger.py
223
224
225
226
227
228
229
230
231
def get_hydrated_version(self) -> "TriggerResponse":
    """Get the hydrated version of this trigger.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_trigger(self.id)

TriggerResponseBody

Bases: WorkspaceScopedResponseBody

Response body for triggers.

TriggerResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for triggers.

TriggerResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the trigger entity.

TriggerUpdate

Bases: BaseUpdate

Update model for triggers.

UUIDFilter

Bases: StrFilter

Filter for all uuid fields which are mostly treated like strings.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a UUID column.

Parameters:

Name Type Description Default
column Any

The UUID column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a UUID column.

    Args:
        column: The UUID column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    import sqlalchemy
    from sqlalchemy_utils.functions import cast_if

    from zenml.utils import uuid_utils

    # For equality checks, compare the UUID directly
    if self.operation == GenericFilterOps.EQUALS:
        if not uuid_utils.is_valid_uuid(self.value):
            return False

        return column == self.value

    if self.operation == GenericFilterOps.NOT_EQUALS:
        if not uuid_utils.is_valid_uuid(self.value):
            return True

        return column != self.value

    # For all other operations, cast and handle the column as string
    return super().generate_query_conditions_from_column(
        column=cast_if(column, sqlalchemy.String)
    )

UserAuthModel

Bases: BaseZenModel

Authentication Model for the User.

This model is only used server-side. The server endpoints can use this model to authenticate the user credentials (Token, Password).

Functions
get_hashed_activation_token() -> Optional[str]

Returns the hashed activation token, if configured.

Returns:

Type Description
Optional[str]

The hashed activation token.

Source code in src/zenml/models/v2/misc/user_auth.py
139
140
141
142
143
144
145
def get_hashed_activation_token(self) -> Optional[str]:
    """Returns the hashed activation token, if configured.

    Returns:
        The hashed activation token.
    """
    return self._get_hashed_secret(self.activation_token)
get_hashed_password() -> Optional[str]

Returns the hashed password, if configured.

Returns:

Type Description
Optional[str]

The hashed password.

Source code in src/zenml/models/v2/misc/user_auth.py
131
132
133
134
135
136
137
def get_hashed_password(self) -> Optional[str]:
    """Returns the hashed password, if configured.

    Returns:
        The hashed password.
    """
    return self._get_hashed_secret(self.password)
get_password() -> Optional[str]

Get the password.

Returns:

Type Description
Optional[str]

The password as a plain string, if it exists.

Source code in src/zenml/models/v2/misc/user_auth.py
121
122
123
124
125
126
127
128
129
def get_password(self) -> Optional[str]:
    """Get the password.

    Returns:
        The password as a plain string, if it exists.
    """
    if self.password is None:
        return None
    return self.password.get_secret_value()
verify_activation_token(activation_token: str, user: Optional[UserAuthModel] = None) -> bool classmethod

Verifies a given activation token against the stored token.

Parameters:

Name Type Description Default
activation_token str

Input activation token to be verified.

required
user Optional[UserAuthModel]

User for which the activation token is to be verified.

None

Returns:

Type Description
bool

True if the token is valid.

Source code in src/zenml/models/v2/misc/user_auth.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@classmethod
def verify_activation_token(
    cls, activation_token: str, user: Optional["UserAuthModel"] = None
) -> bool:
    """Verifies a given activation token against the stored token.

    Args:
        activation_token: Input activation token to be verified.
        user: User for which the activation token is to be verified.

    Returns:
        True if the token is valid.
    """
    # even when the user or token is not set, we still want to execute the
    # token hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    token_hash: str = ""
    if (
        user is not None
        # Disable activation tokens for service accounts as an extra
        # security measure. Service accounts should only be used with API
        # keys.
        and not user.is_service_account
        and user.activation_token is not None
        and not user.active
    ):
        token_hash = user.get_hashed_activation_token() or ""
    pwd_context = cls._get_crypt_context()
    return pwd_context.verify(activation_token, token_hash)
verify_password(plain_password: str, user: Optional[UserAuthModel] = None) -> bool classmethod

Verifies a given plain password against the stored password.

Parameters:

Name Type Description Default
plain_password str

Input password to be verified.

required
user Optional[UserAuthModel]

User for which the password is to be verified.

None

Returns:

Type Description
bool

True if the passwords match.

Source code in src/zenml/models/v2/misc/user_auth.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@classmethod
def verify_password(
    cls, plain_password: str, user: Optional["UserAuthModel"] = None
) -> bool:
    """Verifies a given plain password against the stored password.

    Args:
        plain_password: Input password to be verified.
        user: User for which the password is to be verified.

    Returns:
        True if the passwords match.
    """
    # even when the user or password is not set, we still want to execute
    # the password hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    password_hash: Optional[str] = None
    if (
        user is not None
        # Disable password verification for service accounts as an extra
        # security measure. Service accounts should only be used with API
        # keys.
        and not user.is_service_account
        and user.password is not None
    ):  # and user.active:
        password_hash = user.get_hashed_password()
    pwd_context = cls._get_crypt_context()
    return pwd_context.verify(plain_password, password_hash)

UserFilter

Bases: BaseFilter

Model to enable advanced filtering of all Users.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to filter out service accounts from the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/user.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to filter out service accounts from the query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)
    query = query.where(
        getattr(table, "is_service_account") != True  # noqa: E712
    )

    return query

UserRequest

Bases: UserBase, BaseRequest

Request model for users.

UserResponse

Bases: BaseIdentifiedResponse[UserResponseBody, UserResponseMetadata, UserResponseResources]

Response model for user and service accounts.

This returns the activation_token that is required for the user-invitation-flow of the frontend. The email is returned optionally as well for use by the analytics on the client-side.

Attributes
activation_token: Optional[str] property

The activation_token property.

Returns:

Type Description
Optional[str]

the value of the property.

active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

email: Optional[str] property

The email property.

Returns:

Type Description
Optional[str]

the value of the property.

email_opted_in: Optional[bool] property

The email_opted_in property.

Returns:

Type Description
Optional[bool]

the value of the property.

external_user_id: Optional[UUID] property

The external_user_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

full_name: str property

The full_name property.

Returns:

Type Description
str

the value of the property.

is_admin: bool property

The is_admin property.

Returns:

Type Description
bool

Whether the user is an admin.

is_service_account: bool property

The is_service_account property.

Returns:

Type Description
bool

the value of the property.

user_metadata: Dict[str, Any] property

The user_metadata property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

Functions
get_hydrated_version() -> UserResponse

Get the hydrated version of this user.

Returns:

Type Description
UserResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/user.py
333
334
335
336
337
338
339
340
341
def get_hydrated_version(self) -> "UserResponse":
    """Get the hydrated version of this user.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_user(self.id)

UserResponseBody

Bases: BaseDatedResponseBody

Response body for users.

UserResponseMetadata

Bases: BaseResponseMetadata

Response metadata for users.

UserScopedFilter

Bases: BaseFilter

Model to enable advanced user-based scoping.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self.scope_user:
        query = query.where(getattr(table, "user_id") == self.scope_user)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import UserSchema

    sort_by, operand = self.sorting_params

    if sort_by == "user":
        column = UserSchema.name

        query = query.outerjoin(
            UserSchema,
            getattr(table, "user_id") == UserSchema.id,
        )

        query = query.add_columns(UserSchema.name)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc(column))
        else:
            query = query.order_by(desc(column))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import UserSchema

    if self.user:
        user_filter = and_(
            getattr(table, "user_id") == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters
set_scope_user(user_id: UUID) -> None

Set the user that is performing the filtering to scope the response.

Parameters:

Name Type Description Default
user_id UUID

The user ID to scope the response to.

required
Source code in src/zenml/models/v2/base/scoped.py
182
183
184
185
186
187
188
def set_scope_user(self, user_id: UUID) -> None:
    """Set the user that is performing the filtering to scope the response.

    Args:
        user_id: The user ID to scope the response to.
    """
    self.scope_user = user_id

UserScopedRequest

Bases: BaseRequest

Base user-owned request model.

Used as a base class for all domain models that are "owned" by a user.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for user scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
61
62
63
64
65
66
67
68
69
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for user scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["user_id"] = self.user
    return metadata

UserScopedResponse

Bases: BaseIdentifiedResponse[UserBody, UserMetadata, UserResources], Generic[UserBody, UserMetadata, UserResources]

Base user-owned model.

Used as a base class for all domain models that are "owned" by a user.

Attributes
user: Optional[UserResponse] property

The user property.

Returns:

Type Description
Optional[UserResponse]

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for user scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
128
129
130
131
132
133
134
135
136
137
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for user scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    if self.user is not None:
        metadata["user_id"] = self.user.id
    return metadata

UserScopedResponseBody

Bases: BaseDatedResponseBody

Base user-owned body.

UserScopedResponseMetadata

Bases: BaseResponseMetadata

Base user-owned metadata.

UserUpdate

Bases: UserBase, BaseZenModel

Update model for users.

Functions
create_copy(exclude: AbstractSet[str]) -> UserUpdate

Create a copy of the current instance.

Parameters:

Name Type Description Default
exclude AbstractSet[str]

Fields to exclude from the copy.

required

Returns:

Type Description
UserUpdate

A copy of the current instance.

Source code in src/zenml/models/v2/core/user.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def create_copy(self, exclude: AbstractSet[str]) -> "UserUpdate":
    """Create a copy of the current instance.

    Args:
        exclude: Fields to exclude from the copy.

    Returns:
        A copy of the current instance.
    """
    return UserUpdate(
        **self.model_dump(
            exclude=set(exclude),
            exclude_unset=True,
        )
    )
user_email_updates() -> UserUpdate

Validate that the UserUpdateModel conforms to the email-opt-in-flow.

Returns:

Type Description
UserUpdate

The validated values.

Raises:

Type Description
ValueError

If the email was not provided when the email_opted_in field was set to True.

Source code in src/zenml/models/v2/core/user.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
@model_validator(mode="after")
def user_email_updates(self) -> "UserUpdate":
    """Validate that the UserUpdateModel conforms to the email-opt-in-flow.

    Returns:
        The validated values.

    Raises:
        ValueError: If the email was not provided when the email_opted_in
            field was set to True.
    """
    # When someone sets the email, or updates the email and hasn't
    #  before explicitly opted out, they are opted in
    if self.email is not None:
        if self.email_opted_in is None:
            self.email_opted_in = True

    # It should not be possible to do opt in without an email
    if self.email_opted_in is True:
        if self.email is None:
            raise ValueError(
                "Please provide an email, when you are opting-in with "
                "your email."
            )
    return self

WorkspaceFilter

Bases: BaseFilter

Model to enable advanced filtering of all Workspaces.

WorkspaceRequest

Bases: BaseRequest

Request model for workspaces.

WorkspaceResponse

Bases: BaseIdentifiedResponse[WorkspaceResponseBody, WorkspaceResponseMetadata, WorkspaceResponseResources]

Response model for workspaces.

Attributes
description: str property

The description property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> WorkspaceResponse

Get the hydrated version of this workspace.

Returns:

Type Description
WorkspaceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/workspace.py
101
102
103
104
105
106
107
108
109
def get_hydrated_version(self) -> "WorkspaceResponse":
    """Get the hydrated version of this workspace.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_workspace(self.id)

WorkspaceResponseBody

Bases: BaseDatedResponseBody

Response body for workspaces.

WorkspaceResponseMetadata

Bases: BaseResponseMetadata

Response metadata for workspaces.

WorkspaceScopedFilter

Bases: UserScopedFilter

Model to enable advanced scoping with workspace.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    from sqlmodel import or_

    query = super().apply_filter(query=query, table=table)

    if self.scope_workspace:
        scope_filter = or_(
            getattr(table, "workspace_id") == self.scope_workspace,
            getattr(table, "workspace_id").is_(None),
        )
        query = query.where(scope_filter)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import WorkspaceSchema

    sort_by, operand = self.sorting_params

    if sort_by == "workspace":
        column = WorkspaceSchema.name

        query = query.join(
            WorkspaceSchema,
            getattr(table, "workspace_id") == WorkspaceSchema.id,
        )

        query = query.add_columns(WorkspaceSchema.name)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc(column))
        else:
            query = query.order_by(desc(column))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import WorkspaceSchema

    if self.workspace:
        workspace_filter = and_(
            getattr(table, "workspace_id") == WorkspaceSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.workspace,
                table=WorkspaceSchema,
            ),
        )
        custom_filters.append(workspace_filter)

    return custom_filters
set_scope_workspace(workspace_id: UUID) -> None

Set the workspace to scope this response.

Parameters:

Name Type Description Default
workspace_id UUID

The workspace to scope this response to.

required
Source code in src/zenml/models/v2/base/scoped.py
362
363
364
365
366
367
368
def set_scope_workspace(self, workspace_id: UUID) -> None:
    """Set the workspace to scope this response.

    Args:
        workspace_id: The workspace to scope this response to.
    """
    self.scope_workspace = workspace_id

WorkspaceScopedRequest

Bases: UserScopedRequest

Base workspace-scoped request domain model.

Used as a base class for all domain models that are workspace-scoped.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for workspace scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
82
83
84
85
86
87
88
89
90
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for workspace scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["workspace_id"] = self.workspace
    return metadata

WorkspaceScopedResponse

Bases: UserScopedResponse[WorkspaceBody, WorkspaceMetadata, WorkspaceResources], Generic[WorkspaceBody, WorkspaceMetadata, WorkspaceResources]

Base workspace-scoped domain model.

Used as a base class for all domain models that are workspace-scoped.

Attributes
workspace: WorkspaceResponse property

The workspace property.

Returns:

Type Description
WorkspaceResponse

the value of the property.

WorkspaceScopedResponseBody

Bases: UserScopedResponseBody

Base workspace-scoped body.

WorkspaceScopedResponseMetadata

Bases: UserScopedResponseMetadata

Base workspace-scoped metadata.

WorkspaceScopedResponseResources

Bases: UserScopedResponseResources

Base workspace-scoped resources.

WorkspaceUpdate

Bases: BaseUpdate

Update model for workspaces.

Modules

v2

Modules
base
Modules
base

Base model definitions.

Classes
BaseDatedResponseBody

Bases: BaseResponseBody

Base body model for entities that track a creation and update timestamp.

Used as a base class for all body models associated with responses. Features a creation and update timestamp.

BaseIdentifiedResponse

Bases: BaseResponse[AnyDatedBody, AnyMetadata, AnyResources], Generic[AnyDatedBody, AnyMetadata, AnyResources]

Base domain model for resources with DB representation.

Attributes
created: datetime property

The created property.

Returns:

Type Description
datetime

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for base response models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/base.py
457
458
459
460
461
462
463
464
465
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for base response models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["entity_id"] = self.id
    return metadata
get_body() -> AnyDatedBody

Fetch the body of the entity.

Returns:

Type Description
AnyDatedBody

The body field of the response.

Raises:

Type Description
IllegalOperationError

If the user lacks permission to access the entity represented by this response.

Source code in src/zenml/models/v2/base/base.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
def get_body(self) -> "AnyDatedBody":
    """Fetch the body of the entity.

    Returns:
        The body field of the response.

    Raises:
        IllegalOperationError: If the user lacks permission to access the
            entity represented by this response.
    """
    if self.permission_denied:
        raise IllegalOperationError(
            f"Missing permissions to access {type(self).__name__} with "
            f"ID {self.id}."
        )

    return super().get_body()
get_hydrated_version() -> BaseIdentifiedResponse[AnyDatedBody, AnyMetadata, AnyResources]

Abstract method to fetch the hydrated version of the model.

Raises:

Type Description
NotImplementedError

in case the method is not implemented.

Source code in src/zenml/models/v2/base/base.py
407
408
409
410
411
412
413
414
415
416
417
418
def get_hydrated_version(
    self,
) -> "BaseIdentifiedResponse[AnyDatedBody, AnyMetadata, AnyResources]":
    """Abstract method to fetch the hydrated version of the model.

    Raises:
        NotImplementedError: in case the method is not implemented.
    """
    raise NotImplementedError(
        "Please implement a `get_hydrated_version` method before "
        "using/hydrating the model."
    )
get_metadata() -> AnyMetadata

Fetch the metadata of the entity.

Returns:

Type Description
AnyMetadata

The metadata field of the response.

Raises:

Type Description
IllegalOperationError

If the user lacks permission to access this entity represented by this response.

Source code in src/zenml/models/v2/base/base.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
def get_metadata(self) -> "AnyMetadata":
    """Fetch the metadata of the entity.

    Returns:
        The metadata field of the response.

    Raises:
        IllegalOperationError: If the user lacks permission to access this
            entity represented by this response.
    """
    if self.permission_denied:
        raise IllegalOperationError(
            f"Missing permissions to access {type(self).__name__} with "
            f"ID {self.id}."
        )

    return super().get_metadata()
BaseRequest

Bases: BaseZenModel

Base request model.

Used as a base class for all request models.

BaseResponse

Bases: BaseZenModel, Generic[AnyBody, AnyMetadata, AnyResources]

Base domain model for all responses.

Functions
get_body() -> AnyBody

Fetch the body of the entity.

Returns:

Type Description
AnyBody

The body field of the response.

Raises:

Type Description
RuntimeError

If the body was not included in the response.

Source code in src/zenml/models/v2/base/base.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def get_body(self) -> "AnyBody":
    """Fetch the body of the entity.

    Returns:
        The body field of the response.

    Raises:
        RuntimeError: If the body was not included in the response.
    """
    if not self.body:
        raise RuntimeError(
            f"Missing response body for {type(self).__name__}."
        )

    return self.body
get_hydrated_version() -> BaseResponse[AnyBody, AnyMetadata, AnyResources]

Abstract method to fetch the hydrated version of the model.

Raises:

Type Description
NotImplementedError

in case the method is not implemented.

Source code in src/zenml/models/v2/base/base.py
226
227
228
229
230
231
232
233
234
235
236
237
def get_hydrated_version(
    self,
) -> "BaseResponse[AnyBody, AnyMetadata, AnyResources]":
    """Abstract method to fetch the hydrated version of the model.

    Raises:
        NotImplementedError: in case the method is not implemented.
    """
    raise NotImplementedError(
        "Please implement a `get_hydrated_version` method before "
        "using/hydrating the model."
    )
get_metadata() -> AnyMetadata

Fetch the metadata of the entity.

Returns:

Type Description
AnyMetadata

The metadata field of the response.

Source code in src/zenml/models/v2/base/base.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
def get_metadata(self) -> "AnyMetadata":
    """Fetch the metadata of the entity.

    Returns:
        The metadata field of the response.
    """
    if self.metadata is None:
        # If the metadata is not there, check the class first.
        metadata_annotation = self.model_fields["metadata"].annotation
        assert metadata_annotation is not None, (
            "For each response model, an annotated metadata"
            "field should exist."
        )

        # metadata is defined as:
        #   metadata: Optional[....ResponseMetadata] = Field(default=None)
        # We need to find the actual class inside the Optional annotation.
        from zenml.utils.typing_utils import get_args

        metadata_type = get_args(metadata_annotation)[0]
        assert issubclass(metadata_type, BaseResponseMetadata)

        if len(metadata_type.model_fields):
            # If the metadata class defines any fields, fetch the metadata
            # through the hydrated version.
            self.hydrate()
        else:
            # Otherwise, use the metadata class to create an empty metadata
            # object.
            self.metadata = metadata_type()

    assert self.metadata is not None

    return self.metadata
get_resources() -> AnyResources

Fetch the resources related to this entity.

Returns:

Type Description
AnyResources

The resources field of the response.

Raises:

Type Description
RuntimeError

If the resources field was not included in the response.

Source code in src/zenml/models/v2/base/base.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def get_resources(self) -> "AnyResources":
    """Fetch the resources related to this entity.

    Returns:
        The resources field of the response.

    Raises:
        RuntimeError: If the resources field was not included in the response.
    """
    if self.resources is None:
        # If the resources are not there, check the class first.
        resources_annotation = self.model_fields["resources"].annotation
        assert resources_annotation is not None, (
            "For each response model, an annotated resources"
            "field should exist."
        )

        # resources is defined as:
        #   resources: Optional[....ResponseResources] = Field(default=None)
        # We need to find the actual class inside the Optional annotation.
        from zenml.utils.typing_utils import get_args

        resources_type = get_args(resources_annotation)[0]
        assert issubclass(resources_type, BaseResponseResources)

        if len(resources_type.model_fields):
            # If the resources class defines any fields, fetch the resources
            # through the hydrated version.
            self.hydrate()
        else:
            # Otherwise, use the resources class to create an empty
            # resources object.
            self.resources = resources_type()

    if self.resources is None:
        raise RuntimeError(
            f"Missing response resources for {type(self).__name__}."
        )

    return self.resources
hydrate() -> None

Hydrate the response.

Source code in src/zenml/models/v2/base/base.py
218
219
220
221
222
223
224
def hydrate(self) -> None:
    """Hydrate the response."""
    hydrated_version = self.get_hydrated_version()
    self._validate_hydrated_version(hydrated_version)

    self.resources = hydrated_version.resources
    self.metadata = hydrated_version.metadata
BaseResponseBody

Bases: BaseZenModel

Base body model.

BaseResponseMetadata

Bases: BaseZenModel

Base metadata model.

Used as a base class for all metadata models associated with responses.

BaseResponseResources

Bases: BaseZenModel

Base resources model.

Used as a base class for all resource models associated with responses.

BaseUpdate

Bases: BaseZenModel

Base update model.

Used as a base class for all update models.

BaseZenModel

Bases: YAMLSerializationMixin, AnalyticsTrackedModelMixin

Base model class for all ZenML models.

This class is used as a base class for all ZenML models. It provides functionality for tracking analytics events.

Functions
base_plugin_flavor

Plugin flavor model definitions.

Classes
BasePluginFlavorResponse

Bases: BaseResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources], Generic[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Base response for all Plugin Flavors.

Functions
get_hydrated_version() -> BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Abstract method to fetch the hydrated version of the model.

Returns:

Type Description
BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]

Hydrated version of the PluginFlavorResponse

Source code in src/zenml/models/v2/base/base_plugin_flavor.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def get_hydrated_version(
    self,
) -> "BasePluginFlavorResponse[AnyPluginBody, AnyPluginMetadata, AnyPluginResources]":
    """Abstract method to fetch the hydrated version of the model.

    Returns:
        Hydrated version of the PluginFlavorResponse
    """
    # TODO: shouldn't this call the Zen store ? The client should not have
    #  to know about the plugin flavor registry
    from zenml.zen_server.utils import plugin_flavor_registry

    plugin_flavor = plugin_flavor_registry().get_flavor_class(
        name=self.name, _type=self.type, subtype=self.subtype
    )
    return plugin_flavor.get_flavor_response_model(hydrate=True)
BasePluginResponseBody

Bases: BaseResponseBody

Response body for plugins.

BasePluginResponseMetadata

Bases: BaseResponseMetadata

Response metadata for plugins.

BasePluginResponseResources

Bases: BaseResponseResources

Response resources for plugins.

filter

Base filter model definitions.

Classes
BaseFilter

Bases: BaseModel

Class to unify all filter, paginate and sort request parameters.

This Model allows fine-grained filtering, sorting and pagination of resources.

Usage example for subclasses of this class:

ResourceListModel(
    name="contains:default",
    workspace="default"
    count_steps="gte:5"
    sort_by="created",
    page=2,
    size=20
)
Attributes
list_of_filters: List[Filter] property

Converts the class variables into a list of usable Filter Models.

Returns:

Type Description
List[Filter]

A list of Filter models.

offset: int property

Returns the offset needed for the query on the data persistence layer.

Returns:

Type Description
int

The offset for the query.

sorting_params: Tuple[str, SorterOps] property

Converts the class variables into a list of usable Filter Models.

Returns:

Type Description
Tuple[str, SorterOps]

A tuple of the column to sort by and the sorting operand.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/filter.py
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    rbac_filter = self.generate_rbac_filter(table=table)

    if rbac_filter is not None:
        query = query.where(rbac_filter)

    filters = self.generate_filter(table=table)

    if filters is not None:
        query = query.where(filters)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/filter.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    column, operand = self.sorting_params

    if operand == SorterOps.DESCENDING:
        sort_clause = desc(getattr(table, column))  # type: ignore[var-annotated]
    else:
        sort_clause = asc(getattr(table, column))

    # We always add the `id` column as a tiebreaker to ensure a stable,
    # repeatable order of items, otherwise subsequent pages might contain
    # the same items.
    query = query.order_by(sort_clause, asc(table.id))  # type: ignore[arg-type]

    return query
configure_rbac(authenticated_user_id: UUID, **column_allowed_ids: Optional[Set[UUID]]) -> None

Configure RBAC allowed column values.

Parameters:

Name Type Description Default
authenticated_user_id UUID

ID of the authenticated user. All entities owned by this user will be included.

required
column_allowed_ids Optional[Set[UUID]]

Set of IDs per column to limit the query to. If given, the remaining filters will be applied to entities within this set only. If None, the remaining filters will be applied to all entries in the table.

{}
Source code in src/zenml/models/v2/base/filter.py
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
def configure_rbac(
    self,
    authenticated_user_id: UUID,
    **column_allowed_ids: Optional[Set[UUID]],
) -> None:
    """Configure RBAC allowed column values.

    Args:
        authenticated_user_id: ID of the authenticated user. All entities
            owned by this user will be included.
        column_allowed_ids: Set of IDs per column to limit the query to.
            If given, the remaining filters will be applied to entities
            within this set only. If `None`, the remaining filters will
            be applied to all entries in the table.
    """
    self._rbac_configuration = (authenticated_user_id, column_allowed_ids)
filter_ops(data: Dict[str, Any]) -> Dict[str, Any] classmethod

Parse incoming filters to ensure all filters are legal.

Parameters:

Name Type Description Default
data Dict[str, Any]

The values of the class.

required

Returns:

Type Description
Dict[str, Any]

The values of the class.

Source code in src/zenml/models/v2/base/filter.py
532
533
534
535
536
537
538
539
540
541
542
543
544
545
@model_validator(mode="before")
@classmethod
@before_validator_handler
def filter_ops(cls, data: Dict[str, Any]) -> Dict[str, Any]:
    """Parse incoming filters to ensure all filters are legal.

    Args:
        data: The values of the class.

    Returns:
        The values of the class.
    """
    cls._generate_filter_list(data)
    return data
generate_custom_query_conditions_for_column(value: Any, table: Type[SQLModel], column: str, json_encode_value: bool = False) -> ColumnElement[bool] staticmethod

Generate custom filter conditions for a column of a table.

Parameters:

Name Type Description Default
value Any

The filter value.

required
table Type[SQLModel]

The table which contains the column.

required
column str

The column name.

required
json_encode_value bool

Whether to json encode the value.

False

Returns:

Type Description
ColumnElement[bool]

The query conditions.

Source code in src/zenml/models/v2/base/filter.py
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
@staticmethod
def generate_custom_query_conditions_for_column(
    value: Any,
    table: Type[SQLModel],
    column: str,
    json_encode_value: bool = False,
) -> "ColumnElement[bool]":
    """Generate custom filter conditions for a column of a table.

    Args:
        value: The filter value.
        table: The table which contains the column.
        column: The column name.
        json_encode_value: Whether to json encode the value.

    Returns:
        The query conditions.
    """
    value, operator = BaseFilter._resolve_operator(value)
    filter_ = FilterGenerator(table).define_filter(
        column=column, value=value, operator=operator
    )
    if isinstance(filter_, StrFilter):
        filter_.json_encode_value = json_encode_value

    return filter_.generate_query_conditions(table=table)
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Raises:

Type Description
RuntimeError

If a valid logical operator is not supplied.

Source code in src/zenml/models/v2/base/filter.py
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.

    Raises:
        RuntimeError: If a valid logical operator is not supplied.
    """
    from sqlmodel import and_, or_

    filters = []
    for column_filter in self.list_of_filters:
        filters.append(
            column_filter.generate_query_conditions(table=table)
        )
    for custom_filter in self.get_custom_filters(table):
        filters.append(custom_filter)
    if self.logical_operator == LogicalOperators.OR:
        return or_(False, *filters)
    elif self.logical_operator == LogicalOperators.AND:
        return and_(True, *filters)
    else:
        raise RuntimeError("No valid logical operator was supplied.")
generate_name_or_id_query_conditions(value: Union[UUID, str], table: Type[NamedSchema], additional_columns: Optional[List[str]] = None) -> ColumnElement[bool]

Generate filter conditions for name or id of a table.

Parameters:

Name Type Description Default
value Union[UUID, str]

The filter value.

required
table Type[NamedSchema]

The table to filter.

required
additional_columns Optional[List[str]]

Additional table columns that should also filtered for the given value as part of the or condition.

None

Returns:

Type Description
ColumnElement[bool]

The query conditions.

Source code in src/zenml/models/v2/base/filter.py
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
def generate_name_or_id_query_conditions(
    self,
    value: Union[UUID, str],
    table: Type["NamedSchema"],
    additional_columns: Optional[List[str]] = None,
) -> "ColumnElement[bool]":
    """Generate filter conditions for name or id of a table.

    Args:
        value: The filter value.
        table: The table to filter.
        additional_columns: Additional table columns that should also
            filtered for the given value as part of the or condition.

    Returns:
        The query conditions.
    """
    from sqlmodel import or_

    value, operator = BaseFilter._resolve_operator(value)
    value = str(value)

    conditions = []

    filter_ = FilterGenerator(table).define_filter(
        column="id", value=value, operator=operator
    )
    conditions.append(filter_.generate_query_conditions(table=table))

    filter_ = FilterGenerator(table).define_filter(
        column="name", value=value, operator=operator
    )
    conditions.append(filter_.generate_query_conditions(table=table))

    for column in additional_columns or []:
        filter_ = FilterGenerator(table).define_filter(
            column=column, value=value, operator=operator
        )
        conditions.append(filter_.generate_query_conditions(table=table))

    return or_(*conditions)
generate_rbac_filter(table: Type[AnySchema]) -> Optional[ColumnElement[bool]]

Generates an optional RBAC filter.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
Optional[ColumnElement[bool]]

The RBAC filter.

Source code in src/zenml/models/v2/base/filter.py
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
def generate_rbac_filter(
    self,
    table: Type["AnySchema"],
) -> Optional["ColumnElement[bool]"]:
    """Generates an optional RBAC filter.

    Args:
        table: The query table.

    Returns:
        The RBAC filter.
    """
    from sqlmodel import or_

    if not self._rbac_configuration:
        return None

    expressions = []

    for column_name, allowed_ids in self._rbac_configuration[1].items():
        if allowed_ids is not None:
            expression = getattr(table, column_name).in_(allowed_ids)
            expressions.append(expression)

    if expressions and hasattr(table, "user_id"):
        # If `expressions` is not empty, we do not have full access to all
        # rows of the table. In this case, we also include rows which the
        # user owns.

        # Unowned entities are considered server-owned and can be seen
        # by anyone
        expressions.append(getattr(table, "user_id").is_(None))
        # The authenticated user owns this entity
        expressions.append(
            getattr(table, "user_id") == self._rbac_configuration[0]
        )

    if expressions:
        return or_(*expressions)
    else:
        return None
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

This can be overridden by subclasses to define custom filters that are not based on the columns of the underlying table.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/filter.py
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    This can be overridden by subclasses to define custom filters that are
    not based on the columns of the underlying table.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    return []
validate_sort_by(value: Any) -> Any classmethod

Validate that the sort_column is a valid column with a valid operand.

Parameters:

Name Type Description Default
value Any

The sort_by field value.

required

Returns:

Type Description
Any

The validated sort_by field value.

Raises:

Type Description
ValidationError

If the sort_by field is not a string.

ValueError

If the resource can't be sorted by this field.

Source code in src/zenml/models/v2/base/filter.py
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
@field_validator("sort_by", mode="before")
@classmethod
def validate_sort_by(cls, value: Any) -> Any:
    """Validate that the sort_column is a valid column with a valid operand.

    Args:
        value: The sort_by field value.

    Returns:
        The validated sort_by field value.

    Raises:
        ValidationError: If the sort_by field is not a string.
        ValueError: If the resource can't be sorted by this field.
    """
    # Somehow pydantic allows you to pass in int values, which will be
    #  interpreted as string, however within the validator they are still
    #  integers, which don't have a .split() method
    if not isinstance(value, str):
        raise ValidationError(
            f"str type expected for the sort_by field. "
            f"Received a {type(value)}"
        )
    column = value
    split_value = value.split(":", 1)
    if len(split_value) == 2:
        column = split_value[1]

        if split_value[0] not in SorterOps.values():
            logger.warning(
                "Invalid operand used for column sorting. "
                "Only the following operands are supported `%s`. "
                "Defaulting to 'asc' on column `%s`.",
                SorterOps.values(),
                column,
            )
            value = column

    if column in cls.CUSTOM_SORTING_OPTIONS:
        return value
    elif column in cls.FILTER_EXCLUDE_FIELDS:
        raise ValueError(
            f"This resource can not be sorted by this field: '{value}'"
        )
    if column in cls.model_fields:
        return value
    else:
        raise ValueError(
            "You can only sort by valid fields of this resource"
        )
BoolFilter

Bases: Filter

Filter for all Boolean fields.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a boolean column.

Parameters:

Name Type Description Default
column Any

The boolean column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
156
157
158
159
160
161
162
163
164
165
166
167
168
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a boolean column.

    Args:
        column: The boolean column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != self.value

    return column == self.value
DatetimeFilter

Bases: Filter

Filter for all datetime fields.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a datetime column.

Parameters:

Name Type Description Default
column Any

The datetime column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a datetime column.

    Args:
        column: The datetime column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    if self.operation == GenericFilterOps.IN:
        assert isinstance(self.value, tuple)
        lower_bound, upper_bound = self.value
        return column.between(lower_bound, upper_bound)

    assert isinstance(self.value, datetime)
    if self.operation == GenericFilterOps.GTE:
        return column >= self.value
    if self.operation == GenericFilterOps.GT:
        return column > self.value
    if self.operation == GenericFilterOps.LTE:
        return column <= self.value
    if self.operation == GenericFilterOps.LT:
        return column < self.value
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != self.value
    return column == self.value
Filter

Bases: BaseModel, ABC

Filter for all fields.

A Filter is a combination of a column, a value that the user uses to filter on this column and an operation to use. The easiest example would be user equals aria with column=user, value=aria and the operation=equals.

All subclasses of this class will support different sets of operations. This operation set is defined in the ALLOWED_OPS class variable.

Functions
generate_query_conditions(table: Type[SQLModel]) -> ColumnElement[bool]

Generate the query conditions for the database.

This method converts the Filter class into an appropriate SQLModel query condition, to be used when filtering on the Database.

Parameters:

Name Type Description Default
table Type[SQLModel]

The SQLModel table to use for the query creation

required

Returns:

Type Description
ColumnElement[bool]

A list of conditions that will be combined using the and operation

Source code in src/zenml/models/v2/base/filter.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def generate_query_conditions(
    self,
    table: Type[SQLModel],
) -> "ColumnElement[bool]":
    """Generate the query conditions for the database.

    This method converts the Filter class into an appropriate SQLModel
    query condition, to be used when filtering on the Database.

    Args:
        table: The SQLModel table to use for the query creation

    Returns:
        A list of conditions that will be combined using the `and` operation
    """
    column = getattr(table, self.column)
    conditions = self.generate_query_conditions_from_column(column)
    return conditions  # type:ignore[no-any-return]
generate_query_conditions_from_column(column: Any) -> Any abstractmethod

Generate query conditions given the corresponding database column.

This method should be overridden by subclasses to define how each supported operation in self.ALLOWED_OPS can be used to filter the given column by self.value.

Parameters:

Name Type Description Default
column Any

The column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@abstractmethod
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions given the corresponding database column.

    This method should be overridden by subclasses to define how each
    supported operation in `self.ALLOWED_OPS` can be used to filter the
    given column by `self.value`.

    Args:
        column: The column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
validate_operation(value: Any) -> Any classmethod

Validate that the operation is a valid op for the field type.

Parameters:

Name Type Description Default
value Any

The operation of this filter.

required

Returns:

Type Description
Any

The operation if it is valid.

Raises:

Type Description
ValueError

If the operation is not valid for this field type.

Source code in src/zenml/models/v2/base/filter.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
@field_validator("operation", mode="before")
@classmethod
def validate_operation(cls, value: Any) -> Any:
    """Validate that the operation is a valid op for the field type.

    Args:
        value: The operation of this filter.

    Returns:
        The operation if it is valid.

    Raises:
        ValueError: If the operation is not valid for this field type.
    """
    if value not in cls.ALLOWED_OPS:
        raise ValueError(
            f"This datatype can not be filtered using this operation: "
            f"'{value}'. The allowed operations are: {cls.ALLOWED_OPS}"
        )
    else:
        return value
FilterGenerator(model_class: Type[BaseModel])

Helper class to define filters for a class.

Initialize the object.

Parameters:

Name Type Description Default
model_class Type[BaseModel]

The model class for which to define filters.

required
Source code in src/zenml/models/v2/base/filter.py
889
890
891
892
893
894
895
def __init__(self, model_class: Type[BaseModel]) -> None:
    """Initialize the object.

    Args:
        model_class: The model class for which to define filters.
    """
    self._model_class = model_class
Functions
check_field_annotation(k: str, type_: Any) -> bool

Checks whether a model field has a certain annotation.

Parameters:

Name Type Description Default
k str

The name of the field.

required
type_ Any

The type to check.

required

Raises:

Type Description
ValueError

if the model field within does not have an annotation.

Returns:

Type Description
bool

True if the annotation of the field matches the given type, False

bool

otherwise.

Source code in src/zenml/models/v2/base/filter.py
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
def check_field_annotation(self, k: str, type_: Any) -> bool:
    """Checks whether a model field has a certain annotation.

    Args:
        k: The name of the field.
        type_: The type to check.

    Raises:
        ValueError: if the model field within does not have an annotation.

    Returns:
        True if the annotation of the field matches the given type, False
        otherwise.
    """
    try:
        annotation = self._model_class.model_fields[k].annotation

        if annotation is not None:
            return (
                issubclass(type_, get_args(annotation))
                or annotation is type_
            )
        else:
            raise ValueError(
                f"The field '{k}' inside the model {self._model_class.__name__} "
                "does not have an annotation."
            )
    except TypeError:
        return False
define_filter(column: str, value: Any, operator: GenericFilterOps) -> Filter

Define a filter for a given column.

Parameters:

Name Type Description Default
column str

The column to filter on.

required
value Any

The value by which to filter.

required
operator GenericFilterOps

The operator to use for filtering.

required

Returns:

Type Description
Filter

A Filter object.

Source code in src/zenml/models/v2/base/filter.py
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
def define_filter(
    self, column: str, value: Any, operator: GenericFilterOps
) -> Filter:
    """Define a filter for a given column.

    Args:
        column: The column to filter on.
        value: The value by which to filter.
        operator: The operator to use for filtering.

    Returns:
        A Filter object.
    """
    # Create datetime filters
    if self.is_datetime_field(column):
        return self._define_datetime_filter(
            column=column,
            value=value,
            operator=operator,
        )

    # Create UUID filters
    if self.is_uuid_field(column):
        return self._define_uuid_filter(
            column=column,
            value=value,
            operator=operator,
        )

    # Create int filters
    if self.is_int_field(column):
        return NumericFilter(
            operation=GenericFilterOps(operator),
            column=column,
            value=int(value),
        )

    # Create bool filters
    if self.is_bool_field(column):
        return self._define_bool_filter(
            column=column,
            value=value,
            operator=operator,
        )

    # Create str filters
    if self.is_str_field(column):
        return self._define_str_filter(
            operator=GenericFilterOps(operator),
            column=column,
            value=value,
        )

    # Handle unsupported datatypes
    logger.warning(
        f"The Datatype {self._model_class.model_fields[column].annotation} "
        "might not be supported for filtering. Defaulting to a string "
        "filter."
    )
    return StrFilter(
        operation=GenericFilterOps(operator),
        column=column,
        value=str(value),
    )
is_bool_field(k: str) -> bool

Checks if it's a bool field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is a bool field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
def is_bool_field(self, k: str) -> bool:
    """Checks if it's a bool field.

    Args:
        k: The key to check.

    Returns:
        True if the field is a bool field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=bool)
is_datetime_field(k: str) -> bool

Checks if it's a datetime field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is a datetime field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
def is_datetime_field(self, k: str) -> bool:
    """Checks if it's a datetime field.

    Args:
        k: The key to check.

    Returns:
        True if the field is a datetime field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=datetime)
is_int_field(k: str) -> bool

Checks if it's an int field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is an int field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
def is_int_field(self, k: str) -> bool:
    """Checks if it's an int field.

    Args:
        k: The key to check.

    Returns:
        True if the field is an int field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=int)
is_sort_by_field(k: str) -> bool

Checks if it's a sort by field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is a sort by field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
def is_sort_by_field(self, k: str) -> bool:
    """Checks if it's a sort by field.

    Args:
        k: The key to check.

    Returns:
        True if the field is a sort by field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=str) and k == "sort_by"
is_str_field(k: str) -> bool

Checks if it's a string field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is a string field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
def is_str_field(self, k: str) -> bool:
    """Checks if it's a string field.

    Args:
        k: The key to check.

    Returns:
        True if the field is a string field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=str)
is_uuid_field(k: str) -> bool

Checks if it's a UUID field.

Parameters:

Name Type Description Default
k str

The key to check.

required

Returns:

Type Description
bool

True if the field is a UUID field, False otherwise.

Source code in src/zenml/models/v2/base/filter.py
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
def is_uuid_field(self, k: str) -> bool:
    """Checks if it's a UUID field.

    Args:
        k: The key to check.

    Returns:
        True if the field is a UUID field, False otherwise.
    """
    return self.check_field_annotation(k=k, type_=UUID)
NumericFilter

Bases: Filter

Filter for all numeric fields.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a numeric column.

Parameters:

Name Type Description Default
column Any

The numeric column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a numeric column.

    Args:
        column: The numeric column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    if self.operation == GenericFilterOps.GTE:
        return column >= self.value
    if self.operation == GenericFilterOps.GT:
        return column > self.value
    if self.operation == GenericFilterOps.LTE:
        return column <= self.value
    if self.operation == GenericFilterOps.LT:
        return column < self.value
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != self.value
    return column == self.value
StrFilter

Bases: Filter

Filter for all string fields.

Functions
check_value_if_operation_oneof() -> StrFilter

Validator to check if value is a list if oneof operation is used.

Raises:

Type Description
ValueError

If the value is not a list

Returns:

Type Description
StrFilter

self

Source code in src/zenml/models/v2/base/filter.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@model_validator(mode="after")
def check_value_if_operation_oneof(self) -> "StrFilter":
    """Validator to check if value is a list if oneof operation is used.

    Raises:
        ValueError: If the value is not a list

    Returns:
        self
    """
    if self.operation == GenericFilterOps.ONEOF:
        if not isinstance(self.value, list):
            raise ValueError(ONEOF_ERROR)
    return self
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a string column.

Parameters:

Name Type Description Default
column Any

The string column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Raises:

Type Description
ValueError

the comparison of the column to a numeric value fails.

Source code in src/zenml/models/v2/base/filter.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a string column.

    Args:
        column: The string column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.

    Raises:
        ValueError: the comparison of the column to a numeric value fails.
    """
    if self.operation in {
        GenericFilterOps.GT,
        GenericFilterOps.LT,
        GenericFilterOps.GTE,
        GenericFilterOps.LTE,
    }:
        try:
            numeric_column = cast(column, Float)

            assert self.value is not None

            if self.operation == GenericFilterOps.GT:
                return and_(
                    numeric_column, numeric_column > float(self.value)
                )
            if self.operation == GenericFilterOps.LT:
                return and_(
                    numeric_column, numeric_column < float(self.value)
                )
            if self.operation == GenericFilterOps.GTE:
                return and_(
                    numeric_column, numeric_column >= float(self.value)
                )
            if self.operation == GenericFilterOps.LTE:
                return and_(
                    numeric_column, numeric_column <= float(self.value)
                )
        except Exception as e:
            raise ValueError(
                f"Failed to compare the column '{column}' to the "
                f"value '{self.value}' (must be numeric): {e}"
            )

    if self.operation == GenericFilterOps.ONEOF:
        assert isinstance(self.value, list)
        # Convert the list of values to a list of json strings
        json_list = (
            [json.dumps(v) for v in self.value]
            if self.json_encode_value
            else self.value
        )
        return column.in_(json_list)

    # Don't convert the value to a json string if the operation is contains
    # because the quotes around strings will mess with the comparison
    if self.operation == GenericFilterOps.CONTAINS:
        return column.like(f"%{self.value}%")

    json_value = (
        json.dumps(self.value) if self.json_encode_value else self.value
    )

    if self.operation == GenericFilterOps.STARTSWITH:
        return column.startswith(f"{json_value}")
    if self.operation == GenericFilterOps.ENDSWITH:
        return column.endswith(f"{json_value}")
    if self.operation == GenericFilterOps.NOT_EQUALS:
        return column != json_value

    return column == json_value
UUIDFilter

Bases: StrFilter

Filter for all uuid fields which are mostly treated like strings.

Functions
generate_query_conditions_from_column(column: Any) -> Any

Generate query conditions for a UUID column.

Parameters:

Name Type Description Default
column Any

The UUID column of an SQLModel table on which to filter.

required

Returns:

Type Description
Any

A list of query conditions.

Source code in src/zenml/models/v2/base/filter.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
def generate_query_conditions_from_column(self, column: Any) -> Any:
    """Generate query conditions for a UUID column.

    Args:
        column: The UUID column of an SQLModel table on which to filter.

    Returns:
        A list of query conditions.
    """
    import sqlalchemy
    from sqlalchemy_utils.functions import cast_if

    from zenml.utils import uuid_utils

    # For equality checks, compare the UUID directly
    if self.operation == GenericFilterOps.EQUALS:
        if not uuid_utils.is_valid_uuid(self.value):
            return False

        return column == self.value

    if self.operation == GenericFilterOps.NOT_EQUALS:
        if not uuid_utils.is_valid_uuid(self.value):
            return True

        return column != self.value

    # For all other operations, cast and handle the column as string
    return super().generate_query_conditions_from_column(
        column=cast_if(column, sqlalchemy.String)
    )
Functions
page

Page model definitions.

Classes
Page

Bases: BaseModel, Generic[B]

Return Model for List Models to accommodate pagination.

Attributes
size: int property

Return the item count of the page.

Returns:

Type Description
int

The amount of items in the page.

scoped

Scoped model definitions.

Classes
TaggableFilter

Bases: BaseFilter

Model to enable filtering and sorting by tags.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    from zenml.zen_stores.schemas import TagResourceSchema, TagSchema

    query = super().apply_filter(query=query, table=table)
    if self.tag:
        query = query.join(
            TagResourceSchema,
            TagResourceSchema.resource_id == getattr(table, "id"),
        ).join(TagSchema, TagSchema.id == TagResourceSchema.tag_id)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    sort_by, operand = self.sorting_params

    if sort_by == "tags":
        from sqlmodel import asc, desc, func, select

        from zenml.enums import SorterOps, TaggableResourceTypes
        from zenml.zen_stores.schemas import (
            ArtifactSchema,
            ArtifactVersionSchema,
            ModelSchema,
            ModelVersionSchema,
            PipelineRunSchema,
            PipelineSchema,
            RunTemplateSchema,
            TagResourceSchema,
            TagSchema,
        )

        resource_type_mapping = {
            ArtifactSchema: TaggableResourceTypes.ARTIFACT,
            ArtifactVersionSchema: TaggableResourceTypes.ARTIFACT_VERSION,
            ModelSchema: TaggableResourceTypes.MODEL,
            ModelVersionSchema: TaggableResourceTypes.MODEL_VERSION,
            PipelineSchema: TaggableResourceTypes.PIPELINE,
            PipelineRunSchema: TaggableResourceTypes.PIPELINE_RUN,
            RunTemplateSchema: TaggableResourceTypes.RUN_TEMPLATE,
        }

        sorted_tags = (
            select(TagResourceSchema.resource_id, TagSchema.name)
            .join(TagSchema, TagResourceSchema.tag_id == TagSchema.id)  # type: ignore[arg-type]
            .filter(
                TagResourceSchema.resource_type  # type: ignore[arg-type]
                == resource_type_mapping[table]
            )
            .order_by(
                asc(TagResourceSchema.resource_id), asc(TagSchema.name)
            )
        ).alias("sorted_tags")

        tags_subquery = (
            select(
                sorted_tags.c.resource_id,
                func.group_concat(sorted_tags.c.name, ", ").label(
                    "tags_list"
                ),
            ).group_by(sorted_tags.c.resource_id)
        ).alias("tags_subquery")

        query = query.add_columns(tags_subquery.c.tags_list).outerjoin(
            tags_subquery, table.id == tags_subquery.c.resource_id
        )

        # Apply ordering based on the tags list
        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc("tags_list"))
        else:
            query = query.order_by(desc("tags_list"))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom tag filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom tag filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    from zenml.zen_stores.schemas import TagSchema

    custom_filters = super().get_custom_filters(table)
    if self.tag:
        custom_filters.append(
            self.generate_custom_query_conditions_for_column(
                value=self.tag, table=TagSchema, column="name"
            )
        )

    return custom_filters
UserScopedFilter

Bases: BaseFilter

Model to enable advanced user-based scoping.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self.scope_user:
        query = query.where(getattr(table, "user_id") == self.scope_user)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import UserSchema

    sort_by, operand = self.sorting_params

    if sort_by == "user":
        column = UserSchema.name

        query = query.outerjoin(
            UserSchema,
            getattr(table, "user_id") == UserSchema.id,
        )

        query = query.add_columns(UserSchema.name)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc(column))
        else:
            query = query.order_by(desc(column))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import UserSchema

    if self.user:
        user_filter = and_(
            getattr(table, "user_id") == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters
set_scope_user(user_id: UUID) -> None

Set the user that is performing the filtering to scope the response.

Parameters:

Name Type Description Default
user_id UUID

The user ID to scope the response to.

required
Source code in src/zenml/models/v2/base/scoped.py
182
183
184
185
186
187
188
def set_scope_user(self, user_id: UUID) -> None:
    """Set the user that is performing the filtering to scope the response.

    Args:
        user_id: The user ID to scope the response to.
    """
    self.scope_user = user_id
UserScopedRequest

Bases: BaseRequest

Base user-owned request model.

Used as a base class for all domain models that are "owned" by a user.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for user scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
61
62
63
64
65
66
67
68
69
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for user scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["user_id"] = self.user
    return metadata
UserScopedResponse

Bases: BaseIdentifiedResponse[UserBody, UserMetadata, UserResources], Generic[UserBody, UserMetadata, UserResources]

Base user-owned model.

Used as a base class for all domain models that are "owned" by a user.

Attributes
user: Optional[UserResponse] property

The user property.

Returns:

Type Description
Optional[UserResponse]

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for user scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
128
129
130
131
132
133
134
135
136
137
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for user scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    if self.user is not None:
        metadata["user_id"] = self.user.id
    return metadata
UserScopedResponseBody

Bases: BaseDatedResponseBody

Base user-owned body.

UserScopedResponseMetadata

Bases: BaseResponseMetadata

Base user-owned metadata.

UserScopedResponseResources

Bases: BaseResponseResources

Base class for all resource models associated with the user.

WorkspaceScopedFilter

Bases: UserScopedFilter

Model to enable advanced scoping with workspace.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/base/scoped.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    from sqlmodel import or_

    query = super().apply_filter(query=query, table=table)

    if self.scope_workspace:
        scope_filter = or_(
            getattr(table, "workspace_id") == self.scope_workspace,
            getattr(table, "workspace_id").is_(None),
        )
        query = query.where(scope_filter)

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/base/scoped.py
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import WorkspaceSchema

    sort_by, operand = self.sorting_params

    if sort_by == "workspace":
        column = WorkspaceSchema.name

        query = query.join(
            WorkspaceSchema,
            getattr(table, "workspace_id") == WorkspaceSchema.id,
        )

        query = query.add_columns(WorkspaceSchema.name)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(asc(column))
        else:
            query = query.order_by(desc(column))

        return query

    return super().apply_sorting(query=query, table=table)
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/base/scoped.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import WorkspaceSchema

    if self.workspace:
        workspace_filter = and_(
            getattr(table, "workspace_id") == WorkspaceSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.workspace,
                table=WorkspaceSchema,
            ),
        )
        custom_filters.append(workspace_filter)

    return custom_filters
set_scope_workspace(workspace_id: UUID) -> None

Set the workspace to scope this response.

Parameters:

Name Type Description Default
workspace_id UUID

The workspace to scope this response to.

required
Source code in src/zenml/models/v2/base/scoped.py
362
363
364
365
366
367
368
def set_scope_workspace(self, workspace_id: UUID) -> None:
    """Set the workspace to scope this response.

    Args:
        workspace_id: The workspace to scope this response to.
    """
    self.scope_workspace = workspace_id
WorkspaceScopedRequest

Bases: UserScopedRequest

Base workspace-scoped request domain model.

Used as a base class for all domain models that are workspace-scoped.

Functions
get_analytics_metadata() -> Dict[str, Any]

Fetches the analytics metadata for workspace scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
82
83
84
85
86
87
88
89
90
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for workspace scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["workspace_id"] = self.workspace
    return metadata
WorkspaceScopedResponse

Bases: UserScopedResponse[WorkspaceBody, WorkspaceMetadata, WorkspaceResources], Generic[WorkspaceBody, WorkspaceMetadata, WorkspaceResources]

Base workspace-scoped domain model.

Used as a base class for all domain models that are workspace-scoped.

Attributes
workspace: WorkspaceResponse property

The workspace property.

Returns:

Type Description
WorkspaceResponse

the value of the property.

WorkspaceScopedResponseBody

Bases: UserScopedResponseBody

Base workspace-scoped body.

WorkspaceScopedResponseMetadata

Bases: UserScopedResponseMetadata

Base workspace-scoped metadata.

WorkspaceScopedResponseResources

Bases: UserScopedResponseResources

Base workspace-scoped resources.

core
Modules
action

Collection of all models concerning actions.

Classes
ActionFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all actions.

ActionRequest

Bases: WorkspaceScopedRequest

Model for creating a new action.

ActionResponse

Bases: WorkspaceScopedResponse[ActionResponseBody, ActionResponseMetadata, ActionResponseResources]

Response model for actions.

Attributes
auth_window: int property

The auth_window property.

Returns:

Type Description
int

the value of the property.

configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

flavor: str property

The flavor property.

Returns:

Type Description
str

the value of the property.

plugin_subtype: PluginSubType property

The plugin_subtype property.

Returns:

Type Description
PluginSubType

the value of the property.

service_account: UserResponse property

The service_account property.

Returns:

Type Description
UserResponse

the value of the property.

Functions
get_hydrated_version() -> ActionResponse

Get the hydrated version of this action.

Returns:

Type Description
ActionResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/action.py
184
185
186
187
188
189
190
191
192
def get_hydrated_version(self) -> "ActionResponse":
    """Get the hydrated version of this action.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_action(self.id)
set_configuration(configuration: Dict[str, Any]) -> None

Set the configuration property.

Parameters:

Name Type Description Default
configuration Dict[str, Any]

The value to set.

required
Source code in src/zenml/models/v2/core/action.py
240
241
242
243
244
245
246
def set_configuration(self, configuration: Dict[str, Any]) -> None:
    """Set the `configuration` property.

    Args:
        configuration: The value to set.
    """
    self.get_metadata().configuration = configuration
ActionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for actions.

ActionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for actions.

ActionResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the action entity.

ActionUpdate

Bases: BaseUpdate

Update model for actions.

Functions
from_response(response: ActionResponse) -> ActionUpdate classmethod

Create an update model from a response model.

Parameters:

Name Type Description Default
response ActionResponse

The response model to create the update model from.

required

Returns:

Type Description
ActionUpdate

The update model.

Source code in src/zenml/models/v2/core/action.py
116
117
118
119
120
121
122
123
124
125
126
127
128
@classmethod
def from_response(cls, response: "ActionResponse") -> "ActionUpdate":
    """Create an update model from a response model.

    Args:
        response: The response model to create the update model from.

    Returns:
        The update model.
    """
    return ActionUpdate(
        configuration=copy.deepcopy(response.configuration),
    )
action_flavor

Action flavor model definitions.

Classes
ActionFlavorResponse

Bases: BasePluginFlavorResponse[ActionFlavorResponseBody, ActionFlavorResponseMetadata, ActionFlavorResponseResources]

Response model for Action Flavors.

Attributes
config_schema: Dict[str, Any] property

The source_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

ActionFlavorResponseBody

Bases: BasePluginResponseBody

Response body for action flavors.

ActionFlavorResponseMetadata

Bases: BasePluginResponseMetadata

Response metadata for action flavors.

ActionFlavorResponseResources

Bases: BasePluginResponseResources

Response resources for action flavors.

api_key

Models representing API keys.

Classes
APIKey

Bases: BaseModel

Encoded model for API keys.

Functions
decode_api_key(encoded_key: str) -> APIKey classmethod

Decodes an API key from a base64 string.

Parameters:

Name Type Description Default
encoded_key str

The encoded API key.

required

Returns:

Type Description
APIKey

The decoded API key.

Raises:

Type Description
ValueError

If the key is not valid.

Source code in src/zenml/models/v2/core/api_key.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@classmethod
def decode_api_key(cls, encoded_key: str) -> "APIKey":
    """Decodes an API key from a base64 string.

    Args:
        encoded_key: The encoded API key.

    Returns:
        The decoded API key.

    Raises:
        ValueError: If the key is not valid.
    """
    if encoded_key.startswith(ZENML_API_KEY_PREFIX):
        encoded_key = encoded_key[len(ZENML_API_KEY_PREFIX) :]
    try:
        json_key = b64_decode(encoded_key)
        return cls.model_validate_json(json_key)
    except Exception:
        raise ValueError("Invalid API key.")
encode() -> str

Encodes the API key in a base64 string that includes the key ID and prefix.

Returns:

Type Description
str

The encoded API key.

Source code in src/zenml/models/v2/core/api_key.py
72
73
74
75
76
77
78
79
def encode(self) -> str:
    """Encodes the API key in a base64 string that includes the key ID and prefix.

    Returns:
        The encoded API key.
    """
    encoded_key = b64_encode(self.model_dump_json())
    return f"{ZENML_API_KEY_PREFIX}{encoded_key}"
APIKeyFilter

Bases: BaseFilter

Filter model for API keys.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to apply the service account scope as an additional filter.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/api_key.py
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to apply the service account scope as an additional filter.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self.service_account:
        scope_filter = (
            getattr(table, "service_account_id") == self.service_account
        )
        query = query.where(scope_filter)

    return query
set_service_account(service_account_id: UUID) -> None

Set the service account by which to scope this query.

Parameters:

Name Type Description Default
service_account_id UUID

The service account ID.

required
Source code in src/zenml/models/v2/core/api_key.py
377
378
379
380
381
382
383
def set_service_account(self, service_account_id: UUID) -> None:
    """Set the service account by which to scope this query.

    Args:
        service_account_id: The service account ID.
    """
    self.service_account = service_account_id
APIKeyInternalResponse

Bases: APIKeyResponse

Response model for API keys used internally.

Functions
verify_key(key: str) -> bool

Verifies a given key against the stored (hashed) key(s).

Parameters:

Name Type Description Default
key str

Input key to be verified.

required

Returns:

Type Description
bool

True if the keys match.

Source code in src/zenml/models/v2/core/api_key.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def verify_key(
    self,
    key: str,
) -> bool:
    """Verifies a given key against the stored (hashed) key(s).

    Args:
        key: Input key to be verified.

    Returns:
        True if the keys match.
    """
    # even when the hashed key is not set, we still want to execute
    # the hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    key_hash: Optional[str] = None
    context = CryptContext(schemes=["bcrypt"], deprecated="auto")
    if self.key is not None and self.active:
        key_hash = self.key
    result = context.verify(key, key_hash)

    # same for the previous key, if set and if it's still valid
    key_hash = None
    if (
        self.previous_key is not None
        and self.last_rotated is not None
        and self.active
        and self.retain_period_minutes > 0
    ):
        # check if the previous key is still valid
        if utc_now(
            tz_aware=self.last_rotated
        ) - self.last_rotated < timedelta(
            minutes=self.retain_period_minutes
        ):
            key_hash = self.previous_key
    previous_result = context.verify(key, key_hash)

    return result or previous_result
APIKeyInternalUpdate

Bases: APIKeyUpdate

Update model for API keys used internally.

APIKeyRequest

Bases: BaseRequest

Request model for API keys.

APIKeyResponse

Bases: BaseIdentifiedResponse[APIKeyResponseBody, APIKeyResponseMetadata, APIKeyResponseResources]

Response model for API keys.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

key: Optional[str] property

The key property.

Returns:

Type Description
Optional[str]

the value of the property.

last_login: Optional[datetime] property

The last_login property.

Returns:

Type Description
Optional[datetime]

the value of the property.

last_rotated: Optional[datetime] property

The last_rotated property.

Returns:

Type Description
Optional[datetime]

the value of the property.

retain_period_minutes: int property

The retain_period_minutes property.

Returns:

Type Description
int

the value of the property.

service_account: ServiceAccountResponse property

The service_account property.

Returns:

Type Description
ServiceAccountResponse

the value of the property.

Functions
get_hydrated_version() -> APIKeyResponse

Get the hydrated version of this API key.

Returns:

Type Description
APIKeyResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/api_key.py
198
199
200
201
202
203
204
205
206
207
208
209
def get_hydrated_version(self) -> "APIKeyResponse":
    """Get the hydrated version of this API key.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_api_key(
        service_account_id=self.service_account.id,
        api_key_name_or_id=self.id,
    )
set_key(key: str) -> None

Sets the API key and encodes it.

Parameters:

Name Type Description Default
key str

The API key value to be set.

required
Source code in src/zenml/models/v2/core/api_key.py
212
213
214
215
216
217
218
def set_key(self, key: str) -> None:
    """Sets the API key and encodes it.

    Args:
        key: The API key value to be set.
    """
    self.get_body().key = APIKey(id=self.id, key=key).encode()
APIKeyResponseBody

Bases: BaseDatedResponseBody

Response body for API keys.

APIKeyResponseMetadata

Bases: BaseResponseMetadata

Response metadata for API keys.

APIKeyResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the APIKey entity.

APIKeyRotateRequest

Bases: BaseModel

Request model for API key rotation.

APIKeyUpdate

Bases: BaseUpdate

Update model for API keys.

Functions
artifact

Models representing artifacts.

Classes
ArtifactFilter

Bases: TaggableFilter

Model to enable advanced filtering of artifacts.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query for Artifacts.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/artifact.py
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query for Artifacts.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == SORT_BY_LATEST_VERSION_KEY:
        # Subquery to find the latest version per artifact
        latest_version_subquery = (
            select(
                ArtifactSchema.id,
                case(
                    (
                        func.max(ArtifactVersionSchema.created).is_(None),
                        ArtifactSchema.created,
                    ),
                    else_=func.max(ArtifactVersionSchema.created),
                ).label("latest_version_created"),
            )
            .outerjoin(
                ArtifactVersionSchema,
                ArtifactSchema.id == ArtifactVersionSchema.artifact_id,  # type: ignore[arg-type]
            )
            .group_by(col(ArtifactSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_version_subquery.c.latest_version_created,
        ).where(ArtifactSchema.id == latest_version_subquery.c.id)

        # Apply sorting based on the operand
        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_version_subquery.c.latest_version_created),
                asc(ArtifactSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_version_subquery.c.latest_version_created),
                desc(ArtifactSchema.id),
            )
        return query

    # For other sorting cases, delegate to the parent class
    return super().apply_sorting(query=query, table=table)
ArtifactRequest

Bases: BaseRequest

Artifact request model.

ArtifactResponse

Bases: BaseIdentifiedResponse[ArtifactResponseBody, ArtifactResponseMetadata, ArtifactResponseResources]

Artifact response model.

Attributes
has_custom_name: bool property

The has_custom_name property.

Returns:

Type Description
bool

the value of the property.

latest_version_id: Optional[UUID] property

The latest_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_version_name: Optional[str] property

The latest_version_name property.

Returns:

Type Description
Optional[str]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

versions: Dict[str, ArtifactVersionResponse] property

Get a list of all versions of this artifact.

Returns:

Type Description
Dict[str, ArtifactVersionResponse]

A list of all versions of this artifact.

Functions
get_hydrated_version() -> ArtifactResponse

Get the hydrated version of this artifact.

Returns:

Type Description
ArtifactResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact.py
117
118
119
120
121
122
123
124
125
def get_hydrated_version(self) -> "ArtifactResponse":
    """Get the hydrated version of this artifact.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact(self.id)
ArtifactResponseBody

Bases: BaseDatedResponseBody

Response body for artifacts.

ArtifactResponseMetadata

Bases: BaseResponseMetadata

Response metadata for artifacts.

ArtifactResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the Artifact Entity.

ArtifactUpdate

Bases: BaseModel

Artifact update model.

artifact_version

Models representing artifact versions.

Classes
ArtifactVersionFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of artifact versions.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[Union[ColumnElement[bool]]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[Union[ColumnElement[bool]]]

A list of custom filters.

Source code in src/zenml/models/v2/core/artifact_version.py
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List[Union["ColumnElement[bool]"]]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, or_, select

    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
        ModelSchema,
        ModelVersionArtifactSchema,
        ModelVersionSchema,
        PipelineRunSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        StepRunInputArtifactSchema,
        StepRunOutputArtifactSchema,
        StepRunSchema,
    )

    if self.name:
        value, filter_operator = self._resolve_operator(self.name)
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        artifact_name_filter = and_(
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            filter_.generate_query_conditions(ArtifactSchema),
        )
        custom_filters.append(artifact_name_filter)

    if self.only_unused:
        unused_filter = and_(
            ArtifactVersionSchema.id.notin_(  # type: ignore[attr-defined]
                select(StepRunOutputArtifactSchema.artifact_id)
            ),
            ArtifactVersionSchema.id.notin_(  # type: ignore[attr-defined]
                select(StepRunInputArtifactSchema.artifact_id)
            ),
        )
        custom_filters.append(unused_filter)

    if self.model_version_id:
        value, operator = self._resolve_operator(self.model_version_id)

        model_version_filter = and_(
            ArtifactVersionSchema.id
            == ModelVersionArtifactSchema.artifact_version_id,
            ModelVersionArtifactSchema.model_version_id
            == ModelVersionSchema.id,
            FilterGenerator(ModelVersionSchema)
            .define_filter(column="id", value=value, operator=operator)
            .generate_query_conditions(ModelVersionSchema),
        )
        custom_filters.append(model_version_filter)

    if self.has_custom_name is not None:
        custom_name_filter = and_(
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            ArtifactSchema.has_custom_name == self.has_custom_name,
        )
        custom_filters.append(custom_name_filter)

    if self.model:
        model_filter = and_(
            ArtifactVersionSchema.id
            == ModelVersionArtifactSchema.artifact_version_id,
            ModelVersionArtifactSchema.model_version_id
            == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)

    if self.pipeline_run:
        pipeline_run_filter = and_(
            or_(
                and_(
                    ArtifactVersionSchema.id
                    == StepRunOutputArtifactSchema.artifact_id,
                    StepRunOutputArtifactSchema.step_id
                    == StepRunSchema.id,
                ),
                and_(
                    ArtifactVersionSchema.id
                    == StepRunInputArtifactSchema.artifact_id,
                    StepRunInputArtifactSchema.step_id == StepRunSchema.id,
                ),
            ),
            StepRunSchema.pipeline_run_id == PipelineRunSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline_run, table=PipelineRunSchema
            ),
        )
        custom_filters.append(pipeline_run_filter)

    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == ArtifactVersionSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.ARTIFACT_VERSION.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters
ArtifactVersionRequest

Bases: WorkspaceScopedRequest

Request model for artifact versions.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum str length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/artifact_version.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
@field_validator("version")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum str length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value
ArtifactVersionResponse

Bases: WorkspaceScopedResponse[ArtifactVersionResponseBody, ArtifactVersionResponseMetadata, ArtifactVersionResponseResources]

Response model for artifact versions.

Attributes
artifact: ArtifactResponse property

The artifact property.

Returns:

Type Description
ArtifactResponse

the value of the property.

artifact_store_id: Optional[UUID] property

The artifact_store_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

data_type: Source property

The data_type property.

Returns:

Type Description
Source

the value of the property.

materializer: Source property

The materializer property.

Returns:

Type Description
Source

the value of the property.

name: str property

The name property.

Returns:

Type Description
str

the value of the property.

producer_pipeline_run_id: Optional[UUID] property

The producer_pipeline_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

producer_step_run_id: Optional[UUID] property

The producer_step_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

run: PipelineRunResponse property

Get the pipeline run that produced this artifact.

Returns:

Type Description
PipelineRunResponse

The pipeline run that produced this artifact.

run_metadata: Dict[str, MetadataType] property

The metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

save_type: ArtifactSaveType property

The save_type property.

Returns:

Type Description
ArtifactSaveType

the value of the property.

step: StepRunResponse property

Get the step that produced this artifact.

Returns:

Type Description
StepRunResponse

The step that produced this artifact.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

type: ArtifactType property

The type property.

Returns:

Type Description
ArtifactType

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

version: Union[str, int] property

The version property.

Returns:

Type Description
Union[str, int]

the value of the property.

visualizations: Optional[List[ArtifactVisualizationResponse]] property

The visualizations property.

Returns:

Type Description
Optional[List[ArtifactVisualizationResponse]]

the value of the property.

Functions
download_files(path: str, overwrite: bool = False) -> None

Downloads data for an artifact with no materializing.

Any artifacts will be saved as a zip file to the given path.

Parameters:

Name Type Description Default
path str

The path to save the binary data to.

required
overwrite bool

Whether to overwrite the file if it already exists.

False

Raises:

Type Description
ValueError

If the path does not end with '.zip'.

Source code in src/zenml/models/v2/core/artifact_version.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def download_files(self, path: str, overwrite: bool = False) -> None:
    """Downloads data for an artifact with no materializing.

    Any artifacts will be saved as a zip file to the given path.

    Args:
        path: The path to save the binary data to.
        overwrite: Whether to overwrite the file if it already exists.

    Raises:
        ValueError: If the path does not end with '.zip'.
    """
    if not path.endswith(".zip"):
        raise ValueError(
            "The path should end with '.zip' to save the binary data."
        )
    from zenml.artifacts.utils import (
        download_artifact_files_from_response,
    )

    download_artifact_files_from_response(
        self,
        path=path,
        overwrite=overwrite,
    )
get_hydrated_version() -> ArtifactVersionResponse

Get the hydrated version of this artifact version.

Returns:

Type Description
ArtifactVersionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact_version.py
261
262
263
264
265
266
267
268
269
def get_hydrated_version(self) -> "ArtifactVersionResponse":
    """Get the hydrated version of this artifact version.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact_version(self.id)
load() -> Any

Materializes (loads) the data stored in this artifact.

Returns:

Type Description
Any

The materialized data.

Source code in src/zenml/models/v2/core/artifact_version.py
423
424
425
426
427
428
429
430
431
def load(self) -> Any:
    """Materializes (loads) the data stored in this artifact.

    Returns:
        The materialized data.
    """
    from zenml.artifacts.utils import load_artifact_from_response

    return load_artifact_from_response(self)
visualize(title: Optional[str] = None) -> None

Visualize the artifact in notebook environments.

Parameters:

Name Type Description Default
title Optional[str]

Optional title to show before the visualizations.

None
Source code in src/zenml/models/v2/core/artifact_version.py
459
460
461
462
463
464
465
466
467
def visualize(self, title: Optional[str] = None) -> None:
    """Visualize the artifact in notebook environments.

    Args:
        title: Optional title to show before the visualizations.
    """
    from zenml.utils.visualization_utils import visualize_artifact

    visualize_artifact(self, title=title)
ArtifactVersionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for artifact versions.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum str length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/artifact_version.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@field_validator("version")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum str length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value
ArtifactVersionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for artifact versions.

ArtifactVersionResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the artifact version entity.

ArtifactVersionUpdate

Bases: BaseModel

Artifact version update model.

LazyArtifactVersionResponse

Bases: ArtifactVersionResponse

Lazy artifact version response.

Used if the artifact version is accessed from the model in a pipeline context available only during pipeline compilation.

Attributes
run_metadata: Dict[str, MetadataType] property

The metadata property in lazy loading mode.

Returns:

Type Description
Dict[str, MetadataType]

getter of lazy responses for internal use.

Functions
get_body() -> None

Protects from misuse of the lazy loader.

Raises:

Type Description
RuntimeError

always

Source code in src/zenml/models/v2/core/artifact_version.py
722
723
724
725
726
727
728
def get_body(self) -> None:  # type: ignore[override]
    """Protects from misuse of the lazy loader.

    Raises:
        RuntimeError: always
    """
    raise RuntimeError("Cannot access artifact body before pipeline runs.")
get_metadata() -> None

Protects from misuse of the lazy loader.

Raises:

Type Description
RuntimeError

always

Source code in src/zenml/models/v2/core/artifact_version.py
730
731
732
733
734
735
736
737
738
def get_metadata(self) -> None:  # type: ignore[override]
    """Protects from misuse of the lazy loader.

    Raises:
        RuntimeError: always
    """
    raise RuntimeError(
        "Cannot access artifact metadata before pipeline runs."
    )
Functions
artifact_visualization

Models representing artifact visualizations.

Classes
ArtifactVisualizationRequest

Bases: BaseRequest

Request model for artifact visualization.

ArtifactVisualizationResponse

Bases: BaseIdentifiedResponse[ArtifactVisualizationResponseBody, ArtifactVisualizationResponseMetadata, ArtifactVisualizationResponseResources]

Response model for artifact visualizations.

Attributes
artifact_version_id: UUID property

The artifact_version_id property.

Returns:

Type Description
UUID

the value of the property.

type: VisualizationType property

The type property.

Returns:

Type Description
VisualizationType

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ArtifactVisualizationResponse

Get the hydrated version of this artifact visualization.

Returns:

Type Description
ArtifactVisualizationResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/artifact_visualization.py
70
71
72
73
74
75
76
77
78
def get_hydrated_version(self) -> "ArtifactVisualizationResponse":
    """Get the hydrated version of this artifact visualization.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_artifact_visualization(self.id)
ArtifactVisualizationResponseBody

Bases: BaseDatedResponseBody

Response body for artifact visualizations.

ArtifactVisualizationResponseMetadata

Bases: BaseResponseMetadata

Response metadata model for artifact visualizations.

ArtifactVisualizationResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the artifact visualization.

code_reference

Models representing code references.

Classes
CodeReferenceRequest

Bases: BaseRequest

Request model for code references.

CodeReferenceResponse

Bases: BaseIdentifiedResponse[CodeReferenceResponseBody, CodeReferenceResponseMetadata, CodeReferenceResponseResources]

Response model for code references.

Attributes
code_repository: CodeRepositoryResponse property

The code_repository property.

Returns:

Type Description
CodeRepositoryResponse

the value of the property.

commit: str property

The commit property.

Returns:

Type Description
str

the value of the property.

subdirectory: str property

The subdirectory property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> CodeReferenceResponse

Get the hydrated version of this code reference.

Returns:

Type Description
CodeReferenceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/code_reference.py
85
86
87
88
89
90
91
92
93
def get_hydrated_version(self) -> "CodeReferenceResponse":
    """Get the hydrated version of this code reference.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_code_reference(self.id)
CodeReferenceResponseBody

Bases: BaseDatedResponseBody

Response body for code references.

CodeReferenceResponseMetadata

Bases: BaseResponseMetadata

Response metadata for code references.

CodeReferenceResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the code reference entity.

code_repository

Models representing code repositories.

Classes
CodeRepositoryFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all code repositories.

CodeRepositoryRequest

Bases: WorkspaceScopedRequest

Request model for code repositories.

CodeRepositoryResponse

Bases: WorkspaceScopedResponse[CodeRepositoryResponseBody, CodeRepositoryResponseMetadata, CodeRepositoryResponseResources]

Response model for code repositories.

Attributes
config: Dict[str, Any] property

The config property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

source: Source property

The source property.

Returns:

Type Description
Source

the value of the property.

Functions
get_hydrated_version() -> CodeRepositoryResponse

Get the hydrated version of this code repository.

Returns:

Type Description
CodeRepositoryResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/code_repository.py
133
134
135
136
137
138
139
140
141
def get_hydrated_version(self) -> "CodeRepositoryResponse":
    """Get the hydrated version of this code repository.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_code_repository(self.id)
CodeRepositoryResponseBody

Bases: WorkspaceScopedResponseBody

Response body for code repositories.

CodeRepositoryResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for code repositories.

CodeRepositoryResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the code repository entity.

CodeRepositoryUpdate

Bases: BaseUpdate

Update model for code repositories.

component

Models representing components.

Classes
ComponentBase

Bases: BaseModel

Base model for components.

ComponentFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all ComponentModels.

The Component Model needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Stack components can be scoped by type to narrow the search.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Source code in src/zenml/models/v2/core/component.py
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Stack components can be scoped by type to narrow the search.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.
    """
    from sqlmodel import and_, or_

    from zenml.zen_stores.schemas import (
        StackComponentSchema,
        StackCompositionSchema,
    )

    base_filter = super().generate_filter(table)
    if self.scope_type:
        type_filter = getattr(table, "type") == self.scope_type
        return and_(base_filter, type_filter)

    if self.stack_id:
        operator = (
            or_ if self.logical_operator == LogicalOperators.OR else and_
        )

        stack_filter = and_(
            StackCompositionSchema.stack_id == self.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
        )
        base_filter = operator(base_filter, stack_filter)

    return base_filter
set_scope_type(component_type: str) -> None

Set the type of component on which to perform the filtering to scope the response.

Parameters:

Name Type Description Default
component_type str

The type of component to scope the query to.

required
Source code in src/zenml/models/v2/core/component.py
394
395
396
397
398
399
400
def set_scope_type(self, component_type: str) -> None:
    """Set the type of component on which to perform the filtering to scope the response.

    Args:
        component_type: The type of component to scope the query to.
    """
    self.scope_type = component_type
ComponentRequest

Bases: ComponentBase, WorkspaceScopedRequest

Request model for components.

Functions
name_cant_be_a_secret_reference(name: str) -> str classmethod

Validator to ensure that the given name is not a secret reference.

Parameters:

Name Type Description Default
name str

The name to validate.

required

Returns:

Type Description
str

The name if it is not a secret reference.

Raises:

Type Description
ValueError

If the name is a secret reference.

Source code in src/zenml/models/v2/core/component.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@field_validator("name")
@classmethod
def name_cant_be_a_secret_reference(cls, name: str) -> str:
    """Validator to ensure that the given name is not a secret reference.

    Args:
        name: The name to validate.

    Returns:
        The name if it is not a secret reference.

    Raises:
        ValueError: If the name is a secret reference.
    """
    if secret_utils.is_secret_reference(name):
        raise ValueError(
            "Passing the `name` attribute of a stack component as a "
            "secret reference is not allowed."
        )
    return name
ComponentResponse

Bases: WorkspaceScopedResponse[ComponentResponseBody, ComponentResponseMetadata, ComponentResponseResources]

Response model for components.

Attributes
configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector: Optional[ServiceConnectorResponse] property

The connector property.

Returns:

Type Description
Optional[ServiceConnectorResponse]

the value of the property.

connector_resource_id: Optional[str] property

The connector_resource_id property.

Returns:

Type Description
Optional[str]

the value of the property.

flavor: FlavorResponse property

The flavor property.

Returns:

Type Description
FlavorResponse

the value of the property.

flavor_name: str property

The flavor_name property.

Returns:

Type Description
str

the value of the property.

integration: Optional[str] property

The integration property.

Returns:

Type Description
Optional[str]

the value of the property.

labels: Optional[Dict[str, Any]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

type: StackComponentType property

The type property.

Returns:

Type Description
StackComponentType

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the component labels to analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/component.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the component labels to analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    if self.labels is not None:
        metadata.update(
            {
                label[6:]: value
                for label, value in self.labels.items()
                if label.startswith("zenml:")
            }
        )
    metadata["flavor"] = self.flavor_name

    return metadata
get_hydrated_version() -> ComponentResponse

Get the hydrated version of this component.

Returns:

Type Description
ComponentResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/component.py
253
254
255
256
257
258
259
260
261
def get_hydrated_version(self) -> "ComponentResponse":
    """Get the hydrated version of this component.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_stack_component(self.id)
ComponentResponseBody

Bases: WorkspaceScopedResponseBody

Response body for components.

ComponentResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for components.

ComponentResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the component entity.

ComponentUpdate

Bases: BaseUpdate

Update model for stack components.

InternalComponentRequest

Bases: ComponentRequest

Internal component request model.

Modules
device

Models representing devices.

Classes
OAuthDeviceFilter

Bases: UserScopedFilter

Model to enable advanced filtering of OAuth2 devices.

OAuthDeviceInternalRequest

Bases: BaseRequest

Internal request model for OAuth2 devices.

OAuthDeviceInternalResponse

Bases: OAuthDeviceResponse

OAuth2 device response model used internally for authentication.

Functions
verify_device_code(device_code: str) -> bool

Verifies a given device code against the stored (hashed) device code.

Parameters:

Name Type Description Default
device_code str

The device code to verify.

required

Returns:

Type Description
bool

True if the device code is valid, False otherwise.

Source code in src/zenml/models/v2/core/device.py
421
422
423
424
425
426
427
428
429
430
431
432
433
def verify_device_code(
    self,
    device_code: str,
) -> bool:
    """Verifies a given device code against the stored (hashed) device code.

    Args:
        device_code: The device code to verify.

    Returns:
        True if the device code is valid, False otherwise.
    """
    return self._verify_code(device_code, self.device_code)
verify_user_code(user_code: str) -> bool

Verifies a given user code against the stored (hashed) user code.

Parameters:

Name Type Description Default
user_code str

The user code to verify.

required

Returns:

Type Description
bool

True if the user code is valid, False otherwise.

Source code in src/zenml/models/v2/core/device.py
407
408
409
410
411
412
413
414
415
416
417
418
419
def verify_user_code(
    self,
    user_code: str,
) -> bool:
    """Verifies a given user code against the stored (hashed) user code.

    Args:
        user_code: The user code to verify.

    Returns:
        True if the user code is valid, False otherwise.
    """
    return self._verify_code(user_code, self.user_code)
OAuthDeviceInternalUpdate

Bases: OAuthDeviceUpdate

OAuth2 device update model used internally for authentication.

OAuthDeviceResponse

Bases: UserScopedResponse[OAuthDeviceResponseBody, OAuthDeviceResponseMetadata, OAuthDeviceResponseResources]

Response model for OAuth2 devices.

Attributes
city: Optional[str] property

The city property.

Returns:

Type Description
Optional[str]

the value of the property.

client_id: UUID property

The client_id property.

Returns:

Type Description
UUID

the value of the property.

country: Optional[str] property

The country property.

Returns:

Type Description
Optional[str]

the value of the property.

expires: Optional[datetime] property

The expires property.

Returns:

Type Description
Optional[datetime]

the value of the property.

failed_auth_attempts: int property

The failed_auth_attempts property.

Returns:

Type Description
int

the value of the property.

hostname: Optional[str] property

The hostname property.

Returns:

Type Description
Optional[str]

the value of the property.

ip_address: Optional[str] property

The ip_address property.

Returns:

Type Description
Optional[str]

the value of the property.

last_login: Optional[datetime] property

The last_login property.

Returns:

Type Description
Optional[datetime]

the value of the property.

os: Optional[str] property

The os property.

Returns:

Type Description
Optional[str]

the value of the property.

python_version: Optional[str] property

The python_version property.

Returns:

Type Description
Optional[str]

the value of the property.

region: Optional[str] property

The region property.

Returns:

Type Description
Optional[str]

the value of the property.

status: OAuthDeviceStatus property

The status property.

Returns:

Type Description
OAuthDeviceStatus

the value of the property.

trusted_device: bool property

The trusted_device property.

Returns:

Type Description
bool

the value of the property.

zenml_version: Optional[str] property

The zenml_version property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_hydrated_version() -> OAuthDeviceResponse

Get the hydrated version of this OAuth2 device.

Returns:

Type Description
OAuthDeviceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/device.py
240
241
242
243
244
245
246
247
248
def get_hydrated_version(self) -> "OAuthDeviceResponse":
    """Get the hydrated version of this OAuth2 device.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_authorized_device(self.id)
OAuthDeviceResponseBody

Bases: UserScopedResponseBody

Response body for OAuth2 devices.

OAuthDeviceResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for OAuth2 devices.

OAuthDeviceResponseResources

Bases: UserScopedResponseResources

Class for all resource models associated with the OAuthDevice entity.

OAuthDeviceUpdate

Bases: BaseModel

OAuth2 device update model.

event_source

Collection of all models concerning event configurations.

Classes
EventSourceFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all EventSourceModels.

EventSourceRequest

Bases: WorkspaceScopedRequest

BaseModel for all event sources.

EventSourceResponse

Bases: WorkspaceScopedResponse[EventSourceResponseBody, EventSourceResponseMetadata, EventSourceResponseResources]

Response model for event sources.

Attributes
configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

flavor: str property

The flavor property.

Returns:

Type Description
str

the value of the property.

is_active: bool property

The is_active property.

Returns:

Type Description
bool

the value of the property.

plugin_subtype: PluginSubType property

The plugin_subtype property.

Returns:

Type Description
PluginSubType

the value of the property.

Functions
get_hydrated_version() -> EventSourceResponse

Get the hydrated version of this event source.

Returns:

Type Description
EventSourceResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/event_source.py
161
162
163
164
165
166
167
168
169
def get_hydrated_version(self) -> "EventSourceResponse":
    """Get the hydrated version of this event source.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_event_source(self.id)
set_configuration(configuration: Dict[str, Any]) -> None

Set the configuration property.

Parameters:

Name Type Description Default
configuration Dict[str, Any]

The value to set.

required
Source code in src/zenml/models/v2/core/event_source.py
217
218
219
220
221
222
223
def set_configuration(self, configuration: Dict[str, Any]) -> None:
    """Set the `configuration` property.

    Args:
        configuration: The value to set.
    """
    self.get_metadata().configuration = configuration
EventSourceResponseBody

Bases: WorkspaceScopedResponseBody

ResponseBody for event sources.

EventSourceResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for event sources.

EventSourceResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the code repository entity.

EventSourceUpdate

Bases: BaseZenModel

Update model for event sources.

Functions
from_response(response: EventSourceResponse) -> EventSourceUpdate classmethod

Create an update model from a response model.

Parameters:

Name Type Description Default
response EventSourceResponse

The response model to create the update model from.

required

Returns:

Type Description
EventSourceUpdate

The update model.

Source code in src/zenml/models/v2/core/event_source.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def from_response(
    cls, response: "EventSourceResponse"
) -> "EventSourceUpdate":
    """Create an update model from a response model.

    Args:
        response: The response model to create the update model from.

    Returns:
        The update model.
    """
    return EventSourceUpdate(
        name=response.name,
        description=response.description,
        configuration=copy.deepcopy(response.configuration),
        is_active=response.is_active,
    )
event_source_flavor

Models representing event source flavors..

Classes
EventSourceFlavorResponse

Bases: BasePluginFlavorResponse[EventSourceFlavorResponseBody, EventSourceFlavorResponseMetadata, EventSourceFlavorResponseResources]

Response model for Event Source Flavors.

Attributes
filter_config_schema: Dict[str, Any] property

The filter_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

source_config_schema: Dict[str, Any] property

The source_config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

EventSourceFlavorResponseBody

Bases: BasePluginResponseBody

Response body for event flavors.

EventSourceFlavorResponseMetadata

Bases: BasePluginResponseMetadata

Response metadata for event flavors.

EventSourceFlavorResponseResources

Bases: BasePluginResponseResources

Response resources for event source flavors.

flavor

Models representing flavors.

Classes
FlavorFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Flavors.

FlavorRequest

Bases: UserScopedRequest

Request model for flavors.

FlavorResponse

Bases: UserScopedResponse[FlavorResponseBody, FlavorResponseMetadata, FlavorResponseResources]

Response model for flavors.

Attributes
config_schema: Dict[str, Any] property

The config_schema property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector_requirements: Optional[ServiceConnectorRequirements] property

Returns the connector requirements for the flavor.

Returns:

Type Description
Optional[ServiceConnectorRequirements]

The connector requirements for the flavor.

connector_resource_id_attr: Optional[str] property

The connector_resource_id_attr property.

Returns:

Type Description
Optional[str]

the value of the property.

connector_resource_type: Optional[str] property

The connector_resource_type property.

Returns:

Type Description
Optional[str]

the value of the property.

connector_type: Optional[str] property

The connector_type property.

Returns:

Type Description
Optional[str]

the value of the property.

docs_url: Optional[str] property

The docs_url property.

Returns:

Type Description
Optional[str]

the value of the property.

integration: Optional[str] property

The integration property.

Returns:

Type Description
Optional[str]

the value of the property.

is_custom: bool property

The is_custom property.

Returns:

Type Description
bool

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

sdk_docs_url: Optional[str] property

The sdk_docs_url property.

Returns:

Type Description
Optional[str]

the value of the property.

source: str property

The source property.

Returns:

Type Description
str

the value of the property.

type: StackComponentType property

The type property.

Returns:

Type Description
StackComponentType

the value of the property.

workspace: Optional[WorkspaceResponse] property

The workspace property.

Returns:

Type Description
Optional[WorkspaceResponse]

the value of the property.

Functions
get_hydrated_version() -> FlavorResponse

Get the hydrated version of the flavor.

Returns:

Type Description
FlavorResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/flavor.py
270
271
272
273
274
275
276
277
278
def get_hydrated_version(self) -> "FlavorResponse":
    """Get the hydrated version of the flavor.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_flavor(self.id)
FlavorResponseBody

Bases: UserScopedResponseBody

Response body for flavor.

FlavorResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for flavors.

FlavorResponseResources

Bases: UserScopedResponseResources

Class for all resource models associated with the flavor entity.

FlavorUpdate

Bases: BaseUpdate

Update model for flavors.

InternalFlavorRequest

Bases: FlavorRequest

Internal flavor request model.

logs

Models representing logs.

Classes
LogsRequest

Bases: BaseRequest

Request model for logs.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@field_validator("artifact_store_id")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {STR_FIELD_MAX_LENGTH}"
    )
    return value
text_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@field_validator("uri")
@classmethod
def text_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < TEXT_FIELD_MAX_LENGTH, (
        "The length of the value for this field can not "
        f"exceed {TEXT_FIELD_MAX_LENGTH}"
    )
    return value
LogsResponse

Bases: BaseIdentifiedResponse[LogsResponseBody, LogsResponseMetadata, LogsResponseResources]

Response model for logs.

Attributes
artifact_store_id: Union[str, UUID] property

The artifact_store_id property.

Returns:

Type Description
Union[str, UUID]

the value of the property.

pipeline_run_id: Optional[Union[str, UUID]] property

The pipeline_run_id property.

Returns:

Type Description
Optional[Union[str, UUID]]

the value of the property.

step_run_id: Optional[Union[str, UUID]] property

The step_run_id property.

Returns:

Type Description
Optional[Union[str, UUID]]

the value of the property.

uri: str property

The uri property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> LogsResponse

Get the hydrated version of these logs.

Returns:

Type Description
LogsResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/logs.py
152
153
154
155
156
157
158
159
160
def get_hydrated_version(self) -> "LogsResponse":
    """Get the hydrated version of these logs.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_logs(self.id)
LogsResponseBody

Bases: BaseDatedResponseBody

Response body for logs.

LogsResponseMetadata

Bases: BaseResponseMetadata

Response metadata for logs.

Functions
str_field_max_length_check(value: Any) -> Any classmethod

Checks if the length of the value exceeds the maximum text length.

Parameters:

Name Type Description Default
value Any

the value set in the field

required

Returns:

Type Description
Any

the value itself.

Raises:

Type Description
AssertionError

if the length of the field is longer than the maximum threshold.

Source code in src/zenml/models/v2/core/logs.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@field_validator("artifact_store_id")
@classmethod
def str_field_max_length_check(cls, value: Any) -> Any:
    """Checks if the length of the value exceeds the maximum text length.

    Args:
        value: the value set in the field

    Returns:
        the value itself.

    Raises:
        AssertionError: if the length of the field is longer than the
            maximum threshold.
    """
    assert len(str(value)) < STR_FIELD_MAX_LENGTH
    return value
LogsResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the Logs entity.

model

Models representing models.

Classes
ModelFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of all Workspaces.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query for Models.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/model.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query for Models.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == SORT_BY_LATEST_VERSION_KEY:
        # Subquery to find the latest version per model
        latest_version_subquery = (
            select(
                ModelSchema.id,
                case(
                    (
                        func.max(ModelVersionSchema.created).is_(None),
                        ModelSchema.created,
                    ),
                    else_=func.max(ModelVersionSchema.created),
                ).label("latest_version_created"),
            )
            .outerjoin(
                ModelVersionSchema,
                ModelSchema.id == ModelVersionSchema.model_id,  # type: ignore[arg-type]
            )
            .group_by(col(ModelSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_version_subquery.c.latest_version_created,
        ).where(ModelSchema.id == latest_version_subquery.c.id)

        # Apply sorting based on the operand
        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_version_subquery.c.latest_version_created),
                asc(ModelSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_version_subquery.c.latest_version_created),
                desc(ModelSchema.id),
            )
        return query

    # For other sorting cases, delegate to the parent class
    return super().apply_sorting(query=query, table=table)
ModelRequest

Bases: WorkspaceScopedRequest

Request model for models.

ModelResponse

Bases: WorkspaceScopedResponse[ModelResponseBody, ModelResponseMetadata, ModelResponseResources]

Response model for models.

Attributes
audience: Optional[str] property

The audience property.

Returns:

Type Description
Optional[str]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

ethics: Optional[str] property

The ethics property.

Returns:

Type Description
Optional[str]

the value of the property.

latest_version_id: Optional[UUID] property

The latest_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_version_name: Optional[str] property

The latest_version_name property.

Returns:

Type Description
Optional[str]

the value of the property.

license: Optional[str] property

The license property.

Returns:

Type Description
Optional[str]

the value of the property.

limitations: Optional[str] property

The limitations property.

Returns:

Type Description
Optional[str]

the value of the property.

save_models_to_registry: bool property

The save_models_to_registry property.

Returns:

Type Description
bool

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

trade_offs: Optional[str] property

The trade_offs property.

Returns:

Type Description
Optional[str]

the value of the property.

use_cases: Optional[str] property

The use_cases property.

Returns:

Type Description
Optional[str]

the value of the property.

versions: List[Model] property

List all versions of the model.

Returns:

Type Description
List[Model]

The list of all model version.

Functions
get_hydrated_version() -> ModelResponse

Get the hydrated version of this model.

Returns:

Type Description
ModelResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/model.py
193
194
195
196
197
198
199
200
201
def get_hydrated_version(self) -> "ModelResponse":
    """Get the hydrated version of this model.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_model(self.id)
ModelResponseBody

Bases: WorkspaceScopedResponseBody

Response body for models.

ModelResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for models.

ModelResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the model entity.

ModelUpdate

Bases: BaseModel

Update model for models.

Functions
model_version

Models representing model versions.

Classes
ModelVersionFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Filter model for model versions.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/model_version.py
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)

    if self._model_id:
        query = query.where(getattr(table, "model_id") == self._model_id)

    return query
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version.py
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelVersionSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
    )

    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == ModelVersionSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.MODEL_VERSION,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters
set_scope_model(model_name_or_id: Union[str, UUID]) -> None

Set the model to scope this response.

Parameters:

Name Type Description Default
model_name_or_id Union[str, UUID]

The model to scope this response to.

required
Source code in src/zenml/models/v2/core/model_version.py
608
609
610
611
612
613
614
615
616
617
618
619
620
621
def set_scope_model(self, model_name_or_id: Union[str, UUID]) -> None:
    """Set the model to scope this response.

    Args:
        model_name_or_id: The model to scope this response to.
    """
    try:
        model_id = UUID(str(model_name_or_id))
    except ValueError:
        from zenml.client import Client

        model_id = Client().get_model(model_name_or_id).id

    self._model_id = model_id
ModelVersionRequest

Bases: WorkspaceScopedRequest

Request model for model versions.

ModelVersionResponse

Bases: WorkspaceScopedResponse[ModelVersionResponseBody, ModelVersionResponseMetadata, ModelVersionResponseResources]

Response model for model versions.

Attributes
data_artifact_ids: Dict[str, Dict[str, UUID]] property

The data_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

data_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all data artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of data artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

deployment_artifact_ids: Dict[str, Dict[str, UUID]] property

The deployment_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

deployment_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all deployment artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of deployment artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

model: ModelResponse property

The model property.

Returns:

Type Description
ModelResponse

the value of the property.

model_artifact_ids: Dict[str, Dict[str, UUID]] property

The model_artifact_ids property.

Returns:

Type Description
Dict[str, Dict[str, UUID]]

the value of the property.

model_artifacts: Dict[str, Dict[str, ArtifactVersionResponse]] property

Get all model artifacts linked to this model version.

Returns:

Type Description
Dict[str, Dict[str, ArtifactVersionResponse]]

Dictionary of model artifacts with versions as

Dict[str, Dict[str, ArtifactVersionResponse]]

Dict[str, Dict[str, ArtifactResponse]]

number: int property

The number property.

Returns:

Type Description
int

the value of the property.

pipeline_run_ids: Dict[str, UUID] property

The pipeline_run_ids property.

Returns:

Type Description
Dict[str, UUID]

the value of the property.

pipeline_runs: Dict[str, PipelineRunResponse] property

Get all pipeline runs linked to this version.

Returns:

Type Description
Dict[str, PipelineRunResponse]

Dictionary of Pipeline Runs as PipelineRunResponseModel

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

stage: Optional[str] property

The stage property.

Returns:

Type Description
Optional[str]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the artifact to retrieve.

required
version Optional[str]

The version of the artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of an artifact or None

Source code in src/zenml/models/v2/core/model_version.py
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
def get_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the artifact linked to this model version.

    Args:
        name: The name of the artifact to retrieve.
        version: The version of the artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of an artifact or None
    """
    return self._get_linked_object(name, version)
get_data_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the data artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the data artifact to retrieve.

required
version Optional[str]

The version of the data artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the data artifact or None

Source code in src/zenml/models/v2/core/model_version.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
def get_data_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the data artifact linked to this model version.

    Args:
        name: The name of the data artifact to retrieve.
        version: The version of the data artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the data artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.DATA)
get_deployment_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the deployment artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the deployment artifact to retrieve.

required
version Optional[str]

The version of the deployment artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the deployment artifact or None

Source code in src/zenml/models/v2/core/model_version.py
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
def get_deployment_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the deployment artifact linked to this model version.

    Args:
        name: The name of the deployment artifact to retrieve.
        version: The version of the deployment artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the deployment artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.SERVICE)
get_hydrated_version() -> ModelVersionResponse

Get the hydrated version of this model version.

Returns:

Type Description
ModelVersionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/model_version.py
310
311
312
313
314
315
316
317
318
def get_hydrated_version(self) -> "ModelVersionResponse":
    """Get the hydrated version of this model version.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_model_version(self.id)
get_model_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]

Get the model artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the model artifact to retrieve.

required
version Optional[str]

The version of the model artifact to retrieve (None for latest/non-versioned)

None

Returns:

Type Description
Optional[ArtifactVersionResponse]

Specific version of the model artifact or None

Source code in src/zenml/models/v2/core/model_version.py
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
def get_model_artifact(
    self,
    name: str,
    version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
    """Get the model artifact linked to this model version.

    Args:
        name: The name of the model artifact to retrieve.
        version: The version of the model artifact to retrieve (None for
            latest/non-versioned)

    Returns:
        Specific version of the model artifact or None
    """
    return self._get_linked_object(name, version, ArtifactType.MODEL)
get_pipeline_run(name: str) -> PipelineRunResponse

Get pipeline run linked to this version.

Parameters:

Name Type Description Default
name str

The name of the pipeline run to retrieve.

required

Returns:

Type Description
PipelineRunResponse

PipelineRun as PipelineRunResponseModel

Source code in src/zenml/models/v2/core/model_version.py
528
529
530
531
532
533
534
535
536
537
538
539
def get_pipeline_run(self, name: str) -> "PipelineRunResponse":
    """Get pipeline run linked to this version.

    Args:
        name: The name of the pipeline run to retrieve.

    Returns:
        PipelineRun as PipelineRunResponseModel
    """
    from zenml.client import Client

    return Client().get_pipeline_run(self.pipeline_run_ids[name])
set_stage(stage: Union[str, ModelStages], force: bool = False) -> None

Sets this Model Version to a desired stage.

Parameters:

Name Type Description Default
stage Union[str, ModelStages]

the target stage for model version.

required
force bool

whether to force archiving of current model version in target stage or raise.

False

Raises:

Type Description
ValueError

if model_stage is not valid.

Source code in src/zenml/models/v2/core/model_version.py
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
def set_stage(
    self, stage: Union[str, ModelStages], force: bool = False
) -> None:
    """Sets this Model Version to a desired stage.

    Args:
        stage: the target stage for model version.
        force: whether to force archiving of current model version in
            target stage or raise.

    Raises:
        ValueError: if model_stage is not valid.
    """
    from zenml.client import Client

    stage = getattr(stage, "value", stage)
    if stage not in [stage.value for stage in ModelStages]:
        raise ValueError(f"`{stage}` is not a valid model stage.")

    Client().update_model_version(
        model_name_or_id=self.model.id,
        version_name_or_id=self.id,
        stage=stage,
        force=force,
    )
to_model_class(suppress_class_validation_warnings: bool = True) -> Model

Convert response model to Model object.

Parameters:

Name Type Description Default
suppress_class_validation_warnings bool

internally used to suppress repeated warnings.

True

Returns:

Type Description
Model

Model object

Source code in src/zenml/models/v2/core/model_version.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def to_model_class(
    self,
    suppress_class_validation_warnings: bool = True,
) -> "Model":
    """Convert response model to Model object.

    Args:
        suppress_class_validation_warnings: internally used to suppress
            repeated warnings.

    Returns:
        Model object
    """
    from zenml.model.model import Model

    mv = Model(
        name=self.model.name,
        license=self.model.license,
        description=self.description,
        audience=self.model.audience,
        use_cases=self.model.use_cases,
        limitations=self.model.limitations,
        trade_offs=self.model.trade_offs,
        ethics=self.model.ethics,
        tags=[t.name for t in self.tags],
        version=self.name,
        suppress_class_validation_warnings=suppress_class_validation_warnings,
        model_version_id=self.id,
    )

    return mv
ModelVersionResponseBody

Bases: WorkspaceScopedResponseBody

Response body for model versions.

ModelVersionResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for model versions.

ModelVersionResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the model version entity.

ModelVersionUpdate

Bases: BaseModel

Update model for model versions.

model_version_artifact

Models representing the link between model versions and artifacts.

Classes
ModelVersionArtifactFilter

Bases: BaseFilter

Model version pipeline run links filter model.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[Union[ColumnElement[bool]]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[Union[ColumnElement[bool]]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version_artifact.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List[Union["ColumnElement[bool]"]]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, col

    from zenml.zen_stores.schemas import (
        ArtifactSchema,
        ArtifactVersionSchema,
        ModelVersionArtifactSchema,
        UserSchema,
    )

    if self.artifact_name:
        value, filter_operator = self._resolve_operator(self.artifact_name)
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        artifact_name_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            filter_.generate_query_conditions(ArtifactSchema),
        )
        custom_filters.append(artifact_name_filter)

    if self.only_data_artifacts:
        data_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            col(ArtifactVersionSchema.type).not_in(
                ["ServiceArtifact", "ModelArtifact"]
            ),
        )
        custom_filters.append(data_artifact_filter)

    if self.only_model_artifacts:
        model_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.type == "ModelArtifact",
        )
        custom_filters.append(model_artifact_filter)

    if self.only_deployment_artifacts:
        deployment_artifact_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.type == "ServiceArtifact",
        )
        custom_filters.append(deployment_artifact_filter)

    if self.has_custom_name is not None:
        custom_name_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            ArtifactSchema.has_custom_name == self.has_custom_name,
        )
        custom_filters.append(custom_name_filter)

    if self.user:
        user_filter = and_(
            ModelVersionArtifactSchema.artifact_version_id
            == ArtifactVersionSchema.id,
            ArtifactVersionSchema.user_id == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters
ModelVersionArtifactRequest

Bases: BaseRequest

Request model for links between model versions and artifacts.

ModelVersionArtifactResponse

Bases: BaseIdentifiedResponse[ModelVersionArtifactResponseBody, BaseResponseMetadata, ModelVersionArtifactResponseResources]

Response model for links between model versions and artifacts.

Attributes
artifact_version: ArtifactVersionResponse property

The artifact_version property.

Returns:

Type Description
ArtifactVersionResponse

the value of the property.

model_version: UUID property

The model_version property.

Returns:

Type Description
UUID

the value of the property.

ModelVersionArtifactResponseBody

Bases: BaseDatedResponseBody

Response body for links between model versions and artifacts.

ModelVersionArtifactResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the model version artifact entity.

model_version_pipeline_run

Models representing the link between model versions and pipeline runs.

Classes
ModelVersionPipelineRunFilter

Bases: BaseFilter

Model version pipeline run links filter model.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/model_version_pipeline_run.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelVersionPipelineRunSchema,
        PipelineRunSchema,
        UserSchema,
    )

    if self.pipeline_run_name:
        value, filter_operator = self._resolve_operator(
            self.pipeline_run_name
        )
        filter_ = StrFilter(
            operation=GenericFilterOps(filter_operator),
            column="name",
            value=value,
        )
        pipeline_run_name_filter = and_(
            ModelVersionPipelineRunSchema.pipeline_run_id
            == PipelineRunSchema.id,
            filter_.generate_query_conditions(PipelineRunSchema),
        )
        custom_filters.append(pipeline_run_name_filter)

    if self.user:
        user_filter = and_(
            ModelVersionPipelineRunSchema.pipeline_run_id
            == PipelineRunSchema.id,
            PipelineRunSchema.user_id == UserSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.user,
                table=UserSchema,
                additional_columns=["full_name"],
            ),
        )
        custom_filters.append(user_filter)

    return custom_filters
ModelVersionPipelineRunRequest

Bases: BaseRequest

Request model for links between model versions and pipeline runs.

ModelVersionPipelineRunResponse

Bases: BaseIdentifiedResponse[ModelVersionPipelineRunResponseBody, BaseResponseMetadata, ModelVersionPipelineRunResponseResources]

Response model for links between model versions and pipeline runs.

Attributes
model_version: UUID property

The model_version property.

Returns:

Type Description
UUID

the value of the property.

pipeline_run: PipelineRunResponse property

The pipeline_run property.

Returns:

Type Description
PipelineRunResponse

the value of the property.

ModelVersionPipelineRunResponseBody

Bases: BaseDatedResponseBody

Response body for links between model versions and pipeline runs.

ModelVersionPipelineRunResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the model version pipeline run entity.

pipeline

Models representing pipelines.

Classes
PipelineFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Pipeline filter model.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Applies the filter to a query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/pipeline.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def apply_filter(
    self, query: AnyQuery, table: Type["AnySchema"]
) -> AnyQuery:
    """Applies the filter to a query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query, table)

    from sqlmodel import and_, col, func, select

    from zenml.zen_stores.schemas import PipelineRunSchema, PipelineSchema

    if self.latest_run_status:
        latest_pipeline_run_subquery = (
            select(
                PipelineRunSchema.pipeline_id,
                func.max(PipelineRunSchema.created).label("created"),
            )
            .where(col(PipelineRunSchema.pipeline_id).is_not(None))
            .group_by(col(PipelineRunSchema.pipeline_id))
            .subquery()
        )

        query = (
            query.join(
                PipelineRunSchema,
                PipelineSchema.id == PipelineRunSchema.pipeline_id,
            )
            .join(
                latest_pipeline_run_subquery,
                and_(
                    PipelineRunSchema.pipeline_id
                    == latest_pipeline_run_subquery.c.pipeline_id,
                    PipelineRunSchema.created
                    == latest_pipeline_run_subquery.c.created,
                ),
            )
            .where(
                self.generate_custom_query_conditions_for_column(
                    value=self.latest_run_status,
                    table=PipelineRunSchema,
                    column="status",
                )
            )
        )

    return query
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/pipeline.py
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, case, col, desc, func, select

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import PipelineRunSchema, PipelineSchema

    sort_by, operand = self.sorting_params

    if sort_by == SORT_PIPELINES_BY_LATEST_RUN_KEY:
        # Subquery to find the latest run per pipeline
        latest_run_subquery = (
            select(
                PipelineSchema.id,
                case(
                    (
                        func.max(PipelineRunSchema.created).is_(None),
                        PipelineSchema.created,
                    ),
                    else_=func.max(PipelineRunSchema.created),
                ).label("latest_run"),
            )
            .outerjoin(
                PipelineRunSchema,
                PipelineSchema.id == PipelineRunSchema.pipeline_id,  # type: ignore[arg-type]
            )
            .group_by(col(PipelineSchema.id))
            .subquery()
        )

        query = query.add_columns(
            latest_run_subquery.c.latest_run,
        ).where(PipelineSchema.id == latest_run_subquery.c.id)

        if operand == SorterOps.ASCENDING:
            query = query.order_by(
                asc(latest_run_subquery.c.latest_run),
                asc(PipelineSchema.id),
            )
        else:
            query = query.order_by(
                desc(latest_run_subquery.c.latest_run),
                desc(PipelineSchema.id),
            )
        return query
    else:
        return super().apply_sorting(query=query, table=table)
PipelineRequest

Bases: WorkspaceScopedRequest

Request model for pipelines.

PipelineResponse

Bases: WorkspaceScopedResponse[PipelineResponseBody, PipelineResponseMetadata, PipelineResponseResources]

Response model for pipelines.

Attributes
last_run: PipelineRunResponse property

Returns the last run of this pipeline.

Returns:

Type Description
PipelineRunResponse

The last run of this pipeline.

Raises:

Type Description
RuntimeError

If no runs were found for this pipeline.

last_successful_run: PipelineRunResponse property

Returns the last successful run of this pipeline.

Returns:

Type Description
PipelineRunResponse

The last successful run of this pipeline.

Raises:

Type Description
RuntimeError

If no successful runs were found for this pipeline.

latest_run_id: Optional[UUID] property

The latest_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_run_status: Optional[ExecutionStatus] property

The latest_run_status property.

Returns:

Type Description
Optional[ExecutionStatus]

the value of the property.

num_runs: int property

Returns the number of runs of this pipeline.

Returns:

Type Description
int

The number of runs of this pipeline.

runs: List[PipelineRunResponse] property

Returns the 20 most recent runs of this pipeline in descending order.

Returns:

Type Description
List[PipelineRunResponse]

The 20 most recent runs of this pipeline in descending order.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_hydrated_version() -> PipelineResponse

Get the hydrated version of this pipeline.

Returns:

Type Description
PipelineResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline.py
146
147
148
149
150
151
152
153
154
def get_hydrated_version(self) -> "PipelineResponse":
    """Get the hydrated version of this pipeline.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_pipeline(self.id)
get_runs(**kwargs: Any) -> List[PipelineRunResponse]

Get runs of this pipeline.

Can be used to fetch runs other than self.runs and supports fine-grained filtering and pagination.

Parameters:

Name Type Description Default
**kwargs Any

Further arguments for filtering or pagination that are passed to client.list_pipeline_runs().

{}

Returns:

Type Description
List[PipelineRunResponse]

List of runs of this pipeline.

Source code in src/zenml/models/v2/core/pipeline.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def get_runs(self, **kwargs: Any) -> List["PipelineRunResponse"]:
    """Get runs of this pipeline.

    Can be used to fetch runs other than `self.runs` and supports
    fine-grained filtering and pagination.

    Args:
        **kwargs: Further arguments for filtering or pagination that are
            passed to `client.list_pipeline_runs()`.

    Returns:
        List of runs of this pipeline.
    """
    from zenml.client import Client

    return Client().list_pipeline_runs(pipeline_id=self.id, **kwargs).items
PipelineResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipelines.

PipelineResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipelines.

PipelineResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline entity.

PipelineUpdate

Bases: BaseUpdate

Update model for pipelines.

pipeline_build

Models representing pipeline builds.

Classes
PipelineBuildBase

Bases: BaseZenModel

Base model for pipeline builds.

Attributes
requires_code_download: bool property

Whether the build requires code download.

Returns:

Type Description
bool

Whether the build requires code download.

Functions
get_image(component_key: str, step: Optional[str] = None) -> str

Get the image built for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the image.

required
step Optional[str]

The pipeline step for which to get the image. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
str

The image name or digest.

Source code in src/zenml/models/v2/core/pipeline_build.py
104
105
106
107
108
109
110
111
112
113
114
115
116
def get_image(self, component_key: str, step: Optional[str] = None) -> str:
    """Get the image built for a specific key.

    Args:
        component_key: The key for which to get the image.
        step: The pipeline step for which to get the image. If no image
            exists for this step, will fall back to the pipeline image for
            the same key.

    Returns:
        The image name or digest.
    """
    return self._get_item(component_key=component_key, step=step).image
get_image_key(component_key: str, step: Optional[str] = None) -> str staticmethod

Get the image key.

Parameters:

Name Type Description Default
component_key str

The component key.

required
step Optional[str]

The pipeline step for which the image was built.

None

Returns:

Type Description
str

The image key.

Source code in src/zenml/models/v2/core/pipeline_build.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@staticmethod
def get_image_key(component_key: str, step: Optional[str] = None) -> str:
    """Get the image key.

    Args:
        component_key: The component key.
        step: The pipeline step for which the image was built.

    Returns:
        The image key.
    """
    if step:
        return f"{step}.{component_key}"
    else:
        return component_key
get_settings_checksum(component_key: str, step: Optional[str] = None) -> Optional[str]

Get the settings checksum for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the checksum.

required
step Optional[str]

The pipeline step for which to get the checksum. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
Optional[str]

The settings checksum.

Source code in src/zenml/models/v2/core/pipeline_build.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def get_settings_checksum(
    self, component_key: str, step: Optional[str] = None
) -> Optional[str]:
    """Get the settings checksum for a specific key.

    Args:
        component_key: The key for which to get the checksum.
        step: The pipeline step for which to get the checksum. If no
            image exists for this step, will fall back to the pipeline image
            for the same key.

    Returns:
        The settings checksum.
    """
    return self._get_item(
        component_key=component_key, step=step
    ).settings_checksum
PipelineBuildFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all pipeline builds.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/pipeline_build.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
def get_custom_filters(
    self,
    table: Type["AnySchema"],
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.enums import StackComponentType
    from zenml.zen_stores.schemas import (
        PipelineBuildSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.container_registry_id:
        container_registry_filter = and_(
            PipelineBuildSchema.stack_id == StackSchema.id,
            StackSchema.id == StackCompositionSchema.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            StackComponentSchema.type
            == StackComponentType.CONTAINER_REGISTRY.value,
            StackComponentSchema.id == self.container_registry_id,
        )
        custom_filters.append(container_registry_filter)

    return custom_filters
PipelineBuildRequest

Bases: PipelineBuildBase, WorkspaceScopedRequest

Request model for pipelines builds.

PipelineBuildResponse

Bases: WorkspaceScopedResponse[PipelineBuildResponseBody, PipelineBuildResponseMetadata, PipelineBuildResponseResources]

Response model for pipeline builds.

Attributes
checksum: Optional[str] property

The checksum property.

Returns:

Type Description
Optional[str]

the value of the property.

contains_code: bool property

The contains_code property.

Returns:

Type Description
bool

the value of the property.

images: Dict[str, BuildItem] property

The images property.

Returns:

Type Description
Dict[str, BuildItem]

the value of the property.

is_local: bool property

The is_local property.

Returns:

Type Description
bool

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

python_version: Optional[str] property

The python_version property.

Returns:

Type Description
Optional[str]

the value of the property.

requires_code_download: bool property

Whether the build requires code download.

Returns:

Type Description
bool

Whether the build requires code download.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

stack_checksum: Optional[str] property

The stack_checksum property.

Returns:

Type Description
Optional[str]

the value of the property.

zenml_version: Optional[str] property

The zenml_version property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_hydrated_version() -> PipelineBuildResponse

Return the hydrated version of this pipeline build.

Returns:

Type Description
PipelineBuildResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_build.py
241
242
243
244
245
246
247
248
249
def get_hydrated_version(self) -> "PipelineBuildResponse":
    """Return the hydrated version of this pipeline build.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_build(self.id)
get_image(component_key: str, step: Optional[str] = None) -> str

Get the image built for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the image.

required
step Optional[str]

The pipeline step for which to get the image. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
str

The image name or digest.

Source code in src/zenml/models/v2/core/pipeline_build.py
309
310
311
312
313
314
315
316
317
318
319
320
321
def get_image(self, component_key: str, step: Optional[str] = None) -> str:
    """Get the image built for a specific key.

    Args:
        component_key: The key for which to get the image.
        step: The pipeline step for which to get the image. If no image
            exists for this step, will fall back to the pipeline image for
            the same key.

    Returns:
        The image name or digest.
    """
    return self._get_item(component_key=component_key, step=step).image
get_image_key(component_key: str, step: Optional[str] = None) -> str staticmethod

Get the image key.

Parameters:

Name Type Description Default
component_key str

The component key.

required
step Optional[str]

The pipeline step for which the image was built.

None

Returns:

Type Description
str

The image key.

Source code in src/zenml/models/v2/core/pipeline_build.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
@staticmethod
def get_image_key(component_key: str, step: Optional[str] = None) -> str:
    """Get the image key.

    Args:
        component_key: The component key.
        step: The pipeline step for which the image was built.

    Returns:
        The image key.
    """
    if step:
        return f"{step}.{component_key}"
    else:
        return component_key
get_settings_checksum(component_key: str, step: Optional[str] = None) -> Optional[str]

Get the settings checksum for a specific key.

Parameters:

Name Type Description Default
component_key str

The key for which to get the checksum.

required
step Optional[str]

The pipeline step for which to get the checksum. If no image exists for this step, will fall back to the pipeline image for the same key.

None

Returns:

Type Description
Optional[str]

The settings checksum.

Source code in src/zenml/models/v2/core/pipeline_build.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
def get_settings_checksum(
    self, component_key: str, step: Optional[str] = None
) -> Optional[str]:
    """Get the settings checksum for a specific key.

    Args:
        component_key: The key for which to get the checksum.
        step: The pipeline step for which to get the checksum. If no
            image exists for this step, will fall back to the pipeline image
            for the same key.

    Returns:
        The settings checksum.
    """
    return self._get_item(
        component_key=component_key, step=step
    ).settings_checksum
to_yaml() -> Dict[str, Any]

Create a yaml representation of the pipeline build.

Create a yaml representation of the pipeline build that can be used to create a PipelineBuildBase instance.

Returns:

Type Description
Dict[str, Any]

The yaml representation of the pipeline build.

Source code in src/zenml/models/v2/core/pipeline_build.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def to_yaml(self) -> Dict[str, Any]:
    """Create a yaml representation of the pipeline build.

    Create a yaml representation of the pipeline build that can be used
    to create a PipelineBuildBase instance.

    Returns:
        The yaml representation of the pipeline build.
    """
    # Get the base attributes
    yaml_dict: Dict[str, Any] = json.loads(
        self.model_dump_json(
            exclude={
                "body",
                "metadata",
            }
        )
    )
    images = json.loads(
        self.get_metadata().model_dump_json(
            exclude={
                "pipeline",
                "stack",
                "workspace",
            }
        )
    )
    yaml_dict.update(images)
    return yaml_dict
PipelineBuildResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline builds.

PipelineBuildResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline builds.

PipelineBuildResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline build entity.

pipeline_deployment

Models representing pipeline deployments.

Classes
PipelineDeploymentBase

Bases: BaseZenModel

Base model for pipeline deployments.

Attributes
should_prevent_build_reuse: bool property

Whether the deployment prevents a build reuse.

Returns:

Type Description
bool

Whether the deployment prevents a build reuse.

PipelineDeploymentFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all pipeline deployments.

PipelineDeploymentRequest

Bases: PipelineDeploymentBase, WorkspaceScopedRequest

Request model for pipeline deployments.

PipelineDeploymentResponse

Bases: WorkspaceScopedResponse[PipelineDeploymentResponseBody, PipelineDeploymentResponseMetadata, PipelineDeploymentResponseResources]

Response model for pipeline deployments.

Attributes
build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

client_environment: Dict[str, str] property

The client_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

client_version: Optional[str] property

The client_version property.

Returns:

Type Description
Optional[str]

the value of the property.

code_path: Optional[str] property

The code_path property.

Returns:

Type Description
Optional[str]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The code_reference property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

pipeline_configuration: PipelineConfiguration property

The pipeline_configuration property.

Returns:

Type Description
PipelineConfiguration

the value of the property.

pipeline_spec: Optional[PipelineSpec] property

The pipeline_spec property.

Returns:

Type Description
Optional[PipelineSpec]

the value of the property.

pipeline_version_hash: Optional[str] property

The pipeline_version_hash property.

Returns:

Type Description
Optional[str]

the value of the property.

run_name_template: str property

The run_name_template property.

Returns:

Type Description
str

the value of the property.

schedule: Optional[ScheduleResponse] property

The schedule property.

Returns:

Type Description
Optional[ScheduleResponse]

the value of the property.

server_version: Optional[str] property

The server_version property.

Returns:

Type Description
Optional[str]

the value of the property.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

step_configurations: Dict[str, Step] property

The step_configurations property.

Returns:

Type Description
Dict[str, Step]

the value of the property.

template_id: Optional[UUID] property

The template_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

Functions
get_hydrated_version() -> PipelineDeploymentResponse

Return the hydrated version of this pipeline deployment.

Returns:

Type Description
PipelineDeploymentResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_deployment.py
208
209
210
211
212
213
214
215
216
def get_hydrated_version(self) -> "PipelineDeploymentResponse":
    """Return the hydrated version of this pipeline deployment.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_deployment(self.id)
PipelineDeploymentResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline deployments.

PipelineDeploymentResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline deployments.

PipelineDeploymentResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline deployment entity.

pipeline_run

Models representing pipeline runs.

Classes
PipelineRunFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model to enable advanced filtering of all Workspaces.

Functions
apply_sorting(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Apply sorting to the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the sorting.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with sorting applied.

Source code in src/zenml/models/v2/core/pipeline_run.py
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
def apply_sorting(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Apply sorting to the query.

    Args:
        query: The query to which to apply the sorting.
        table: The query table.

    Returns:
        The query with sorting applied.
    """
    from sqlmodel import asc, desc

    from zenml.enums import SorterOps
    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
        PipelineDeploymentSchema,
        PipelineRunSchema,
        PipelineSchema,
        StackSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == "pipeline":
        query = query.outerjoin(
            PipelineSchema,
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
        )
        column = PipelineSchema.name
    elif sort_by == "stack":
        query = query.outerjoin(
            PipelineDeploymentSchema,
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
        ).outerjoin(
            StackSchema,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
        )
        column = StackSchema.name
    elif sort_by == "model":
        query = query.outerjoin(
            ModelVersionSchema,
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
        ).outerjoin(
            ModelSchema,
            ModelVersionSchema.model_id == ModelSchema.id,
        )
        column = ModelSchema.name
    elif sort_by == "model_version":
        query = query.outerjoin(
            ModelVersionSchema,
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
        )
        column = ModelVersionSchema.name
    else:
        return super().apply_sorting(query=query, table=table)

    query = query.add_columns(column)

    if operand == SorterOps.ASCENDING:
        query = query.order_by(asc(column))
    else:
        query = query.order_by(desc(column))

    return query
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/pipeline_run.py
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
def get_custom_filters(
    self,
    table: Type["AnySchema"],
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_, col, or_

    from zenml.zen_stores.schemas import (
        CodeReferenceSchema,
        CodeRepositorySchema,
        ModelSchema,
        ModelVersionSchema,
        PipelineBuildSchema,
        PipelineDeploymentSchema,
        PipelineRunSchema,
        PipelineSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        ScheduleSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.unlisted is not None:
        if self.unlisted is True:
            unlisted_filter = PipelineRunSchema.pipeline_id.is_(None)  # type: ignore[union-attr]
        else:
            unlisted_filter = PipelineRunSchema.pipeline_id.is_not(None)  # type: ignore[union-attr]
        custom_filters.append(unlisted_filter)

    if self.code_repository_id:
        code_repo_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == self.code_repository_id,
        )
        custom_filters.append(code_repo_filter)

    if self.stack_id:
        stack_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            StackSchema.id == self.stack_id,
        )
        custom_filters.append(stack_filter)

    if self.schedule_id:
        schedule_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.schedule_id == ScheduleSchema.id,
            ScheduleSchema.id == self.schedule_id,
        )
        custom_filters.append(schedule_filter)

    if self.build_id:
        pipeline_build_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.build_id == PipelineBuildSchema.id,
            PipelineBuildSchema.id == self.build_id,
        )
        custom_filters.append(pipeline_build_filter)

    if self.template_id:
        run_template_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.template_id == self.template_id,
        )
        custom_filters.append(run_template_filter)

    if self.pipeline:
        pipeline_filter = and_(
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline, table=PipelineSchema
            ),
        )
        custom_filters.append(pipeline_filter)

    if self.stack:
        stack_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack,
                table=StackSchema,
            ),
        )
        custom_filters.append(stack_filter)

    if self.code_repository:
        code_repo_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == CodeRepositorySchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.code_repository,
                table=CodeRepositorySchema,
            ),
        )
        custom_filters.append(code_repo_filter)

    if self.model:
        model_filter = and_(
            PipelineRunSchema.model_version_id == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)

    if self.stack_component:
        component_filter = and_(
            PipelineRunSchema.deployment_id == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            StackSchema.id == StackCompositionSchema.stack_id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack_component,
                table=StackComponentSchema,
            ),
        )
        custom_filters.append(component_filter)

    if self.pipeline_name:
        pipeline_name_filter = and_(
            PipelineRunSchema.pipeline_id == PipelineSchema.id,
            self.generate_custom_query_conditions_for_column(
                value=self.pipeline_name,
                table=PipelineSchema,
                column="name",
            ),
        )
        custom_filters.append(pipeline_name_filter)

    if self.templatable is not None:
        if self.templatable is True:
            templatable_filter = and_(
                # The following condition is not perfect as it does not
                # consider stacks with custom flavor components or local
                # components, but the best we can do currently with our
                # table columns.
                PipelineRunSchema.deployment_id
                == PipelineDeploymentSchema.id,
                PipelineDeploymentSchema.build_id
                == PipelineBuildSchema.id,
                col(PipelineBuildSchema.is_local).is_(False),
                col(PipelineBuildSchema.stack_id).is_not(None),
            )
        else:
            templatable_filter = or_(
                col(PipelineRunSchema.deployment_id).is_(None),
                and_(
                    PipelineRunSchema.deployment_id
                    == PipelineDeploymentSchema.id,
                    col(PipelineDeploymentSchema.build_id).is_(None),
                ),
                and_(
                    PipelineRunSchema.deployment_id
                    == PipelineDeploymentSchema.id,
                    PipelineDeploymentSchema.build_id
                    == PipelineBuildSchema.id,
                    or_(
                        col(PipelineBuildSchema.is_local).is_(True),
                        col(PipelineBuildSchema.stack_id).is_(None),
                    ),
                ),
            )

        custom_filters.append(templatable_filter)
    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id
                == PipelineRunSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.PIPELINE_RUN.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters
PipelineRunRequest

Bases: WorkspaceScopedRequest

Request model for pipeline runs.

PipelineRunResponse

Bases: WorkspaceScopedResponse[PipelineRunResponseBody, PipelineRunResponseMetadata, PipelineRunResponseResources]

Response model for pipeline runs.

Attributes
artifact_versions: List[ArtifactVersionResponse] property

Get all artifact versions that are outputs of steps of this run.

Returns:

Type Description
List[ArtifactVersionResponse]

All output artifact versions of this run (including cached ones).

build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

client_environment: Dict[str, str] property

The client_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

code_path: Optional[str] property

The code_path property.

Returns:

Type Description
Optional[str]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The schedule property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

config: PipelineConfiguration property

The config property.

Returns:

Type Description
PipelineConfiguration

the value of the property.

deployment_id: Optional[UUID] property

The deployment_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

is_templatable: bool property

The is_templatable property.

Returns:

Type Description
bool

the value of the property.

model_version: Optional[ModelVersionResponse] property

The model_version property.

Returns:

Type Description
Optional[ModelVersionResponse]

the value of the property.

model_version_id: Optional[UUID] property

The model_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

orchestrator_environment: Dict[str, str] property

The orchestrator_environment property.

Returns:

Type Description
Dict[str, str]

the value of the property.

orchestrator_run_id: Optional[str] property

The orchestrator_run_id property.

Returns:

Type Description
Optional[str]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

produced_artifact_versions: List[ArtifactVersionResponse] property

Get all artifact versions produced during this pipeline run.

Returns:

Type Description
List[ArtifactVersionResponse]

A list of all artifact versions produced during this pipeline run.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

schedule: Optional[ScheduleResponse] property

The schedule property.

Returns:

Type Description
Optional[ScheduleResponse]

the value of the property.

stack: Optional[StackResponse] property

The stack property.

Returns:

Type Description
Optional[StackResponse]

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

status: ExecutionStatus property

The status property.

Returns:

Type Description
ExecutionStatus

the value of the property.

step_substitutions: Dict[str, Dict[str, str]] property

The step_substitutions property.

Returns:

Type Description
Dict[str, Dict[str, str]]

the value of the property.

steps: Dict[str, StepRunResponse] property

The steps property.

Returns:

Type Description
Dict[str, StepRunResponse]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

template_id: Optional[UUID] property

The template_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

trigger_execution: Optional[TriggerExecutionResponse] property

The trigger_execution property.

Returns:

Type Description
Optional[TriggerExecutionResponse]

the value of the property.

Functions
get_hydrated_version() -> PipelineRunResponse

Get the hydrated version of this pipeline run.

Returns:

Type Description
PipelineRunResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/pipeline_run.py
286
287
288
289
290
291
292
293
294
def get_hydrated_version(self) -> "PipelineRunResponse":
    """Get the hydrated version of this pipeline run.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_run(self.id)
refresh_run_status() -> PipelineRunResponse

Method to refresh the status of a run if it is initializing/running.

Returns:

Type Description
PipelineRunResponse

The updated pipeline.

Raises:

Type Description
ValueError

If the stack of the run response is None.

Source code in src/zenml/models/v2/core/pipeline_run.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def refresh_run_status(self) -> "PipelineRunResponse":
    """Method to refresh the status of a run if it is initializing/running.

    Returns:
        The updated pipeline.

    Raises:
        ValueError: If the stack of the run response is None.
    """
    if self.status in [
        ExecutionStatus.INITIALIZING,
        ExecutionStatus.RUNNING,
    ]:
        # Check if the stack still accessible
        if self.stack is None:
            raise ValueError(
                "The stack that this pipeline run response was executed on"
                "has been deleted."
            )

        # Create the orchestrator instance
        from zenml.enums import StackComponentType
        from zenml.orchestrators.base_orchestrator import BaseOrchestrator
        from zenml.stack.stack_component import StackComponent

        # Check if the stack still accessible
        orchestrator_list = self.stack.components.get(
            StackComponentType.ORCHESTRATOR, []
        )
        if len(orchestrator_list) == 0:
            raise ValueError(
                "The orchestrator that this pipeline run response was "
                "executed with has been deleted."
            )

        orchestrator = cast(
            BaseOrchestrator,
            StackComponent.from_model(
                component_model=orchestrator_list[0]
            ),
        )

        # Fetch the status
        status = orchestrator.fetch_status(run=self)

        # If it is different from the current status, update it
        if status != self.status:
            from zenml.client import Client
            from zenml.models import PipelineRunUpdate

            client = Client()
            return client.zen_store.update_run(
                run_id=self.id,
                run_update=PipelineRunUpdate(status=status),
            )

    return self
PipelineRunResponseBody

Bases: WorkspaceScopedResponseBody

Response body for pipeline runs.

PipelineRunResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for pipeline runs.

PipelineRunResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the pipeline run entity.

PipelineRunUpdate

Bases: BaseModel

Pipeline run update model.

run_metadata

Models representing run metadata.

Classes
RunMetadataRequest

Bases: WorkspaceScopedRequest

Request model for run metadata.

Functions
validate_values_keys() -> RunMetadataRequest

Validates if the keys in the metadata are properly defined.

Returns:

Type Description
RunMetadataRequest

self

Raises:

Type Description
ValueError

if one of the key in the metadata contains :

Source code in src/zenml/models/v2/core/run_metadata.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@model_validator(mode="after")
def validate_values_keys(self) -> "RunMetadataRequest":
    """Validates if the keys in the metadata are properly defined.

    Returns:
        self

    Raises:
        ValueError: if one of the key in the metadata contains `:`
    """
    invalid_keys = [key for key in self.values.keys() if ":" in key]
    if invalid_keys:
        raise ValueError(
            "You can not use colons (`:`) in the key names when you "
            "are creating metadata for your ZenML objects. Please change "
            f"the following keys: {invalid_keys}"
        )
    return self
run_template

Models representing pipeline templates.

Classes
RunTemplateFilter

Bases: WorkspaceScopedFilter, TaggableFilter

Model for filtering of run templates.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/run_template.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        CodeReferenceSchema,
        PipelineDeploymentSchema,
        PipelineSchema,
        RunTemplateSchema,
        StackSchema,
    )

    if self.code_repository_id:
        code_repo_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.code_reference_id
            == CodeReferenceSchema.id,
            CodeReferenceSchema.code_repository_id
            == self.code_repository_id,
        )
        custom_filters.append(code_repo_filter)

    if self.stack_id:
        stack_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == self.stack_id,
        )
        custom_filters.append(stack_filter)

    if self.build_id:
        build_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.build_id == self.build_id,
        )
        custom_filters.append(build_filter)

    if self.pipeline_id:
        pipeline_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.pipeline_id == self.pipeline_id,
        )
        custom_filters.append(pipeline_filter)

    if self.pipeline:
        pipeline_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.pipeline_id == PipelineSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.pipeline,
                table=PipelineSchema,
            ),
        )
        custom_filters.append(pipeline_filter)

    if self.stack:
        stack_filter = and_(
            RunTemplateSchema.source_deployment_id
            == PipelineDeploymentSchema.id,
            PipelineDeploymentSchema.stack_id == StackSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack,
                table=StackSchema,
            ),
        )
        custom_filters.append(stack_filter)

    return custom_filters
RunTemplateRequest

Bases: WorkspaceScopedRequest

Request model for run templates.

RunTemplateResponse

Bases: WorkspaceScopedResponse[RunTemplateResponseBody, RunTemplateResponseMetadata, RunTemplateResponseResources]

Response model for run templates.

Attributes
build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

code_reference: Optional[CodeReferenceResponse] property

The code_reference property.

Returns:

Type Description
Optional[CodeReferenceResponse]

the value of the property.

config_schema: Optional[Dict[str, Any]] property

The config_schema property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

config_template: Optional[Dict[str, Any]] property

The config_template property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

latest_run_id: Optional[UUID] property

The latest_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

latest_run_status: Optional[ExecutionStatus] property

The latest_run_status property.

Returns:

Type Description
Optional[ExecutionStatus]

the value of the property.

pipeline: Optional[PipelineResponse] property

The pipeline property.

Returns:

Type Description
Optional[PipelineResponse]

the value of the property.

pipeline_spec: Optional[PipelineSpec] property

The pipeline_spec property.

Returns:

Type Description
Optional[PipelineSpec]

the value of the property.

runnable: bool property

The runnable property.

Returns:

Type Description
bool

the value of the property.

source_deployment: Optional[PipelineDeploymentResponse] property

The source_deployment property.

Returns:

Type Description
Optional[PipelineDeploymentResponse]

the value of the property.

tags: List[TagResponse] property

The tags property.

Returns:

Type Description
List[TagResponse]

the value of the property.

Functions
get_hydrated_version() -> RunTemplateResponse

Return the hydrated version of this run template.

Returns:

Type Description
RunTemplateResponse

The hydrated run template.

Source code in src/zenml/models/v2/core/run_template.py
186
187
188
189
190
191
192
193
194
195
196
def get_hydrated_version(self) -> "RunTemplateResponse":
    """Return the hydrated version of this run template.

    Returns:
        The hydrated run template.
    """
    from zenml.client import Client

    return Client().zen_store.get_run_template(
        template_id=self.id, hydrate=True
    )
RunTemplateResponseBody

Bases: WorkspaceScopedResponseBody

Response body for run templates.

RunTemplateResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for run templates.

RunTemplateResponseResources

Bases: WorkspaceScopedResponseResources

All resource models associated with the run template.

RunTemplateUpdate

Bases: BaseUpdate

Run template update model.

schedule

Models representing schedules.

Classes
ScheduleFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Users.

ScheduleRequest

Bases: WorkspaceScopedRequest

Request model for schedules.

ScheduleResponse

Bases: WorkspaceScopedResponse[ScheduleResponseBody, ScheduleResponseMetadata, ScheduleResponseResources]

Response model for schedules.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

catchup: bool property

The catchup property.

Returns:

Type Description
bool

the value of the property.

cron_expression: Optional[str] property

The cron_expression property.

Returns:

Type Description
Optional[str]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

interval_second: Optional[timedelta] property

The interval_second property.

Returns:

Type Description
Optional[timedelta]

the value of the property.

orchestrator_id: Optional[UUID] property

The orchestrator_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

pipeline_id: Optional[UUID] property

The pipeline_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

run_once_start_time: Optional[datetime] property

The run_once_start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

utc_end_time: Optional[str] property

Optional ISO-formatted string of the UTC end time.

Returns:

Type Description
Optional[str]

Optional ISO-formatted string of the UTC end time.

utc_start_time: Optional[str] property

Optional ISO-formatted string of the UTC start time.

Returns:

Type Description
Optional[str]

Optional ISO-formatted string of the UTC start time.

Functions
get_hydrated_version() -> ScheduleResponse

Get the hydrated version of this schedule.

Returns:

Type Description
ScheduleResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/schedule.py
186
187
188
189
190
191
192
193
194
def get_hydrated_version(self) -> "ScheduleResponse":
    """Get the hydrated version of this schedule.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_schedule(self.id)
ScheduleResponseBody

Bases: WorkspaceScopedResponseBody

Response body for schedules.

ScheduleResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for schedules.

ScheduleResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the schedule entity.

ScheduleUpdate

Bases: BaseUpdate

Update model for schedules.

Functions
secret

Models representing secrets.

Classes
SecretFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all Secrets.

Functions
secret_matches(secret: SecretResponse) -> bool

Checks if a secret matches the filter criteria.

Parameters:

Name Type Description Default
secret SecretResponse

The secret to check.

required

Returns:

Type Description
bool

True if the secret matches the filter criteria, False otherwise.

Source code in src/zenml/models/v2/core/secret.py
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
def secret_matches(self, secret: SecretResponse) -> bool:
    """Checks if a secret matches the filter criteria.

    Args:
        secret: The secret to check.

    Returns:
        True if the secret matches the filter criteria, False otherwise.
    """
    for filter in self.list_of_filters:
        column_value: Optional[Any] = None
        if filter.column == "workspace_id":
            column_value = secret.workspace.id
        elif filter.column == "user_id":
            column_value = secret.user.id if secret.user else None
        else:
            column_value = getattr(secret, filter.column)

        # Convert the values to strings for lexicographical comparison.
        str_column_value = self._get_filtering_value(column_value)
        str_filter_value = self._get_filtering_value(filter.value)

        # Compare the lexicographical values according to the operation.
        if filter.operation == GenericFilterOps.EQUALS:
            result = str_column_value == str_filter_value
        elif filter.operation == GenericFilterOps.CONTAINS:
            result = str_filter_value in str_column_value
        elif filter.operation == GenericFilterOps.STARTSWITH:
            result = str_column_value.startswith(str_filter_value)
        elif filter.operation == GenericFilterOps.ENDSWITH:
            result = str_column_value.endswith(str_filter_value)
        elif filter.operation == GenericFilterOps.GT:
            result = str_column_value > str_filter_value
        elif filter.operation == GenericFilterOps.GTE:
            result = str_column_value >= str_filter_value
        elif filter.operation == GenericFilterOps.LT:
            result = str_column_value < str_filter_value
        elif filter.operation == GenericFilterOps.LTE:
            result = str_column_value <= str_filter_value

        # Exit early if the result is False for AND, and True for OR
        if self.logical_operator == LogicalOperators.AND:
            if not result:
                return False
        else:
            if result:
                return True

    # If we get here, all filters have been checked and the result is
    # True for AND, and False for OR
    if self.logical_operator == LogicalOperators.AND:
        return True
    else:
        return False
sort_secrets(secrets: List[SecretResponse]) -> List[SecretResponse]

Sorts a list of secrets according to the filter criteria.

Parameters:

Name Type Description Default
secrets List[SecretResponse]

The list of secrets to sort.

required

Returns:

Type Description
List[SecretResponse]

The sorted list of secrets.

Source code in src/zenml/models/v2/core/secret.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def sort_secrets(
    self, secrets: List[SecretResponse]
) -> List[SecretResponse]:
    """Sorts a list of secrets according to the filter criteria.

    Args:
        secrets: The list of secrets to sort.

    Returns:
        The sorted list of secrets.
    """
    column, sort_op = self.sorting_params
    sorted_secrets = sorted(
        secrets,
        key=lambda secret: self._get_filtering_value(
            getattr(secret, column)
        ),
        reverse=sort_op == SorterOps.DESCENDING,
    )

    return sorted_secrets
SecretRequest

Bases: WorkspaceScopedRequest

Request models for secrets.

Attributes
secret_values: Dict[str, str] property

A dictionary with all un-obfuscated values stored in this secret.

The values are returned as strings, not SecretStr. If a value is None, it is not included in the returned dictionary. This is to enable the use of None values in the update model to indicate that a secret value should be deleted.

Returns:

Type Description
Dict[str, str]

A dictionary containing the secret's values.

SecretResponse

Bases: WorkspaceScopedResponse[SecretResponseBody, SecretResponseMetadata, SecretResponseResources]

Response model for secrets.

Attributes
has_missing_values: bool property

Returns True if the secret has missing values (i.e. None).

Values can be missing from a secret for example if the user retrieves a secret but does not have the permission to view the secret values.

Returns:

Type Description
bool

True if the secret has any values set to None.

scope: SecretScope property

The scope property.

Returns:

Type Description
SecretScope

the value of the property.

secret_values: Dict[str, str] property

A dictionary with all un-obfuscated values stored in this secret.

The values are returned as strings, not SecretStr. If a value is None, it is not included in the returned dictionary. This is to enable the use of None values in the update model to indicate that a secret value should be deleted.

Returns:

Type Description
Dict[str, str]

A dictionary containing the secret's values.

values: Dict[str, Optional[SecretStr]] property

The values property.

Returns:

Type Description
Dict[str, Optional[SecretStr]]

the value of the property.

Functions
add_secret(key: str, value: str) -> None

Adds a secret value to the secret.

Parameters:

Name Type Description Default
key str

The key of the secret value.

required
value str

The secret value.

required
Source code in src/zenml/models/v2/core/secret.py
210
211
212
213
214
215
216
217
def add_secret(self, key: str, value: str) -> None:
    """Adds a secret value to the secret.

    Args:
        key: The key of the secret value.
        value: The secret value.
    """
    self.get_body().values[key] = SecretStr(value)
get_hydrated_version() -> SecretResponse

Get the hydrated version of this workspace.

Returns:

Type Description
SecretResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/secret.py
149
150
151
152
153
154
155
156
157
def get_hydrated_version(self) -> "SecretResponse":
    """Get the hydrated version of this workspace.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_secret(self.id)
remove_secret(key: str) -> None

Removes a secret value from the secret.

Parameters:

Name Type Description Default
key str

The key of the secret value.

required
Source code in src/zenml/models/v2/core/secret.py
219
220
221
222
223
224
225
def remove_secret(self, key: str) -> None:
    """Removes a secret value from the secret.

    Args:
        key: The key of the secret value.
    """
    del self.get_body().values[key]
remove_secrets() -> None

Removes all secret values from the secret but keep the keys.

Source code in src/zenml/models/v2/core/secret.py
227
228
229
def remove_secrets(self) -> None:
    """Removes all secret values from the secret but keep the keys."""
    self.get_body().values = {k: None for k in self.values.keys()}
set_secrets(values: Dict[str, str]) -> None

Sets the secret values of the secret.

Parameters:

Name Type Description Default
values Dict[str, str]

The secret values to set.

required
Source code in src/zenml/models/v2/core/secret.py
231
232
233
234
235
236
237
def set_secrets(self, values: Dict[str, str]) -> None:
    """Sets the secret values of the secret.

    Args:
        values: The secret values to set.
    """
    self.get_body().values = {k: SecretStr(v) for k, v in values.items()}
SecretResponseBody

Bases: WorkspaceScopedResponseBody

Response body for secrets.

SecretResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for secrets.

SecretResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the secret entity.

SecretUpdate

Bases: BaseUpdate

Secret update model.

Functions
get_secret_values_update() -> Dict[str, Optional[str]]

Returns a dictionary with the secret values to update.

Returns:

Type Description
Dict[str, Optional[str]]

A dictionary with the secret values to update.

Source code in src/zenml/models/v2/core/secret.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def get_secret_values_update(self) -> Dict[str, Optional[str]]:
    """Returns a dictionary with the secret values to update.

    Returns:
        A dictionary with the secret values to update.
    """
    if self.values is not None:
        return {
            k: v.get_secret_value() if v is not None else None
            for k, v in self.values.items()
        }

    return {}
server_settings

Models representing server settings stored in the database.

Classes
ServerActivationRequest

Bases: ServerSettingsUpdate

Model for activating the server.

ServerSettingsResponse

Bases: BaseResponse[ServerSettingsResponseBody, ServerSettingsResponseMetadata, ServerSettingsResponseResources]

Response model for server settings.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

display_announcements: Optional[bool] property

The display_announcements property.

Returns:

Type Description
Optional[bool]

the value of the property.

display_updates: Optional[bool] property

The display_updates property.

Returns:

Type Description
Optional[bool]

the value of the property.

enable_analytics: bool property

The enable_analytics property.

Returns:

Type Description
bool

the value of the property.

last_user_activity: datetime property

The last_user_activity property.

Returns:

Type Description
datetime

the value of the property.

logo_url: Optional[str] property

The logo_url property.

Returns:

Type Description
Optional[str]

the value of the property.

server_id: UUID property

The server_id property.

Returns:

Type Description
UUID

the value of the property.

server_name: str property

The server_name property.

Returns:

Type Description
str

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_hydrated_version() -> ServerSettingsResponse

Get the hydrated version of the server settings.

Returns:

Type Description
ServerSettingsResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/server_settings.py
110
111
112
113
114
115
116
117
118
def get_hydrated_version(self) -> "ServerSettingsResponse":
    """Get the hydrated version of the server settings.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_server_settings(hydrate=True)
ServerSettingsResponseBody

Bases: BaseResponseBody

Response body for server settings.

ServerSettingsResponseMetadata

Bases: BaseResponseMetadata

Response metadata for server settings.

ServerSettingsResponseResources

Bases: BaseResponseResources

Response resources for server settings.

ServerSettingsUpdate

Bases: BaseZenModel

Model for updating server settings.

service

Models representing Services.

Classes
ServiceFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of services.

The Service needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
generate_filter(table: Type[AnySchema]) -> Union[ColumnElement[bool]]

Generate the filter for the query.

Services can be scoped by type to narrow the search.

Parameters:

Name Type Description Default
table Type[AnySchema]

The Table that is being queried from.

required

Returns:

Type Description
Union[ColumnElement[bool]]

The filter expression for the query.

Source code in src/zenml/models/v2/core/service.py
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
def generate_filter(
    self, table: Type["AnySchema"]
) -> Union["ColumnElement[bool]"]:
    """Generate the filter for the query.

    Services can be scoped by type to narrow the search.

    Args:
        table: The Table that is being queried from.

    Returns:
        The filter expression for the query.
    """
    from sqlmodel import and_

    base_filter = super().generate_filter(table)

    if self.type:
        type_filter = getattr(table, "type") == self.type
        base_filter = and_(base_filter, type_filter)

    if self.flavor:
        flavor_filter = getattr(table, "flavor") == self.flavor
        base_filter = and_(base_filter, flavor_filter)

    if self.pipeline_name:
        pipeline_name_filter = (
            getattr(table, "pipeline_name") == self.pipeline_name
        )
        base_filter = and_(base_filter, pipeline_name_filter)

    if self.pipeline_step_name:
        pipeline_step_name_filter = (
            getattr(table, "pipeline_step_name") == self.pipeline_step_name
        )
        base_filter = and_(base_filter, pipeline_step_name_filter)

    return base_filter
set_flavor(flavor: str) -> None

Set the flavor of the service.

Parameters:

Name Type Description Default
flavor str

The flavor of the service.

required
Source code in src/zenml/models/v2/core/service.py
436
437
438
439
440
441
442
def set_flavor(self, flavor: str) -> None:
    """Set the flavor of the service.

    Args:
        flavor: The flavor of the service.
    """
    self.flavor = flavor
set_type(type: str) -> None

Set the type of the service.

Parameters:

Name Type Description Default
type str

The type of the service.

required
Source code in src/zenml/models/v2/core/service.py
428
429
430
431
432
433
434
def set_type(self, type: str) -> None:
    """Set the type of the service.

    Args:
        type: The type of the service.
    """
    self.type = type
ServiceRequest

Bases: WorkspaceScopedRequest

Request model for services.

ServiceResponse

Bases: WorkspaceScopedResponse[ServiceResponseBody, ServiceResponseMetadata, ServiceResponseResources]

Response model for services.

Attributes
admin_state: Optional[ServiceState] property

The admin_state property.

Returns:

Type Description
Optional[ServiceState]

the value of the property.

config: Dict[str, Any] property

The config property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

created: datetime property

The created property.

Returns:

Type Description
datetime

the value of the property.

endpoint: Optional[Dict[str, Any]] property

The endpoint property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

health_check_url: Optional[str] property

The health_check_url property.

Returns:

Type Description
Optional[str]

the value of the property.

labels: Optional[Dict[str, str]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, str]]

the value of the property.

prediction_url: Optional[str] property

The prediction_url property.

Returns:

Type Description
Optional[str]

the value of the property.

service_source: Optional[str] property

The service_source property.

Returns:

Type Description
Optional[str]

the value of the property.

service_type: ServiceType property

The service_type property.

Returns:

Type Description
ServiceType

the value of the property.

state: Optional[ServiceState] property

The state property.

Returns:

Type Description
Optional[ServiceState]

the value of the property.

status: Optional[Dict[str, Any]] property

The status property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

updated: datetime property

The updated property.

Returns:

Type Description
datetime

the value of the property.

Functions
get_hydrated_version() -> ServiceResponse

Get the hydrated version of this artifact.

Returns:

Type Description
ServiceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service.py
246
247
248
249
250
251
252
253
254
def get_hydrated_version(self) -> "ServiceResponse":
    """Get the hydrated version of this artifact.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service(self.id)
ServiceResponseBody

Bases: WorkspaceScopedResponseBody

Response body for services.

ServiceResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for services.

ServiceResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the service entity.

ServiceUpdate

Bases: BaseModel

Update model for stack components.

service_account

Models representing service accounts.

Classes
ServiceAccountFilter

Bases: BaseFilter

Model to enable advanced filtering of service accounts.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to filter out user accounts from the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/service_account.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to filter out user accounts from the query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)
    query = query.where(
        getattr(table, "is_service_account") == True  # noqa: E712
    )

    return query
ServiceAccountRequest

Bases: BaseRequest

Request model for service accounts.

ServiceAccountResponse

Bases: BaseIdentifiedResponse[ServiceAccountResponseBody, ServiceAccountResponseMetadata, ServiceAccountResponseResources]

Response model for service accounts.

Attributes
active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ServiceAccountResponse

Get the hydrated version of this service account.

Returns:

Type Description
ServiceAccountResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service_account.py
126
127
128
129
130
131
132
133
134
def get_hydrated_version(self) -> "ServiceAccountResponse":
    """Get the hydrated version of this service account.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service_account(self.id)
to_user_model() -> UserResponse

Converts the service account to a user model.

For now, a lot of code still relies on the active user and resource owners being a UserResponse object, which is a superset of the ServiceAccountResponse object. We need this method to convert the service account to a user.

Returns:

Type Description
UserResponse

The user model.

Source code in src/zenml/models/v2/core/service_account.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def to_user_model(self) -> "UserResponse":
    """Converts the service account to a user model.

    For now, a lot of code still relies on the active user and resource
    owners being a UserResponse object, which is a superset of the
    ServiceAccountResponse object. We need this method to convert the
    service account to a user.

    Returns:
        The user model.
    """
    from zenml.models.v2.core.user import (
        UserResponse,
        UserResponseBody,
        UserResponseMetadata,
    )

    return UserResponse(
        id=self.id,
        name=self.name,
        body=UserResponseBody(
            active=self.active,
            is_service_account=True,
            email_opted_in=False,
            created=self.created,
            updated=self.updated,
            is_admin=False,
        ),
        metadata=UserResponseMetadata(
            description=self.description,
        ),
    )
ServiceAccountResponseBody

Bases: BaseDatedResponseBody

Response body for service accounts.

ServiceAccountResponseMetadata

Bases: BaseResponseMetadata

Response metadata for service accounts.

ServiceAccountResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the service account entity.

ServiceAccountUpdate

Bases: BaseUpdate

Update model for service accounts.

service_connector

Models representing service connectors.

Classes
ServiceConnectorFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of service connectors.

Functions
validate_labels() -> ServiceConnectorFilter

Parse the labels string into a label dictionary and vice-versa.

Returns:

Type Description
ServiceConnectorFilter

The validated values.

Source code in src/zenml/models/v2/core/service_connector.py
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
@model_validator(mode="after")
def validate_labels(self) -> "ServiceConnectorFilter":
    """Parse the labels string into a label dictionary and vice-versa.

    Returns:
        The validated values.
    """
    if self.labels_str is not None:
        try:
            self.labels = json.loads(self.labels_str)
        except json.JSONDecodeError:
            # Interpret as comma-separated values instead
            self.labels = {
                label.split("=", 1)[0]: label.split("=", 1)[1]
                if "=" in label
                else None
                for label in self.labels_str.split(",")
            }
    elif self.labels is not None:
        self.labels_str = json.dumps(self.labels)

    return self
ServiceConnectorRequest

Bases: WorkspaceScopedRequest

Request model for service connectors.

Attributes
emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector type.

Returns:

Type Description
List[str]

The emojified connector type.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
get_analytics_metadata() -> Dict[str, Any]

Format the resource types in the analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
120
121
122
123
124
125
126
127
128
129
130
131
132
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Format the resource types in the analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    if len(self.resource_types) == 1:
        metadata["resource_types"] = self.resource_types[0]
    else:
        metadata["resource_types"] = ", ".join(self.resource_types)
    metadata["connector_type"] = self.type
    return metadata
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )
ServiceConnectorResponse

Bases: WorkspaceScopedResponse[ServiceConnectorResponseBody, ServiceConnectorResponseMetadata, ServiceConnectorResponseResources]

Response model for service connectors.

Attributes
auth_method: str property

The auth_method property.

Returns:

Type Description
str

the value of the property.

configuration: Dict[str, Any] property

The configuration property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

connector_type: Union[str, ServiceConnectorTypeModel] property

The connector_type property.

Returns:

Type Description
Union[str, ServiceConnectorTypeModel]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector type.

Returns:

Type Description
List[str]

The emojified connector type.

expiration_seconds: Optional[int] property

The expiration_seconds property.

Returns:

Type Description
Optional[int]

the value of the property.

expires_at: Optional[datetime] property

The expires_at property.

Returns:

Type Description
Optional[datetime]

the value of the property.

expires_skew_tolerance: Optional[int] property

The expires_skew_tolerance property.

Returns:

Type Description
Optional[int]

the value of the property.

full_configuration: Dict[str, str] property

Get the full connector configuration, including secrets.

Returns:

Type Description
Dict[str, str]

The full connector configuration, including secrets.

is_multi_instance: bool property

Checks if the connector is multi-instance.

A multi-instance connector is configured to access multiple instances of the configured resource type.

Returns:

Type Description
bool

True if the connector is multi-instance, False otherwise.

is_multi_type: bool property

Checks if the connector is multi-type.

A multi-type connector can be used to access multiple types of resources.

Returns:

Type Description
bool

True if the connector is multi-type, False otherwise.

is_single_instance: bool property

Checks if the connector is single-instance.

A single-instance connector is configured to access only a single instance of the configured resource type or does not support multiple resource instances.

Returns:

Type Description
bool

True if the connector is single-instance, False otherwise.

labels: Dict[str, str] property

The labels property.

Returns:

Type Description
Dict[str, str]

the value of the property.

resource_id: Optional[str] property

The resource_id property.

Returns:

Type Description
Optional[str]

the value of the property.

resource_types: List[str] property

The resource_types property.

Returns:

Type Description
List[str]

the value of the property.

secret_id: Optional[UUID] property

The secret_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

secrets: Dict[str, Optional[SecretStr]] property

The secrets property.

Returns:

Type Description
Dict[str, Optional[SecretStr]]

the value of the property.

supports_instances: bool property

The supports_instances property.

Returns:

Type Description
bool

the value of the property.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the service connector labels to analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the service connector labels to analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    metadata.update(
        {
            label[6:]: value
            for label, value in self.labels.items()
            if label.startswith("zenml:")
        }
    )
    return metadata
get_hydrated_version() -> ServiceConnectorResponse

Get the hydrated version of this service connector.

Returns:

Type Description
ServiceConnectorResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/service_connector.py
517
518
519
520
521
522
523
524
525
def get_hydrated_version(self) -> "ServiceConnectorResponse":
    """Get the hydrated version of this service connector.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_service_connector(self.id)
set_connector_type(value: Union[str, ServiceConnectorTypeModel]) -> None

Auxiliary method to set the connector type.

Parameters:

Name Type Description Default
value Union[str, ServiceConnectorTypeModel]

the new value for the connector type.

required
Source code in src/zenml/models/v2/core/service_connector.py
622
623
624
625
626
627
628
629
630
def set_connector_type(
    self, value: Union[str, "ServiceConnectorTypeModel"]
) -> None:
    """Auxiliary method to set the connector type.

    Args:
        value: the new value for the connector type.
    """
    self.get_body().connector_type = value
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )
ServiceConnectorResponseBody

Bases: WorkspaceScopedResponseBody

Response body for service connectors.

ServiceConnectorResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for service connectors.

ServiceConnectorResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the service connector entity.

ServiceConnectorUpdate

Bases: BaseUpdate

Model used for service connector updates.

Most fields in the update model are optional and will not be updated if omitted. However, the following fields are "special" and leaving them out will also cause the corresponding value to be removed from the service connector in the database:

  • the resource_id field
  • the expiration_seconds field

In addition to the above exceptions, the following rules apply:

  • the configuration and secrets fields together represent a full valid configuration update, not just a partial update. If either is set (i.e. not None) in the update, their values are merged together and will replace the existing configuration and secrets values.
  • the secret_id field value in the update is ignored, given that secrets are managed internally by the ZenML store.
  • the labels field is also a full labels update: if set (i.e. not None), all existing labels are removed and replaced by the new labels in the update.

NOTE: the attributes here override the ones in the base class, so they have a None default value.

Attributes
type: Optional[str] property

Get the connector type.

Returns:

Type Description
Optional[str]

The connector type.

Functions
convert_to_request() -> ServiceConnectorRequest

Method to generate a service connector request object from self.

For certain operations, the service connector update model need to adhere to the limitations set by the request model. In order to use update models in such situations, we need to be able to convert an update model into a request model.

Returns:

Type Description
ServiceConnectorRequest

The equivalent request model

Raises:

Type Description
RuntimeError

if the model can not be converted to a request model.

Source code in src/zenml/models/v2/core/service_connector.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def convert_to_request(self) -> "ServiceConnectorRequest":
    """Method to generate a service connector request object from self.

    For certain operations, the service connector update model need to
    adhere to the limitations set by the request model. In order to use
    update models in such situations, we need to be able to convert an
    update model into a request model.

    Returns:
        The equivalent request model

    Raises:
        RuntimeError: if the model can not be converted to a request model.
    """
    try:
        return ServiceConnectorRequest.model_validate(self.model_dump())
    except ValidationError as e:
        raise RuntimeError(
            "The service connector update model can not be converted into "
            f"an equivalent request model: {e}"
        )
get_analytics_metadata() -> Dict[str, Any]

Format the resource types in the analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/service_connector.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Format the resource types in the analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()

    if self.resource_types is not None:
        if len(self.resource_types) == 1:
            metadata["resource_types"] = self.resource_types[0]
        else:
            metadata["resource_types"] = ", ".join(self.resource_types)

    if self.connector_type is not None:
        metadata["connector_type"] = self.type

    return metadata
validate_and_configure_resources(connector_type: ServiceConnectorTypeModel, resource_types: Optional[Union[str, List[str]]] = None, resource_id: Optional[str] = None, configuration: Optional[Dict[str, Any]] = None, secrets: Optional[Dict[str, Optional[SecretStr]]] = None) -> None

Validate and configure the resources that the connector can be used to access.

Parameters:

Name Type Description Default
connector_type ServiceConnectorTypeModel

The connector type specification used to validate the connector configuration.

required
resource_types Optional[Union[str, List[str]]]

The type(s) of resource that the connector instance can be used to access. If omitted, a multi-type connector is configured.

None
resource_id Optional[str]

Uniquely identifies a specific resource instance that the connector instance can be used to access.

None
configuration Optional[Dict[str, Any]]

The connector configuration.

None
secrets Optional[Dict[str, Optional[SecretStr]]]

The connector secrets.

None
Source code in src/zenml/models/v2/core/service_connector.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
def validate_and_configure_resources(
    self,
    connector_type: "ServiceConnectorTypeModel",
    resource_types: Optional[Union[str, List[str]]] = None,
    resource_id: Optional[str] = None,
    configuration: Optional[Dict[str, Any]] = None,
    secrets: Optional[Dict[str, Optional[SecretStr]]] = None,
) -> None:
    """Validate and configure the resources that the connector can be used to access.

    Args:
        connector_type: The connector type specification used to validate
            the connector configuration.
        resource_types: The type(s) of resource that the connector instance
            can be used to access. If omitted, a multi-type connector is
            configured.
        resource_id: Uniquely identifies a specific resource instance that
            the connector instance can be used to access.
        configuration: The connector configuration.
        secrets: The connector secrets.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
        secrets=secrets,
    )
Functions
stack

Models representing stacks.

Classes
StackFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all StackModels.

The Stack Model needs additional scoping. As such the _scope_user field can be set to the user that is doing the filtering. The generate_filter() method of the baseclass is overwritten to include the scoping.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/stack.py
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from zenml.zen_stores.schemas import (
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    if self.component_id:
        component_id_filter = and_(
            StackCompositionSchema.stack_id == StackSchema.id,
            StackCompositionSchema.component_id == self.component_id,
        )
        custom_filters.append(component_id_filter)

    if self.component:
        component_filter = and_(
            StackCompositionSchema.stack_id == StackSchema.id,
            StackCompositionSchema.component_id == StackComponentSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.component,
                table=StackComponentSchema,
            ),
        )
        custom_filters.append(component_filter)

    return custom_filters
StackRequest

Bases: BaseRequest

Request model for a stack.

Attributes
is_valid: bool property

Check if the stack is valid.

Returns:

Type Description
bool

True if the stack is valid, False otherwise.

StackResponse

Bases: WorkspaceScopedResponse[StackResponseBody, StackResponseMetadata, StackResponseResources]

Response model for stacks.

Attributes
components: Dict[StackComponentType, List[ComponentResponse]] property

The components property.

Returns:

Type Description
Dict[StackComponentType, List[ComponentResponse]]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

is_valid: bool property

Check if the stack is valid.

Returns:

Type Description
bool

True if the stack is valid, False otherwise.

labels: Optional[Dict[str, Any]] property

The labels property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

stack_spec_path: Optional[str] property

The stack_spec_path property.

Returns:

Type Description
Optional[str]

the value of the property.

Functions
get_analytics_metadata() -> Dict[str, Any]

Add the stack components to the stack analytics metadata.

Returns:

Type Description
Dict[str, Any]

Dict of analytics metadata.

Source code in src/zenml/models/v2/core/stack.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Add the stack components to the stack analytics metadata.

    Returns:
        Dict of analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata.update(
        {ct: c[0].flavor_name for ct, c in self.components.items()}
    )

    if self.labels is not None:
        metadata.update(
            {
                label[6:]: value
                for label, value in self.labels.items()
                if label.startswith("zenml:")
            }
        )
    return metadata
get_hydrated_version() -> StackResponse

Get the hydrated version of this stack.

Returns:

Type Description
StackResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/stack.py
209
210
211
212
213
214
215
216
217
def get_hydrated_version(self) -> "StackResponse":
    """Get the hydrated version of this stack.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_stack(self.id)
to_yaml() -> Dict[str, Any]

Create yaml representation of the Stack Model.

Returns:

Type Description
Dict[str, Any]

The yaml representation of the Stack Model.

Source code in src/zenml/models/v2/core/stack.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def to_yaml(self) -> Dict[str, Any]:
    """Create yaml representation of the Stack Model.

    Returns:
        The yaml representation of the Stack Model.
    """
    component_data = {}
    for component_type, components_list in self.components.items():
        component = components_list[0]
        component_dict = dict(
            name=component.name,
            type=str(component.type),
            flavor=component.flavor_name,
        )
        configuration = json.loads(
            component.get_metadata().model_dump_json(
                include={"configuration"}
            )
        )
        component_dict.update(configuration)

        component_data[component_type.value] = component_dict

    # write zenml version and stack dict to YAML
    yaml_data = {
        "stack_name": self.name,
        "components": component_data,
    }

    return yaml_data
StackResponseBody

Bases: WorkspaceScopedResponseBody

Response body for stacks.

StackResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for stacks.

StackResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the stack entity.

StackUpdate

Bases: BaseUpdate

Update model for stacks.

step_run

Models representing steps runs.

Classes
StepRunFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of step runs.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/step_run.py
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    custom_filters = super().get_custom_filters(table)

    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ModelSchema,
        ModelVersionSchema,
        RunMetadataResourceSchema,
        RunMetadataSchema,
        StepRunSchema,
    )

    if self.model:
        model_filter = and_(
            StepRunSchema.model_version_id == ModelVersionSchema.id,
            ModelVersionSchema.model_id == ModelSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)
    if self.run_metadata is not None:
        from zenml.enums import MetadataResourceTypes

        for key, value in self.run_metadata.items():
            additional_filter = and_(
                RunMetadataResourceSchema.resource_id == StepRunSchema.id,
                RunMetadataResourceSchema.resource_type
                == MetadataResourceTypes.STEP_RUN.value,
                RunMetadataResourceSchema.run_metadata_id
                == RunMetadataSchema.id,
                self.generate_custom_query_conditions_for_column(
                    value=key,
                    table=RunMetadataSchema,
                    column="key",
                ),
                self.generate_custom_query_conditions_for_column(
                    value=value,
                    table=RunMetadataSchema,
                    column="value",
                    json_encode_value=True,
                ),
            )
            custom_filters.append(additional_filter)

    return custom_filters
StepRunInputResponse

Bases: ArtifactVersionResponse

Response model for step run inputs.

Functions
get_hydrated_version() -> StepRunInputResponse

Get the hydrated version of this step run input.

Returns:

Type Description
StepRunInputResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/step_run.py
64
65
66
67
68
69
70
71
72
73
74
75
def get_hydrated_version(self) -> "StepRunInputResponse":
    """Get the hydrated version of this step run input.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return StepRunInputResponse(
        input_type=self.input_type,
        **Client().zen_store.get_artifact_version(self.id).model_dump(),
    )
StepRunRequest

Bases: WorkspaceScopedRequest

Request model for step runs.

StepRunResponse

Bases: WorkspaceScopedResponse[StepRunResponseBody, StepRunResponseMetadata, StepRunResponseResources]

Response model for step runs.

Attributes
cache_key: Optional[str] property

The cache_key property.

Returns:

Type Description
Optional[str]

the value of the property.

code_hash: Optional[str] property

The code_hash property.

Returns:

Type Description
Optional[str]

the value of the property.

config: StepConfiguration property

The config property.

Returns:

Type Description
StepConfiguration

the value of the property.

deployment_id: UUID property

The deployment_id property.

Returns:

Type Description
UUID

the value of the property.

docstring: Optional[str] property

The docstring property.

Returns:

Type Description
Optional[str]

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

input: ArtifactVersionResponse property

Returns the input artifact that was used to run this step.

Returns:

Type Description
ArtifactVersionResponse

The input artifact.

Raises:

Type Description
ValueError

If there were zero or multiple inputs to this step.

inputs: Dict[str, StepRunInputResponse] property

The inputs property.

Returns:

Type Description
Dict[str, StepRunInputResponse]

the value of the property.

logs: Optional[LogsResponse] property

The logs property.

Returns:

Type Description
Optional[LogsResponse]

the value of the property.

model_version: Optional[ModelVersionResponse] property

The model_version property.

Returns:

Type Description
Optional[ModelVersionResponse]

the value of the property.

model_version_id: Optional[UUID] property

The model_version_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

original_step_run_id: Optional[UUID] property

The original_step_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

output: ArtifactVersionResponse property

Returns the output artifact that was written by this step.

Returns:

Type Description
ArtifactVersionResponse

The output artifact.

Raises:

Type Description
ValueError

If there were zero or multiple step outputs.

outputs: Dict[str, List[ArtifactVersionResponse]] property

The outputs property.

Returns:

Type Description
Dict[str, List[ArtifactVersionResponse]]

the value of the property.

parent_step_ids: List[UUID] property

The parent_step_ids property.

Returns:

Type Description
List[UUID]

the value of the property.

pipeline_run_id: UUID property

The pipeline_run_id property.

Returns:

Type Description
UUID

the value of the property.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

source_code: Optional[str] property

The source_code property.

Returns:

Type Description
Optional[str]

the value of the property.

spec: StepSpec property

The spec property.

Returns:

Type Description
StepSpec

the value of the property.

start_time: Optional[datetime] property

The start_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

status: ExecutionStatus property

The status property.

Returns:

Type Description
ExecutionStatus

the value of the property.

Functions
get_hydrated_version() -> StepRunResponse

Get the hydrated version of this step run.

Returns:

Type Description
StepRunResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/step_run.py
291
292
293
294
295
296
297
298
299
def get_hydrated_version(self) -> "StepRunResponse":
    """Get the hydrated version of this step run.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_run_step(self.id)
StepRunResponseBody

Bases: WorkspaceScopedResponseBody

Response body for step runs.

StepRunResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for step runs.

StepRunResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the step run entity.

StepRunUpdate

Bases: BaseModel

Update model for step runs.

tag

Models representing tags.

Classes
TagFilter

Bases: BaseFilter

Model to enable advanced filtering of all tags.

TagRequest

Bases: BaseRequest

Request model for tags.

TagResponse

Bases: BaseIdentifiedResponse[TagResponseBody, BaseResponseMetadata, TagResponseResources]

Response model for tags.

Attributes
color: ColorVariants property

The color property.

Returns:

Type Description
ColorVariants

the value of the property.

tagged_count: int property

The tagged_count property.

Returns:

Type Description
int

the value of the property.

Functions
get_hydrated_version() -> TagResponse

Get the hydrated version of this tag.

Returns:

Type Description
TagResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/tag.py
89
90
91
92
93
94
95
96
97
def get_hydrated_version(self) -> "TagResponse":
    """Get the hydrated version of this tag.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_tag(self.id)
TagResponseBody

Bases: BaseDatedResponseBody

Response body for tags.

TagResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the tag entity.

TagUpdate

Bases: BaseModel

Update model for tags.

tag_resource

Models representing the link between tags and resources.

Classes
TagResourceRequest

Bases: BaseRequest

Request model for links between tags and resources.

TagResourceResponse

Bases: BaseIdentifiedResponse[TagResourceResponseBody, BaseResponseMetadata, TagResourceResponseResources]

Response model for the links between tags and resources.

Attributes
resource_id: UUID property

The resource_id property.

Returns:

Type Description
UUID

the value of the property.

resource_type: TaggableResourceTypes property

The resource_type property.

Returns:

Type Description
TaggableResourceTypes

the value of the property.

tag_id: UUID property

The tag_id property.

Returns:

Type Description
UUID

the value of the property.

TagResourceResponseBody

Bases: BaseDatedResponseBody

Response body for the links between tags and resources.

TagResourceResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the tag resource entity.

trigger

Collection of all models concerning triggers.

Classes
TriggerFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all triggers.

Functions
get_custom_filters(table: Type[AnySchema]) -> List[ColumnElement[bool]]

Get custom filters.

Parameters:

Name Type Description Default
table Type[AnySchema]

The query table.

required

Returns:

Type Description
List[ColumnElement[bool]]

A list of custom filters.

Source code in src/zenml/models/v2/core/trigger.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom filters.

    Args:
        table: The query table.

    Returns:
        A list of custom filters.
    """
    from sqlmodel import and_

    from zenml.zen_stores.schemas import (
        ActionSchema,
        EventSourceSchema,
        TriggerSchema,
    )

    custom_filters = super().get_custom_filters(table)

    if self.event_source_flavor:
        event_source_flavor_filter = and_(
            EventSourceSchema.id == TriggerSchema.event_source_id,
            EventSourceSchema.flavor == self.event_source_flavor,
        )
        custom_filters.append(event_source_flavor_filter)

    if self.event_source_subtype:
        event_source_subtype_filter = and_(
            EventSourceSchema.id == TriggerSchema.event_source_id,
            EventSourceSchema.plugin_subtype == self.event_source_subtype,
        )
        custom_filters.append(event_source_subtype_filter)

    if self.action_flavor:
        action_flavor_filter = and_(
            ActionSchema.id == TriggerSchema.action_id,
            ActionSchema.flavor == self.action_flavor,
        )
        custom_filters.append(action_flavor_filter)

    if self.action_subtype:
        action_subtype_filter = and_(
            ActionSchema.id == TriggerSchema.action_id,
            ActionSchema.plugin_subtype == self.action_subtype,
        )
        custom_filters.append(action_subtype_filter)

    return custom_filters
TriggerRequest

Bases: WorkspaceScopedRequest

Model for creating a new trigger.

TriggerResponse

Bases: WorkspaceScopedResponse[TriggerResponseBody, TriggerResponseMetadata, TriggerResponseResources]

Response model for models.

Attributes
action: ActionResponse property

The action property.

Returns:

Type Description
ActionResponse

the value of the property.

action_flavor: str property

The action_flavor property.

Returns:

Type Description
str

the value of the property.

action_subtype: str property

The action_subtype property.

Returns:

Type Description
str

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

the value of the property.

event_filter: Optional[Dict[str, Any]] property

The event_filter property.

Returns:

Type Description
Optional[Dict[str, Any]]

the value of the property.

event_source: Optional[EventSourceResponse] property

The event_source property.

Returns:

Type Description
Optional[EventSourceResponse]

the value of the property.

event_source_flavor: Optional[str] property

The event_source_flavor property.

Returns:

Type Description
Optional[str]

the value of the property.

event_source_subtype: Optional[str] property

The event_source_subtype property.

Returns:

Type Description
Optional[str]

the value of the property.

executions: Page[TriggerExecutionResponse] property

The event_source property.

Returns:

Type Description
Page[TriggerExecutionResponse]

the value of the property.

is_active: bool property

The is_active property.

Returns:

Type Description
bool

the value of the property.

Functions
get_hydrated_version() -> TriggerResponse

Get the hydrated version of this trigger.

Returns:

Type Description
TriggerResponse

An instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/trigger.py
223
224
225
226
227
228
229
230
231
def get_hydrated_version(self) -> "TriggerResponse":
    """Get the hydrated version of this trigger.

    Returns:
        An instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_trigger(self.id)
TriggerResponseBody

Bases: WorkspaceScopedResponseBody

Response body for triggers.

TriggerResponseMetadata

Bases: WorkspaceScopedResponseMetadata

Response metadata for triggers.

TriggerResponseResources

Bases: WorkspaceScopedResponseResources

Class for all resource models associated with the trigger entity.

TriggerUpdate

Bases: BaseUpdate

Update model for triggers.

trigger_execution

Collection of all models concerning trigger executions.

Classes
TriggerExecutionFilter

Bases: WorkspaceScopedFilter

Model to enable advanced filtering of all trigger executions.

TriggerExecutionRequest

Bases: BaseRequest

Model for creating a new Trigger execution.

TriggerExecutionResponse

Bases: BaseIdentifiedResponse[TriggerExecutionResponseBody, TriggerExecutionResponseMetadata, TriggerExecutionResponseResources]

Response model for trigger executions.

Attributes
event_metadata: Dict[str, Any] property

The event_metadata property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

trigger: TriggerResponse property

The trigger property.

Returns:

Type Description
TriggerResponse

the value of the property.

Functions
get_hydrated_version() -> TriggerExecutionResponse

Get the hydrated version of this trigger execution.

Returns:

Type Description
TriggerExecutionResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/trigger_execution.py
78
79
80
81
82
83
84
85
86
def get_hydrated_version(self) -> "TriggerExecutionResponse":
    """Get the hydrated version of this trigger execution.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_trigger_execution(self.id)
TriggerExecutionResponseBody

Bases: BaseDatedResponseBody

Response body for trigger executions.

TriggerExecutionResponseMetadata

Bases: BaseResponseMetadata

Response metadata for trigger executions.

TriggerExecutionResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the trigger entity.

user

Models representing users.

Classes
UserBase

Bases: BaseModel

Base model for users.

Functions
create_hashed_activation_token() -> Optional[str]

Hashes the activation token.

Returns:

Type Description
Optional[str]

The hashed activation token.

Source code in src/zenml/models/v2/core/user.py
121
122
123
124
125
126
127
def create_hashed_activation_token(self) -> Optional[str]:
    """Hashes the activation token.

    Returns:
        The hashed activation token.
    """
    return self._create_hashed_secret(self.activation_token)
create_hashed_password() -> Optional[str]

Hashes the password.

Returns:

Type Description
Optional[str]

The hashed password.

Source code in src/zenml/models/v2/core/user.py
113
114
115
116
117
118
119
def create_hashed_password(self) -> Optional[str]:
    """Hashes the password.

    Returns:
        The hashed password.
    """
    return self._create_hashed_secret(self.password)
generate_activation_token() -> str

Generates and stores a new activation token.

Returns:

Type Description
str

The generated activation token.

Source code in src/zenml/models/v2/core/user.py
129
130
131
132
133
134
135
136
def generate_activation_token(self) -> str:
    """Generates and stores a new activation token.

    Returns:
        The generated activation token.
    """
    self.activation_token = token_hex(32)
    return self.activation_token
UserFilter

Bases: BaseFilter

Model to enable advanced filtering of all Users.

Functions
apply_filter(query: AnyQuery, table: Type[AnySchema]) -> AnyQuery

Override to filter out service accounts from the query.

Parameters:

Name Type Description Default
query AnyQuery

The query to which to apply the filter.

required
table Type[AnySchema]

The query table.

required

Returns:

Type Description
AnyQuery

The query with filter applied.

Source code in src/zenml/models/v2/core/user.py
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
def apply_filter(
    self,
    query: AnyQuery,
    table: Type["AnySchema"],
) -> AnyQuery:
    """Override to filter out service accounts from the query.

    Args:
        query: The query to which to apply the filter.
        table: The query table.

    Returns:
        The query with filter applied.
    """
    query = super().apply_filter(query=query, table=table)
    query = query.where(
        getattr(table, "is_service_account") != True  # noqa: E712
    )

    return query
UserRequest

Bases: UserBase, BaseRequest

Request model for users.

UserResponse

Bases: BaseIdentifiedResponse[UserResponseBody, UserResponseMetadata, UserResponseResources]

Response model for user and service accounts.

This returns the activation_token that is required for the user-invitation-flow of the frontend. The email is returned optionally as well for use by the analytics on the client-side.

Attributes
activation_token: Optional[str] property

The activation_token property.

Returns:

Type Description
Optional[str]

the value of the property.

active: bool property

The active property.

Returns:

Type Description
bool

the value of the property.

email: Optional[str] property

The email property.

Returns:

Type Description
Optional[str]

the value of the property.

email_opted_in: Optional[bool] property

The email_opted_in property.

Returns:

Type Description
Optional[bool]

the value of the property.

external_user_id: Optional[UUID] property

The external_user_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

full_name: str property

The full_name property.

Returns:

Type Description
str

the value of the property.

is_admin: bool property

The is_admin property.

Returns:

Type Description
bool

Whether the user is an admin.

is_service_account: bool property

The is_service_account property.

Returns:

Type Description
bool

the value of the property.

user_metadata: Dict[str, Any] property

The user_metadata property.

Returns:

Type Description
Dict[str, Any]

the value of the property.

Functions
get_hydrated_version() -> UserResponse

Get the hydrated version of this user.

Returns:

Type Description
UserResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/user.py
333
334
335
336
337
338
339
340
341
def get_hydrated_version(self) -> "UserResponse":
    """Get the hydrated version of this user.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_user(self.id)
UserResponseBody

Bases: BaseDatedResponseBody

Response body for users.

UserResponseMetadata

Bases: BaseResponseMetadata

Response metadata for users.

UserResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the user entity.

UserUpdate

Bases: UserBase, BaseZenModel

Update model for users.

Functions
create_copy(exclude: AbstractSet[str]) -> UserUpdate

Create a copy of the current instance.

Parameters:

Name Type Description Default
exclude AbstractSet[str]

Fields to exclude from the copy.

required

Returns:

Type Description
UserUpdate

A copy of the current instance.

Source code in src/zenml/models/v2/core/user.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def create_copy(self, exclude: AbstractSet[str]) -> "UserUpdate":
    """Create a copy of the current instance.

    Args:
        exclude: Fields to exclude from the copy.

    Returns:
        A copy of the current instance.
    """
    return UserUpdate(
        **self.model_dump(
            exclude=set(exclude),
            exclude_unset=True,
        )
    )
user_email_updates() -> UserUpdate

Validate that the UserUpdateModel conforms to the email-opt-in-flow.

Returns:

Type Description
UserUpdate

The validated values.

Raises:

Type Description
ValueError

If the email was not provided when the email_opted_in field was set to True.

Source code in src/zenml/models/v2/core/user.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
@model_validator(mode="after")
def user_email_updates(self) -> "UserUpdate":
    """Validate that the UserUpdateModel conforms to the email-opt-in-flow.

    Returns:
        The validated values.

    Raises:
        ValueError: If the email was not provided when the email_opted_in
            field was set to True.
    """
    # When someone sets the email, or updates the email and hasn't
    #  before explicitly opted out, they are opted in
    if self.email is not None:
        if self.email_opted_in is None:
            self.email_opted_in = True

    # It should not be possible to do opt in without an email
    if self.email_opted_in is True:
        if self.email is None:
            raise ValueError(
                "Please provide an email, when you are opting-in with "
                "your email."
            )
    return self
workspace

Models representing workspaces.

Classes
WorkspaceFilter

Bases: BaseFilter

Model to enable advanced filtering of all Workspaces.

WorkspaceRequest

Bases: BaseRequest

Request model for workspaces.

WorkspaceResponse

Bases: BaseIdentifiedResponse[WorkspaceResponseBody, WorkspaceResponseMetadata, WorkspaceResponseResources]

Response model for workspaces.

Attributes
description: str property

The description property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> WorkspaceResponse

Get the hydrated version of this workspace.

Returns:

Type Description
WorkspaceResponse

an instance of the same entity with the metadata field attached.

Source code in src/zenml/models/v2/core/workspace.py
101
102
103
104
105
106
107
108
109
def get_hydrated_version(self) -> "WorkspaceResponse":
    """Get the hydrated version of this workspace.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    from zenml.client import Client

    return Client().zen_store.get_workspace(self.id)
WorkspaceResponseBody

Bases: BaseDatedResponseBody

Response body for workspaces.

WorkspaceResponseMetadata

Bases: BaseResponseMetadata

Response metadata for workspaces.

WorkspaceResponseResources

Bases: BaseResponseResources

Class for all resource models associated with the workspace entity.

WorkspaceUpdate

Bases: BaseUpdate

Update model for workspaces.

misc
Modules
auth_models

Models representing OAuth2 requests and responses.

Classes
OAuthDeviceAuthorizationRequest

Bases: BaseModel

OAuth2 device authorization grant request.

OAuthDeviceAuthorizationResponse

Bases: BaseModel

OAuth2 device authorization grant response.

OAuthDeviceTokenRequest

Bases: BaseModel

OAuth2 device authorization grant request.

OAuthDeviceUserAgentHeader

Bases: BaseModel

OAuth2 device user agent header.

Functions
decode(header_str: str) -> OAuthDeviceUserAgentHeader classmethod

Decode the user agent header.

Parameters:

Name Type Description Default
header_str str

The user agent header string value.

required

Returns:

Type Description
OAuthDeviceUserAgentHeader

The decoded user agent header.

Source code in src/zenml/models/v2/misc/auth_models.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@classmethod
def decode(cls, header_str: str) -> "OAuthDeviceUserAgentHeader":
    """Decode the user agent header.

    Args:
        header_str: The user agent header string value.

    Returns:
        The decoded user agent header.
    """
    header = cls()
    properties = header_str.strip().split(" ")
    for property in properties:
        try:
            key, value = property.split("/", maxsplit=1)
        except ValueError:
            continue
        if key == "Host":
            header.hostname = value
        elif key == "ZenML":
            header.zenml_version = value
        elif key == "Python":
            header.python_version = value
        elif key == "OS":
            header.os = value
    return header
encode() -> str

Encode the user agent header.

Returns:

Type Description
str

The encoded user agent header.

Source code in src/zenml/models/v2/misc/auth_models.py
85
86
87
88
89
90
91
92
93
94
95
96
def encode(self) -> str:
    """Encode the user agent header.

    Returns:
        The encoded user agent header.
    """
    return (
        f"Host/{self.hostname} "
        f"ZenML/{self.zenml_version} "
        f"Python/{self.python_version} "
        f"OS/{self.os}"
    )
OAuthDeviceVerificationRequest

Bases: BaseModel

OAuth2 device authorization verification request.

OAuthRedirectResponse

Bases: BaseModel

Redirect response.

OAuthTokenResponse

Bases: BaseModel

OAuth2 device authorization token response.

build_item

Model definition for pipeline build item.

Classes
BuildItem

Bases: BaseModel

Pipeline build item.

Attributes:

Name Type Description
image str

The image name or digest.

dockerfile Optional[str]

The contents of the Dockerfile used to build the image.

requirements Optional[str]

The pip requirements installed in the image. This is a string consisting of multiple concatenated requirements.txt files.

settings_checksum Optional[str]

Checksum of the settings used for the build.

contains_code bool

Whether the image contains user files.

requires_code_download bool

Whether the image needs to download files.

external_user

Models representing users.

Classes
ExternalUserModel

Bases: BaseModel

External user model.

info_models

Models representing full stack requests.

Classes
ComponentInfo

Bases: BaseModel

Information about each stack components when creating a full stack.

ResourcesInfo

Bases: BaseModel

Information about the resources needed for CLI and UI.

ServiceConnectorInfo

Bases: BaseModel

Information about the service connector when creating a full stack.

ServiceConnectorResourcesInfo

Bases: BaseModel

Information about the service connector resources needed for CLI and UI.

loaded_visualization

Model representing loaded visualizations.

Classes
LoadedVisualization

Bases: BaseModel

Model for loaded visualizations.

run_metadata

Utility classes for modeling run metadata.

Classes
RunMetadataEntry

Bases: BaseModel

Utility class to sort/list run metadata entries.

RunMetadataResource

Bases: BaseModel

Utility class to help identify resources to tag metadata to.

server_models

Model definitions for ZenML servers.

Classes
ServerDatabaseType

Bases: StrEnum

Enum for server database types.

ServerDeploymentType

Bases: StrEnum

Enum for server deployment types.

ServerLoadInfo

Bases: BaseModel

Domain model for ZenML server load information.

ServerModel

Bases: BaseModel

Domain model for ZenML servers.

Functions
is_local() -> bool

Return whether the server is running locally.

Returns:

Type Description
bool

True if the server is running locally, False otherwise.

Source code in src/zenml/models/v2/misc/server_models.py
146
147
148
149
150
151
152
153
154
155
156
def is_local(self) -> bool:
    """Return whether the server is running locally.

    Returns:
        True if the server is running locally, False otherwise.
    """
    from zenml.config.global_config import GlobalConfiguration

    # Local ZenML servers are identifiable by the fact that their
    # server ID is the same as the local client (user) ID.
    return self.id == GlobalConfiguration().user_id
is_pro_server() -> bool

Return whether the server is a ZenML Pro server.

Returns:

Type Description
bool

True if the server is a ZenML Pro server, False otherwise.

Source code in src/zenml/models/v2/misc/server_models.py
158
159
160
161
162
163
164
def is_pro_server(self) -> bool:
    """Return whether the server is a ZenML Pro server.

    Returns:
        True if the server is a ZenML Pro server, False otherwise.
    """
    return self.deployment_type == ServerDeploymentType.CLOUD
service_connector_type

Model definitions for ZenML service connectors.

Classes
AuthenticationMethodModel(config_class: Optional[Type[BaseModel]] = None, **values: Any)

Bases: BaseModel

Authentication method specification.

Describes the schema for the configuration and secrets that need to be provided to configure an authentication method.

Initialize the authentication method.

Parameters:

Name Type Description Default
config_class Optional[Type[BaseModel]]

The configuration class for the authentication method.

None
**values Any

The data to initialize the authentication method with.

{}
Source code in src/zenml/models/v2/misc/service_connector_type.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self, config_class: Optional[Type[BaseModel]] = None, **values: Any
):
    """Initialize the authentication method.

    Args:
        config_class: The configuration class for the authentication
            method.
        **values: The data to initialize the authentication method with.
    """
    if config_class:
        values["config_schema"] = config_class.model_json_schema()

    super().__init__(**values)
    self._config_class = config_class
Attributes
config_class: Optional[Type[BaseModel]] property

Get the configuration class for the authentication method.

Returns:

Type Description
Optional[Type[BaseModel]]

The configuration class for the authentication method.

Functions
supports_temporary_credentials() -> bool

Check if the authentication method supports temporary credentials.

Returns:

Type Description
bool

True if the authentication method supports temporary credentials,

bool

False otherwise.

Source code in src/zenml/models/v2/misc/service_connector_type.py
157
158
159
160
161
162
163
164
165
166
167
168
def supports_temporary_credentials(self) -> bool:
    """Check if the authentication method supports temporary credentials.

    Returns:
        True if the authentication method supports temporary credentials,
        False otherwise.
    """
    return (
        self.min_expiration_seconds is not None
        or self.max_expiration_seconds is not None
        or self.default_expiration_seconds is not None
    )
validate_expiration(expiration_seconds: Optional[int]) -> Optional[int]

Validate the expiration time.

Parameters:

Name Type Description Default
expiration_seconds Optional[int]

The expiration time in seconds. If None, the default expiration time is used, if applicable.

required

Returns:

Type Description
Optional[int]

The expiration time in seconds or None if not applicable.

Raises:

Type Description
ValueError

If the expiration time is not valid.

Source code in src/zenml/models/v2/misc/service_connector_type.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def validate_expiration(
    self, expiration_seconds: Optional[int]
) -> Optional[int]:
    """Validate the expiration time.

    Args:
        expiration_seconds: The expiration time in seconds. If None, the
            default expiration time is used, if applicable.

    Returns:
        The expiration time in seconds or None if not applicable.

    Raises:
        ValueError: If the expiration time is not valid.
    """
    if not self.supports_temporary_credentials():
        if expiration_seconds is not None:
            # Expiration is not supported
            raise ValueError(
                "Expiration time is not supported for this authentication "
                f"method but a value was provided: {expiration_seconds}"
            )

        return None

    expiration_seconds = (
        expiration_seconds or self.default_expiration_seconds
    )

    if expiration_seconds is None:
        return None

    if self.min_expiration_seconds is not None:
        if expiration_seconds < self.min_expiration_seconds:
            raise ValueError(
                f"Expiration time must be at least "
                f"{self.min_expiration_seconds} seconds."
            )

    if self.max_expiration_seconds is not None:
        if expiration_seconds > self.max_expiration_seconds:
            raise ValueError(
                f"Expiration time must be at most "
                f"{self.max_expiration_seconds} seconds."
            )

    return expiration_seconds
ResourceTypeModel

Bases: BaseModel

Resource type specification.

Describes the authentication methods and resource instantiation model for one or more resource types.

Attributes
emojified_resource_type: str property

Get the emojified resource type.

Returns:

Type Description
str

The emojified resource type.

ServiceConnectorRequirements

Bases: BaseModel

Service connector requirements.

Describes requirements that a service connector consumer has for a service connector instance that it needs in order to access a resource.

Attributes:

Name Type Description
connector_type Optional[str]

The type of service connector that is required. If omitted, any service connector type can be used.

resource_type str

The type of resource that the service connector instance must be able to access.

resource_id_attr Optional[str]

The name of an attribute in the stack component configuration that contains the resource ID of the resource that the service connector instance must be able to access.

Functions
is_satisfied_by(connector: Union[ServiceConnectorResponse, ServiceConnectorRequest], component: Union[ComponentResponse, ComponentBase]) -> Tuple[bool, str]

Check if the requirements are satisfied by a connector.

Parameters:

Name Type Description Default
connector Union[ServiceConnectorResponse, ServiceConnectorRequest]

The connector to check.

required
component Union[ComponentResponse, ComponentBase]

The stack component that the connector is associated with.

required

Returns:

Type Description
bool

True if the requirements are satisfied, False otherwise, and a

str

message describing the reason for the failure.

Source code in src/zenml/models/v2/misc/service_connector_type.py
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
def is_satisfied_by(
    self,
    connector: Union[
        "ServiceConnectorResponse", "ServiceConnectorRequest"
    ],
    component: Union["ComponentResponse", "ComponentBase"],
) -> Tuple[bool, str]:
    """Check if the requirements are satisfied by a connector.

    Args:
        connector: The connector to check.
        component: The stack component that the connector is associated
            with.

    Returns:
        True if the requirements are satisfied, False otherwise, and a
        message describing the reason for the failure.
    """
    if self.connector_type and self.connector_type != connector.type:
        return (
            False,
            f"connector type '{connector.type}' does not match the "
            f"'{self.connector_type}' connector type specified in the "
            "stack component requirements",
        )
    if self.resource_type not in connector.resource_types:
        return False, (
            f"connector does not provide the '{self.resource_type}' "
            "resource type specified in the stack component requirements. "
            "Only the following resource types are supported: "
            f"{', '.join(connector.resource_types)}"
        )
    if self.resource_id_attr:
        resource_id = component.configuration.get(self.resource_id_attr)
        if not resource_id:
            return (
                False,
                f"the '{self.resource_id_attr}' stack component "
                f"configuration attribute plays the role of resource "
                f"identifier, but the stack component does not contain a "
                f"'{self.resource_id_attr}' attribute. Please add the "
                f"'{self.resource_id_attr}' attribute to the stack "
                "component configuration and try again.",
            )

    return True, ""
ServiceConnectorResourcesModel

Bases: BaseModel

Service connector resources list.

Lists the resource types and resource instances that a service connector can provide access to.

Attributes
emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

resource_types: List[str] property

Get the resource types.

Returns:

Type Description
List[str]

The resource types.

resources_dict: Dict[str, ServiceConnectorTypedResourcesModel] property

Get the resources as a dictionary indexed by resource type.

Returns:

Type Description
Dict[str, ServiceConnectorTypedResourcesModel]

The resources as a dictionary indexed by resource type.

type: str property

Get the connector type.

Returns:

Type Description
str

The connector type.

Functions
from_connector_model(connector_model: ServiceConnectorResponse, resource_type: Optional[str] = None) -> ServiceConnectorResourcesModel classmethod

Initialize a resource model from a connector model.

Parameters:

Name Type Description Default
connector_model ServiceConnectorResponse

The connector model.

required
resource_type Optional[str]

The resource type to set on the resource model. If omitted, the resource type is set according to the connector model.

None

Returns:

Type Description
ServiceConnectorResourcesModel

A resource list model instance.

Source code in src/zenml/models/v2/misc/service_connector_type.py
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
@classmethod
def from_connector_model(
    cls,
    connector_model: "ServiceConnectorResponse",
    resource_type: Optional[str] = None,
) -> "ServiceConnectorResourcesModel":
    """Initialize a resource model from a connector model.

    Args:
        connector_model: The connector model.
        resource_type: The resource type to set on the resource model. If
            omitted, the resource type is set according to the connector
            model.

    Returns:
        A resource list model instance.
    """
    resources = cls(
        id=connector_model.id,
        name=connector_model.name,
        connector_type=connector_model.type,
    )

    resource_types = resource_type or connector_model.resource_types
    for resource_type in resource_types:
        resources.resources.append(
            ServiceConnectorTypedResourcesModel(
                resource_type=resource_type,
                resource_ids=[connector_model.resource_id]
                if connector_model.resource_id
                else None,
            )
        )

    return resources
get_default_resource_id() -> Optional[str]

Get the default resource ID, if included in the resource list.

The default resource ID is a resource ID supplied by the connector implementation only for resource types that do not support multiple instances.

Returns:

Type Description
Optional[str]

The default resource ID, or None if no resource ID is set.

Source code in src/zenml/models/v2/misc/service_connector_type.py
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
def get_default_resource_id(self) -> Optional[str]:
    """Get the default resource ID, if included in the resource list.

    The default resource ID is a resource ID supplied by the connector
    implementation only for resource types that do not support multiple
    instances.

    Returns:
        The default resource ID, or None if no resource ID is set.
    """
    if len(self.resources) != 1:
        # multi-type connectors do not have a default resource ID
        return None

    if isinstance(self.connector_type, str):
        # can't determine default resource ID for unknown connector types
        return None

    resource_type_spec = self.connector_type.resource_type_dict[
        self.resources[0].resource_type
    ]
    if resource_type_spec.supports_instances:
        # resource types that support multiple instances do not have a
        # default resource ID
        return None

    resource_ids = self.resources[0].resource_ids

    if not resource_ids or len(resource_ids) != 1:
        return None

    return resource_ids[0]
get_emojified_resource_types(resource_type: Optional[str] = None) -> List[str]

Get the emojified resource type.

Parameters:

Name Type Description Default
resource_type Optional[str]

The resource type to get the emojified resource type for. If omitted, the emojified resource type for all resource types is returned.

None

Returns:

Type Description
List[str]

The list of emojified resource types.

Source code in src/zenml/models/v2/misc/service_connector_type.py
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
def get_emojified_resource_types(
    self, resource_type: Optional[str] = None
) -> List[str]:
    """Get the emojified resource type.

    Args:
        resource_type: The resource type to get the emojified resource type
            for. If omitted, the emojified resource type for all resource
            types is returned.


    Returns:
        The list of emojified resource types.
    """
    if not isinstance(self.connector_type, str):
        if resource_type:
            return [
                self.connector_type.resource_type_dict[
                    resource_type
                ].emojified_resource_type
            ]
        return [
            self.connector_type.resource_type_dict[
                resource_type
            ].emojified_resource_type
            for resource_type in self.resources_dict.keys()
        ]
    if resource_type:
        return [resource_type]
    return list(self.resources_dict.keys())
set_error(error: str, resource_type: Optional[str] = None) -> None

Set a global error message or an error for a single resource type.

Parameters:

Name Type Description Default
error str

The error message.

required
resource_type Optional[str]

The resource type to set the error message for. If omitted, or if there is only one resource type involved, the error message is (also) set globally.

None

Raises:

Type Description
KeyError

If the resource type is not found in the resources list.

Source code in src/zenml/models/v2/misc/service_connector_type.py
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
def set_error(
    self, error: str, resource_type: Optional[str] = None
) -> None:
    """Set a global error message or an error for a single resource type.

    Args:
        error: The error message.
        resource_type: The resource type to set the error message for. If
            omitted, or if there is only one resource type involved, the
            error message is (also) set globally.

    Raises:
        KeyError: If the resource type is not found in the resources list.
    """
    if resource_type:
        resource = self.resources_dict.get(resource_type)
        if not resource:
            raise KeyError(
                f"resource type '{resource_type}' not found in "
                "service connector resources list"
            )
        resource.error = error
        resource.resource_ids = None
        if len(self.resources) == 1:
            # If there is only one resource type involved, set the global
            # error message as well.
            self.error = error
    else:
        self.error = error
        for resource in self.resources:
            resource.error = error
            resource.resource_ids = None
set_resource_ids(resource_type: str, resource_ids: List[str]) -> None

Set the resource IDs for a resource type.

Parameters:

Name Type Description Default
resource_type str

The resource type to set the resource IDs for.

required
resource_ids List[str]

The resource IDs to set.

required

Raises:

Type Description
KeyError

If the resource type is not found in the resources list.

Source code in src/zenml/models/v2/misc/service_connector_type.py
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
def set_resource_ids(
    self, resource_type: str, resource_ids: List[str]
) -> None:
    """Set the resource IDs for a resource type.

    Args:
        resource_type: The resource type to set the resource IDs for.
        resource_ids: The resource IDs to set.

    Raises:
        KeyError: If the resource type is not found in the resources list.
    """
    resource = self.resources_dict.get(resource_type)
    if not resource:
        raise KeyError(
            f"resource type '{resource_type}' not found in "
            "service connector resources list"
        )
    resource.resource_ids = resource_ids
    resource.error = None
ServiceConnectorTypeModel

Bases: BaseModel

Service connector type specification.

Describes the types of resources to which the service connector can be used to gain access and the authentication methods that are supported by the service connector.

The connector type, resource types, resource IDs and authentication methods can all be used as search criteria to lookup and filter service connector instances that are compatible with the requirements of a consumer (e.g. a stack component).

Attributes
auth_method_dict: Dict[str, AuthenticationMethodModel] property

Returns a map of authentication methods to authentication method specifications.

Returns:

Type Description
Dict[str, AuthenticationMethodModel]

A map of authentication methods to authentication method

Dict[str, AuthenticationMethodModel]

specifications.

connector_class: Optional[Type[ServiceConnector]] property

Get the service connector class.

Returns:

Type Description
Optional[Type[ServiceConnector]]

The service connector class.

emojified_connector_type: str property

Get the emojified connector type.

Returns:

Type Description
str

The emojified connector type.

emojified_resource_types: List[str] property

Get the emojified connector types.

Returns:

Type Description
List[str]

The emojified connector types.

resource_type_dict: Dict[str, ResourceTypeModel] property

Returns a map of resource types to resource type specifications.

Returns:

Type Description
Dict[str, ResourceTypeModel]

A map of resource types to resource type specifications.

Functions
find_resource_specifications(auth_method: str, resource_type: Optional[str] = None) -> Tuple[AuthenticationMethodModel, Optional[ResourceTypeModel]]

Find the specifications for a configurable resource.

Validate the supplied connector configuration parameters against the connector specification and return the matching authentication method specification and resource specification.

Parameters:

Name Type Description Default
auth_method str

The name of the authentication method.

required
resource_type Optional[str]

The type of resource being configured.

None

Returns:

Type Description
AuthenticationMethodModel

The authentication method specification and resource specification

Optional[ResourceTypeModel]

for the specified authentication method and resource type.

Raises:

Type Description
KeyError

If the authentication method is not supported by the connector for the specified resource type and ID.

Source code in src/zenml/models/v2/misc/service_connector_type.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
def find_resource_specifications(
    self,
    auth_method: str,
    resource_type: Optional[str] = None,
) -> Tuple[AuthenticationMethodModel, Optional[ResourceTypeModel]]:
    """Find the specifications for a configurable resource.

    Validate the supplied connector configuration parameters against the
    connector specification and return the matching authentication method
    specification and resource specification.

    Args:
        auth_method: The name of the authentication method.
        resource_type: The type of resource being configured.

    Returns:
        The authentication method specification and resource specification
        for the specified authentication method and resource type.

    Raises:
        KeyError: If the authentication method is not supported by the
            connector for the specified resource type and ID.
    """
    # Verify the authentication method
    auth_method_dict = self.auth_method_dict
    if auth_method in auth_method_dict:
        # A match was found for the authentication method
        auth_method_spec = auth_method_dict[auth_method]
    else:
        # No match was found for the authentication method
        raise KeyError(
            f"connector type '{self.connector_type}' does not support the "
            f"'{auth_method}' authentication method. Supported "
            f"authentication methods are: {list(auth_method_dict.keys())}."
        )

    if resource_type is None:
        # No resource type was specified, so no resource type
        # specification can be returned.
        return auth_method_spec, None

    # Verify the resource type
    resource_type_dict = self.resource_type_dict
    if resource_type in resource_type_dict:
        resource_type_spec = resource_type_dict[resource_type]
    else:
        raise KeyError(
            f"connector type '{self.connector_type}' does not support "
            f"resource type '{resource_type}'. Supported resource types "
            f"are: {list(resource_type_dict.keys())}."
        )

    if auth_method not in resource_type_spec.auth_methods:
        raise KeyError(
            f"the '{self.connector_type}' connector type does not support "
            f"the '{auth_method}' authentication method for the "
            f"'{resource_type}' resource type. Supported authentication "
            f"methods are: {resource_type_spec.auth_methods}."
        )

    return auth_method_spec, resource_type_spec
set_connector_class(connector_class: Type[ServiceConnector]) -> None

Set the service connector class.

Parameters:

Name Type Description Default
connector_class Type[ServiceConnector]

The service connector class.

required
Source code in src/zenml/models/v2/misc/service_connector_type.py
321
322
323
324
325
326
327
328
329
def set_connector_class(
    self, connector_class: Type["ServiceConnector"]
) -> None:
    """Set the service connector class.

    Args:
        connector_class: The service connector class.
    """
    self._connector_class = connector_class
validate_auth_methods(values: List[AuthenticationMethodModel]) -> List[AuthenticationMethodModel] classmethod

Validate that the authentication methods are unique.

Parameters:

Name Type Description Default
values List[AuthenticationMethodModel]

The list of authentication methods.

required

Returns:

Type Description
List[AuthenticationMethodModel]

The list of authentication methods.

Raises:

Type Description
ValueError

If two or more authentication method specifications share the same authentication method value.

Source code in src/zenml/models/v2/misc/service_connector_type.py
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@field_validator("auth_methods")
@classmethod
def validate_auth_methods(
    cls, values: List[AuthenticationMethodModel]
) -> List[AuthenticationMethodModel]:
    """Validate that the authentication methods are unique.

    Args:
        values: The list of authentication methods.

    Returns:
        The list of authentication methods.

    Raises:
        ValueError: If two or more authentication method specifications
            share the same authentication method value.
    """
    # Gather all auth methods from the list of auth method
    # specifications.
    auth_methods = [a.auth_method for a in values]
    if len(auth_methods) != len(set(auth_methods)):
        raise ValueError(
            "Two or more authentication method specifications must not "
            "share the same authentication method value."
        )

    return values
validate_resource_types(values: List[ResourceTypeModel]) -> List[ResourceTypeModel] classmethod

Validate that the resource types are unique.

Parameters:

Name Type Description Default
values List[ResourceTypeModel]

The list of resource types.

required

Returns:

Type Description
List[ResourceTypeModel]

The list of resource types.

Raises:

Type Description
ValueError

If two or more resource type specifications list the same resource type.

Source code in src/zenml/models/v2/misc/service_connector_type.py
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@field_validator("resource_types")
@classmethod
def validate_resource_types(
    cls, values: List[ResourceTypeModel]
) -> List[ResourceTypeModel]:
    """Validate that the resource types are unique.

    Args:
        values: The list of resource types.

    Returns:
        The list of resource types.

    Raises:
        ValueError: If two or more resource type specifications list the
            same resource type.
    """
    # Gather all resource types from the list of resource type
    # specifications.
    resource_types = [r.resource_type for r in values]
    if len(resource_types) != len(set(resource_types)):
        raise ValueError(
            "Two or more resource type specifications must not list "
            "the same resource type."
        )

    return values
ServiceConnectorTypedResourcesModel

Bases: BaseModel

Service connector typed resources list.

Lists the resource instances that a service connector can provide access to.

Functions
stack_deployment

Models related to cloud stack deployments.

Classes
DeployedStack

Bases: BaseModel

Information about a deployed stack.

StackDeploymentConfig

Bases: BaseModel

Configuration about a stack deployment.

StackDeploymentInfo

Bases: BaseModel

Information about a stack deployment.

user_auth

Model definition for auth users.

Classes
UserAuthModel

Bases: BaseZenModel

Authentication Model for the User.

This model is only used server-side. The server endpoints can use this model to authenticate the user credentials (Token, Password).

Functions
get_hashed_activation_token() -> Optional[str]

Returns the hashed activation token, if configured.

Returns:

Type Description
Optional[str]

The hashed activation token.

Source code in src/zenml/models/v2/misc/user_auth.py
139
140
141
142
143
144
145
def get_hashed_activation_token(self) -> Optional[str]:
    """Returns the hashed activation token, if configured.

    Returns:
        The hashed activation token.
    """
    return self._get_hashed_secret(self.activation_token)
get_hashed_password() -> Optional[str]

Returns the hashed password, if configured.

Returns:

Type Description
Optional[str]

The hashed password.

Source code in src/zenml/models/v2/misc/user_auth.py
131
132
133
134
135
136
137
def get_hashed_password(self) -> Optional[str]:
    """Returns the hashed password, if configured.

    Returns:
        The hashed password.
    """
    return self._get_hashed_secret(self.password)
get_password() -> Optional[str]

Get the password.

Returns:

Type Description
Optional[str]

The password as a plain string, if it exists.

Source code in src/zenml/models/v2/misc/user_auth.py
121
122
123
124
125
126
127
128
129
def get_password(self) -> Optional[str]:
    """Get the password.

    Returns:
        The password as a plain string, if it exists.
    """
    if self.password is None:
        return None
    return self.password.get_secret_value()
verify_activation_token(activation_token: str, user: Optional[UserAuthModel] = None) -> bool classmethod

Verifies a given activation token against the stored token.

Parameters:

Name Type Description Default
activation_token str

Input activation token to be verified.

required
user Optional[UserAuthModel]

User for which the activation token is to be verified.

None

Returns:

Type Description
bool

True if the token is valid.

Source code in src/zenml/models/v2/misc/user_auth.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@classmethod
def verify_activation_token(
    cls, activation_token: str, user: Optional["UserAuthModel"] = None
) -> bool:
    """Verifies a given activation token against the stored token.

    Args:
        activation_token: Input activation token to be verified.
        user: User for which the activation token is to be verified.

    Returns:
        True if the token is valid.
    """
    # even when the user or token is not set, we still want to execute the
    # token hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    token_hash: str = ""
    if (
        user is not None
        # Disable activation tokens for service accounts as an extra
        # security measure. Service accounts should only be used with API
        # keys.
        and not user.is_service_account
        and user.activation_token is not None
        and not user.active
    ):
        token_hash = user.get_hashed_activation_token() or ""
    pwd_context = cls._get_crypt_context()
    return pwd_context.verify(activation_token, token_hash)
verify_password(plain_password: str, user: Optional[UserAuthModel] = None) -> bool classmethod

Verifies a given plain password against the stored password.

Parameters:

Name Type Description Default
plain_password str

Input password to be verified.

required
user Optional[UserAuthModel]

User for which the password is to be verified.

None

Returns:

Type Description
bool

True if the passwords match.

Source code in src/zenml/models/v2/misc/user_auth.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@classmethod
def verify_password(
    cls, plain_password: str, user: Optional["UserAuthModel"] = None
) -> bool:
    """Verifies a given plain password against the stored password.

    Args:
        plain_password: Input password to be verified.
        user: User for which the password is to be verified.

    Returns:
        True if the passwords match.
    """
    # even when the user or password is not set, we still want to execute
    # the password hash verification to protect against response discrepancy
    # attacks (https://cwe.mitre.org/data/definitions/204.html)
    password_hash: Optional[str] = None
    if (
        user is not None
        # Disable password verification for service accounts as an extra
        # security measure. Service accounts should only be used with API
        # keys.
        and not user.is_service_account
        and user.password is not None
    ):  # and user.active:
        password_hash = user.get_hashed_password()
    pwd_context = cls._get_crypt_context()
    return pwd_context.verify(plain_password, password_hash)