Skip to content

Environment

zenml.environment

Environment implementation.

Attributes

INSIDE_ZENML_CONTAINER = handle_bool_env_var(ENV_ZENML_CONTAINER, False) module-attribute

logger = get_logger(__name__) module-attribute

Classes

Environment()

Provides environment information.

Initializes an Environment instance.

Note: Environment is a singleton class, which means this method will only get called once. All following Environment() calls will return the previously initialized instance.

Source code in src/zenml/environment.py
109
110
111
112
113
114
115
def __init__(self) -> None:
    """Initializes an Environment instance.

    Note: Environment is a singleton class, which means this method will
    only get called once. All following `Environment()` calls will return
    the previously initialized instance.
    """
Functions
get_python_packages() -> List[str] staticmethod

Returns a list of installed Python packages.

Raises:

Type Description
RuntimeError

If the process to get the list of installed packages fails.

Returns:

Type Description
List[str]

List of installed packages in pip freeze format.

Source code in src/zenml/environment.py
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
@staticmethod
def get_python_packages() -> List[str]:
    """Returns a list of installed Python packages.

    Raises:
        RuntimeError: If the process to get the list of installed packages
            fails.

    Returns:
        List of installed packages in pip freeze format.
    """
    try:
        output = subprocess.check_output(["pip", "freeze"]).decode()
        return output.strip().split("\n")
    except subprocess.CalledProcessError:
        raise RuntimeError(
            "Failed to get list of installed Python packages"
        )
get_system_info() -> Dict[str, str] staticmethod

Information about the operating system.

Returns:

Type Description
Dict[str, str]

A dictionary containing information about the operating system.

Source code in src/zenml/environment.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@staticmethod
def get_system_info() -> Dict[str, str]:
    """Information about the operating system.

    Returns:
        A dictionary containing information about the operating system.
    """
    system = platform.system()

    if system == "Windows":
        release, version, csd, ptype = platform.win32_ver()

        return {
            "os": "windows",
            "windows_version_release": release,
            "windows_version": version,
            "windows_version_service_pack": csd,
            "windows_version_os_type": ptype,
        }

    if system == "Darwin":
        return {"os": "mac", "mac_version": platform.mac_ver()[0]}

    if system == "Linux":
        return {
            "os": "linux",
            "linux_distro": distro.id(),
            "linux_distro_like": distro.like(),
            "linux_distro_version": distro.version(),
        }

    # We don't collect data for any other system.
    return {"os": "unknown"}
in_bitbucket_ci() -> bool staticmethod

If the current Python process is running in Bitbucket CI.

Returns:

Type Description
bool

True if the current Python process is running in Bitbucket

bool

CI, False otherwise.

Source code in src/zenml/environment.py
324
325
326
327
328
329
330
331
332
@staticmethod
def in_bitbucket_ci() -> bool:
    """If the current Python process is running in Bitbucket CI.

    Returns:
        `True` if the current Python process is running in Bitbucket
        CI, `False` otherwise.
    """
    return "BITBUCKET_BUILD_NUMBER" in os.environ
in_ci() -> bool staticmethod

If the current Python process is running in any CI.

Returns:

Type Description
bool

True if the current Python process is running in any

bool

CI, False otherwise.

Source code in src/zenml/environment.py
334
335
336
337
338
339
340
341
342
@staticmethod
def in_ci() -> bool:
    """If the current Python process is running in any CI.

    Returns:
        `True` if the current Python process is running in any
        CI, `False` otherwise.
    """
    return "CI" in os.environ
in_circle_ci() -> bool staticmethod

If the current Python process is running in Circle CI.

Returns:

Type Description
bool

True if the current Python process is running in Circle

bool

CI, False otherwise.

Source code in src/zenml/environment.py
314
315
316
317
318
319
320
321
322
@staticmethod
def in_circle_ci() -> bool:
    """If the current Python process is running in Circle CI.

    Returns:
        `True` if the current Python process is running in Circle
        CI, `False` otherwise.
    """
    return "CIRCLECI" in os.environ
in_container() -> bool staticmethod

If the current python process is running in a container.

Returns:

Type Description
bool

True if the current python process is running in a

bool

container, False otherwise.

Source code in src/zenml/environment.py
160
161
162
163
164
165
166
167
168
169
@staticmethod
def in_container() -> bool:
    """If the current python process is running in a container.

    Returns:
        `True` if the current python process is running in a
        container, `False` otherwise.
    """
    # TODO [ENG-167]: Make this more reliable and add test.
    return INSIDE_ZENML_CONTAINER
in_docker() -> bool staticmethod

If the current python process is running in a docker container.

Returns:

Type Description
bool

True if the current python process is running in a docker

bool

container, False otherwise.

Source code in src/zenml/environment.py
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@staticmethod
def in_docker() -> bool:
    """If the current python process is running in a docker container.

    Returns:
        `True` if the current python process is running in a docker
        container, `False` otherwise.
    """
    if os.path.exists("./dockerenv") or os.path.exists("/.dockerinit"):
        return True

    try:
        with open("/proc/1/cgroup", "rt") as ifh:
            info = ifh.read()
            return "docker" in info
    except (FileNotFoundError, Exception):
        return False
in_github_actions() -> bool staticmethod

If the current Python process is running in GitHub Actions.

Returns:

Type Description
bool

True if the current Python process is running in GitHub

bool

Actions, False otherwise.

Source code in src/zenml/environment.py
294
295
296
297
298
299
300
301
302
@staticmethod
def in_github_actions() -> bool:
    """If the current Python process is running in GitHub Actions.

    Returns:
        `True` if the current Python process is running in GitHub
        Actions, `False` otherwise.
    """
    return "GITHUB_ACTIONS" in os.environ
in_github_codespaces() -> bool staticmethod

If the current Python process is running in GitHub Codespaces.

Returns:

Type Description
bool

True if the current Python process is running in GitHub Codespaces,

bool

False otherwise.

Source code in src/zenml/environment.py
247
248
249
250
251
252
253
254
255
256
257
258
259
@staticmethod
def in_github_codespaces() -> bool:
    """If the current Python process is running in GitHub Codespaces.

    Returns:
        `True` if the current Python process is running in GitHub Codespaces,
        `False` otherwise.
    """
    return (
        "CODESPACES" in os.environ
        or "GITHUB_CODESPACE_TOKEN" in os.environ
        or "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" in os.environ
    )
in_gitlab_ci() -> bool staticmethod

If the current Python process is running in GitLab CI.

Returns:

Type Description
bool

True if the current Python process is running in GitLab

bool

CI, False otherwise.

Source code in src/zenml/environment.py
304
305
306
307
308
309
310
311
312
@staticmethod
def in_gitlab_ci() -> bool:
    """If the current Python process is running in GitLab CI.

    Returns:
        `True` if the current Python process is running in GitLab
        CI, `False` otherwise.
    """
    return "GITLAB_CI" in os.environ
in_google_colab() -> bool staticmethod

If the current Python process is running in a Google Colab.

Returns:

Type Description
bool

True if the current Python process is running in a Google Colab,

bool

False otherwise.

Source code in src/zenml/environment.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@staticmethod
def in_google_colab() -> bool:
    """If the current Python process is running in a Google Colab.

    Returns:
        `True` if the current Python process is running in a Google Colab,
        `False` otherwise.
    """
    try:
        import google.colab  # noqa

        return True

    except ModuleNotFoundError:
        return False
in_kubernetes() -> bool staticmethod

If the current python process is running in a kubernetes pod.

Returns:

Type Description
bool

True if the current python process is running in a kubernetes

bool

pod, False otherwise.

Source code in src/zenml/environment.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
@staticmethod
def in_kubernetes() -> bool:
    """If the current python process is running in a kubernetes pod.

    Returns:
        `True` if the current python process is running in a kubernetes
        pod, `False` otherwise.
    """
    if "KUBERNETES_SERVICE_HOST" in os.environ:
        return True

    try:
        with open("/proc/1/cgroup", "rt") as ifh:
            info = ifh.read()
            return "kubepod" in info
    except (FileNotFoundError, Exception):
        return False
in_lightning_ai_studio() -> bool staticmethod

If the current Python process is running in Lightning.ai studios.

Returns:

Type Description
bool

True if the current Python process is running in Lightning.ai studios,

bool

False otherwise.

Source code in src/zenml/environment.py
355
356
357
358
359
360
361
362
363
364
365
366
@staticmethod
def in_lightning_ai_studio() -> bool:
    """If the current Python process is running in Lightning.ai studios.

    Returns:
        `True` if the current Python process is running in Lightning.ai studios,
        `False` otherwise.
    """
    return (
        "LIGHTNING_CLOUD_URL" in os.environ
        and "LIGHTNING_CLOUDSPACE_HOST" in os.environ
    )
in_notebook() -> bool staticmethod

If the current Python process is running in a notebook.

Returns:

Type Description
bool

True if the current Python process is running in a notebook,

bool

False otherwise.

Source code in src/zenml/environment.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
@staticmethod
def in_notebook() -> bool:
    """If the current Python process is running in a notebook.

    Returns:
        `True` if the current Python process is running in a notebook,
        `False` otherwise.
    """
    if Environment.in_google_colab():
        return True

    try:
        ipython = get_ipython()  # type: ignore[name-defined]
    except NameError:
        return False

    if ipython.__class__.__name__ in [
        "TerminalInteractiveShell",
        "ZMQInteractiveShell",
        "DatabricksShell",
    ]:
        return True
    return False
in_paperspace_gradient() -> bool staticmethod

If the current Python process is running in Paperspace Gradient.

Returns:

Type Description
bool

True if the current Python process is running in Paperspace

bool

Gradient, False otherwise.

Source code in src/zenml/environment.py
284
285
286
287
288
289
290
291
292
@staticmethod
def in_paperspace_gradient() -> bool:
    """If the current Python process is running in Paperspace Gradient.

    Returns:
        `True` if the current Python process is running in Paperspace
        Gradient, `False` otherwise.
    """
    return "PAPERSPACE_NOTEBOOK_REPO_ID" in os.environ
in_vscode_remote_container() -> bool staticmethod

If the current Python process is running in a VS Code Remote Container.

Returns:

Type Description
bool

True if the current Python process is running in a VS Code Remote Container,

bool

False otherwise.

Source code in src/zenml/environment.py
271
272
273
274
275
276
277
278
279
280
281
282
@staticmethod
def in_vscode_remote_container() -> bool:
    """If the current Python process is running in a VS Code Remote Container.

    Returns:
        `True` if the current Python process is running in a VS Code Remote Container,
        `False` otherwise.
    """
    return (
        "REMOTE_CONTAINERS" in os.environ
        or "VSCODE_REMOTE_CONTAINERS_SESSION" in os.environ
    )
in_wsl() -> bool staticmethod

If the current process is running in Windows Subsystem for Linux.

source: https://www.scivision.dev/python-detect-wsl/

Returns:

Type Description
bool

True if the current process is running in WSL, False otherwise.

Source code in src/zenml/environment.py
344
345
346
347
348
349
350
351
352
353
@staticmethod
def in_wsl() -> bool:
    """If the current process is running in Windows Subsystem for Linux.

    source: https://www.scivision.dev/python-detect-wsl/

    Returns:
        `True` if the current process is running in WSL, `False` otherwise.
    """
    return "microsoft-standard" in platform.uname().release
in_zenml_codespace() -> bool staticmethod

If the current Python process is running in ZenML Codespaces.

Returns:

Type Description
bool

True if the current Python process is running in ZenML Codespaces,

bool

False otherwise.

Source code in src/zenml/environment.py
261
262
263
264
265
266
267
268
269
@staticmethod
def in_zenml_codespace() -> bool:
    """If the current Python process is running in ZenML Codespaces.

    Returns:
        `True` if the current Python process is running in ZenML Codespaces,
        `False` otherwise.
    """
    return os.environ.get("ZENML_ENVIRONMENT") == "codespace"
python_version() -> str staticmethod

Returns the python version of the running interpreter.

Returns:

Name Type Description
str str

the python version

Source code in src/zenml/environment.py
151
152
153
154
155
156
157
158
@staticmethod
def python_version() -> str:
    """Returns the python version of the running interpreter.

    Returns:
        str: the python version
    """
    return platform.python_version()

EnvironmentType

Bases: StrEnum

Enum for environment types.

SingletonMetaClass(*args: Any, **kwargs: Any)

Bases: type

Singleton metaclass.

Use this metaclass to make any class into a singleton class:

class OneRing(metaclass=SingletonMetaClass):
    def __init__(self, owner):
        self._owner = owner

    @property
    def owner(self):
        return self._owner

the_one_ring = OneRing('Sauron')
the_lost_ring = OneRing('Frodo')
print(the_lost_ring.owner)  # Sauron
OneRing._clear() # ring destroyed

Initialize a singleton class.

Parameters:

Name Type Description Default
*args Any

Additional arguments.

()
**kwargs Any

Additional keyword arguments.

{}
Source code in src/zenml/utils/singleton.py
41
42
43
44
45
46
47
48
49
def __init__(cls, *args: Any, **kwargs: Any) -> None:
    """Initialize a singleton class.

    Args:
        *args: Additional arguments.
        **kwargs: Additional keyword arguments.
    """
    super().__init__(*args, **kwargs)
    cls.__singleton_instance: Optional["SingletonMetaClass"] = None
Functions

Functions

get_environment() -> str

Returns a string representing the execution environment of the pipeline.

Returns:

Name Type Description
str str

the execution environment

Source code in src/zenml/environment.py
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def get_environment() -> str:
    """Returns a string representing the execution environment of the pipeline.

    Returns:
        str: the execution environment
    """
    # Order is important here
    if Environment.in_kubernetes():
        return EnvironmentType.KUBERNETES
    elif Environment.in_github_actions():
        return EnvironmentType.GITHUB_ACTION
    elif Environment.in_gitlab_ci():
        return EnvironmentType.GITLAB_CI
    elif Environment.in_circle_ci():
        return EnvironmentType.CIRCLE_CI
    elif Environment.in_bitbucket_ci():
        return EnvironmentType.BITBUCKET_CI
    elif Environment.in_ci():
        return EnvironmentType.GENERIC_CI
    elif Environment.in_github_codespaces():
        return EnvironmentType.GITHUB_CODESPACES
    elif Environment.in_zenml_codespace():
        return EnvironmentType.ZENML_CODESPACE
    elif Environment.in_vscode_remote_container():
        return EnvironmentType.VSCODE_REMOTE_CONTAINER
    elif Environment.in_lightning_ai_studio():
        return EnvironmentType.LIGHTNING_AI_STUDIO
    elif Environment.in_docker():
        return EnvironmentType.DOCKER
    elif Environment.in_container():
        return EnvironmentType.CONTAINER
    elif Environment.in_google_colab():
        return EnvironmentType.COLAB
    elif Environment.in_paperspace_gradient():
        return EnvironmentType.PAPERSPACE
    elif Environment.in_notebook():
        return EnvironmentType.NOTEBOOK
    elif Environment.in_wsl():
        return EnvironmentType.WSL
    else:
        return EnvironmentType.NATIVE

get_logger(logger_name: str) -> logging.Logger

Main function to get logger name,.

Parameters:

Name Type Description Default
logger_name str

Name of logger to initialize.

required

Returns:

Type Description
Logger

A logger object.

Source code in src/zenml/logger.py
74
75
76
77
78
79
80
81
82
83
def get_logger(logger_name: str) -> logging.Logger:
    """Main function to get logger name,.

    Args:
        logger_name: Name of logger to initialize.

    Returns:
        A logger object.
    """
    return logging.getLogger(logger_name)

get_run_environment_dict() -> Dict[str, Any]

Returns a dictionary of the current run environment.

Everything that is returned here will be saved in the DB as pipeline_run.client_environment and pipeline_run.orchestrator_environment for client and orchestrator respectively.

Returns:

Type Description
Dict[str, Any]

A dictionary of the current run environment.

Source code in src/zenml/environment.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_run_environment_dict() -> Dict[str, Any]:
    """Returns a dictionary of the current run environment.

    Everything that is returned here will be saved in the DB as
    `pipeline_run.client_environment` and
    `pipeline_run.orchestrator_environment` for client and orchestrator
    respectively.

    Returns:
        A dictionary of the current run environment.
    """
    env_dict: Dict[str, Any] = {
        "environment": str(get_environment()),
        **Environment.get_system_info(),
        "python_version": Environment.python_version(),
        "zenml_version": zenml.__version__,
    }

    try:
        python_packages = Environment.get_python_packages()
    except RuntimeError:
        logger.warning("Failed to get list of installed Python packages")
    else:
        # TODO: We send the python packages as a string right now to keep
        # backwards compatibility with old versions. We should update this to
        # be a list of strings eventually.
        env_dict["python_packages"] = "\n".join(python_packages)

    return env_dict

Modules

zenml

Initialization for ZenML.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@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
71
72
73
74
75
76
77
78
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
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
378
379
380
381
382
383
384
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
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 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.
    """
    from passlib.context import CryptContext

    # 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
197
198
199
200
201
202
203
204
205
206
207
208
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
211
212
213
214
215
216
217
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: BaseRequest

Request model for API key rotation.

APIKeyUpdate

Bases: BaseUpdate

Update model for API keys.

ActionFilter

Bases: ProjectScopedFilter

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: ProjectScopedRequest

Model for creating a new action.

ActionResponse

Bases: ProjectScopedResponse[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: ProjectScopedResponseBody

Response body for actions.

ActionResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for actions.

ActionResponseResources

Bases: ProjectScopedResponseResources

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),
    )
ApiTransactionRequest

Bases: UserScopedRequest

Request model for API transactions.

ApiTransactionResponse

Bases: UserScopedResponse[ApiTransactionResponseBody, ApiTransactionResponseMetadata, ApiTransactionResponseResources]

Response model for API transactions.

Attributes
completed: bool property

The completed property.

Returns:

Type Description
bool

the value of the property.

method: str property

The method property.

Returns:

Type Description
str

the value of the property.

result: Optional[PlainSerializedSecretStr] property

The result property.

Returns:

Type Description
Optional[PlainSerializedSecretStr]

the value of the property.

url: str property

The url property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ApiTransactionResponse

Get the hydrated version of this API transaction.

Returns:

Type Description
ApiTransactionResponse

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

Source code in src/zenml/models/v2/core/api_transaction.py
130
131
132
133
134
135
136
def get_hydrated_version(self) -> "ApiTransactionResponse":
    """Get the hydrated version of this API transaction.

    Returns:
        an instance of the same entity with the metadata field attached.
    """
    return self
get_result() -> Optional[str]

Get the result of the API transaction.

Returns:

Type Description
Optional[str]

the result of the API transaction.

Source code in src/zenml/models/v2/core/api_transaction.py
176
177
178
179
180
181
182
183
184
185
def get_result(self) -> Optional[str]:
    """Get the result of the API transaction.

    Returns:
        the result of the API transaction.
    """
    result = self.result
    if result is None:
        return None
    return result.get_secret_value()
set_result(result: str) -> None

Set the result of the API transaction.

Parameters:

Name Type Description Default
result str

the result of the API transaction.

required
Source code in src/zenml/models/v2/core/api_transaction.py
187
188
189
190
191
192
193
def set_result(self, result: str) -> None:
    """Set the result of the API transaction.

    Args:
        result: the result of the API transaction.
    """
    self.get_body().result = SecretStr(result)
ApiTransactionResponseBody

Bases: UserScopedResponseBody

Response body for API transactions.

ApiTransactionResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for API transactions.

ApiTransactionResponseResources

Bases: UserScopedResponseResources

Response resources for API transactions.

ApiTransactionUpdate

Bases: BaseUpdate

Update model for stack components.

Functions
get_result() -> Optional[str]

Get the result of the API transaction.

Returns:

Type Description
Optional[str]

the result of the API transaction.

Source code in src/zenml/models/v2/core/api_transaction.py
72
73
74
75
76
77
78
79
80
81
def get_result(self) -> Optional[str]:
    """Get the result of the API transaction.

    Returns:
        the result of the API transaction.
    """
    result = self.result
    if result is None:
        return None
    return result.get_secret_value()
set_result(result: str) -> None

Set the result of the API transaction.

Parameters:

Name Type Description Default
result str

the result of the API transaction.

required
Source code in src/zenml/models/v2/core/api_transaction.py
83
84
85
86
87
88
89
def set_result(self, result: str) -> None:
    """Set the result of the API transaction.

    Args:
        result: the result of the API transaction.
    """
    self.result = SecretStr(result)
ArtifactConfig

Bases: BaseModel

Artifact configuration class.

Can be used in step definitions to define various artifact properties.

Example:

@step
def my_step() -> Annotated[
    int, ArtifactConfig(
        name="my_artifact",  # override the default artifact name
        version=42,  # set a custom version
        artifact_type=ArtifactType.MODEL,  # Specify the artifact type
        tags=["tag1", "tag2"],  # set custom tags
    )
]:
    return ...

Attributes:

Name Type Description
name Optional[str]

The name of the artifact: - static string e.g. "name" - dynamic string e.g. "name_{date}{time}{custom_placeholder}" If you use any placeholders besides date and time, you need to provide the values for them in the substitutions argument of the step decorator or the substitutions argument of with_options of the step.

version Optional[Union[str, int]]

The version of the artifact.

tags Optional[List[str]]

The tags of the artifact.

run_metadata Optional[Dict[str, MetadataType]]

Metadata to add to the artifact.

artifact_type Optional[ArtifactType]

Optional type of the artifact. If not given, the type specified by the materializer that is used to save this artifact is used.

ArtifactFilter

Bases: ProjectScopedFilter, 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
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
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: ProjectScopedRequest

Artifact request model.

ArtifactResponse

Bases: ProjectScopedResponse[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
120
121
122
123
124
125
126
127
128
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: ProjectScopedResponseBody

Response body for artifacts.

ArtifactResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for artifacts.

ArtifactResponseResources

Bases: ProjectScopedResponseResources

Class for all resource models associated with the Artifact Entity.

ArtifactUpdate

Bases: BaseUpdate

Artifact update model.

ArtifactVersionFilter

Bases: ProjectScopedFilter, TaggableFilter, RunMetadataFilterMixin

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
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
704
705
706
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
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,
        StepRunInputArtifactSchema,
        StepRunOutputArtifactSchema,
        StepRunSchema,
    )

    if self.artifact:
        value, operator = self._resolve_operator(self.artifact)
        artifact_filter = and_(
            ArtifactVersionSchema.artifact_id == ArtifactSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.artifact, table=ArtifactSchema
            ),
        )
        custom_filters.append(artifact_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)

    return custom_filters
ArtifactVersionIdentifier

Bases: VersionedIdentifier

Class for artifact version identifier group.

ArtifactVersionRequest

Bases: ProjectScopedRequest

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@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: ProjectScopedResponse[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.

content_hash: Optional[str] property

The content_hash property.

Returns:

Type Description
Optional[str]

the value of the property.

data_type: Source property

The data_type property.

Returns:

Type Description
Source

the value of the property.

item_count: Optional[int] property

The item_count property.

Returns:

Type Description
Optional[int]

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: str property

The version property.

Returns:

Type Description
str

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
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
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
284
285
286
287
288
289
290
291
292
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(disable_cache: bool = False) -> Any

Materializes (loads) the data stored in this artifact.

Parameters:

Name Type Description Default
disable_cache bool

Whether to disable the artifact cache.

False

Returns:

Type Description
Any

The materialized data.

Source code in src/zenml/models/v2/core/artifact_version.py
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
def load(self, disable_cache: bool = False) -> Any:
    """Materializes (loads) the data stored in this artifact.

    Args:
        disable_cache: Whether to disable the artifact cache.

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

    cache = InMemoryArtifactCache.get()

    if cache and (data := cache.get_artifact_data(self.id)):
        logger.debug("Returning artifact data (%s) from cache", self.id)
        return data

    data = load_artifact_from_response(self)
    if cache and not disable_cache:
        cache.set_artifact_data(self.id, data)
    return data
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
513
514
515
516
517
518
519
520
521
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: ProjectScopedResponseBody

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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
@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: ProjectScopedResponseMetadata

Response metadata for artifact versions.

ArtifactVersionResponseResources

Bases: ProjectScopedResponseResources

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

ArtifactVersionUpdate

Bases: BaseUpdate

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: Optional[ArtifactVersionResponse] property

The artifact version resource, if the response was hydrated with it.

Returns:

Type Description
Optional[ArtifactVersionResponse]

The artifact version resource, if available.

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
82
83
84
85
86
87
88
89
90
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.

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",
    project="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
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
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
 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 sqlalchemy import asc, desc

    column, operand = self.sorting_params

    if operand == SorterOps.DESCENDING:
        sort_clause = desc(getattr(table, column))
    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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
@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) -> 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

Returns:

Type Description
ColumnElement[bool]

The query conditions.

Source code in src/zenml/models/v2/base/filter.py
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
@staticmethod
def generate_custom_query_conditions_for_column(
    value: Any,
    table: Type["SQLModel"],
    column: str,
) -> "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.

    Returns:
        The query conditions.
    """
    value, operator = BaseFilter._resolve_operator(value)
    filter_ = FilterGenerator(table).define_filter(
        column=column, value=value, operator=operator
    )
    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
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
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 filter 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
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
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
            filter for the given value as part of the or condition.

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

    value, operator = BaseFilter._resolve_operator(value)
    # For the `oneof` operator, the return value here will be a list which
    # we do not want to convert.
    if isinstance(value, UUID):
        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
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
748
749
750
751
752
753
754
755
756
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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
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
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
@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
456
457
458
459
460
461
462
463
464
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
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
406
407
408
409
410
411
412
413
414
415
416
417
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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
221
222
223
224
225
226
227
228
229
230
231
232
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
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
276
277
278
279
280
281
282
283
284
285
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 = (
            type(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
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
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 = (
            type(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
213
214
215
216
217
218
219
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
155
156
157
158
159
160
161
162
163
164
165
166
167
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: ProjectScopedFilter

Model to enable advanced filtering of all code repositories.

CodeRepositoryRequest

Bases: ProjectScopedRequest

Request model for code repositories.

CodeRepositoryResponse

Bases: ProjectScopedResponse[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: ProjectScopedResponseBody

Response body for code repositories.

CodeRepositoryResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for code repositories.

CodeRepositoryResponseResources

Bases: ProjectScopedResponseResources

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

CodeRepositoryUpdate

Bases: BaseUpdate

Update model for code repositories.

ComponentBase

Bases: BaseModel

Base model for components.

ComponentFilter

Bases: UserScopedFilter

Model to enable advanced stack component filtering.

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
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
471
472
473
474
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
430
431
432
433
434
435
436
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, UserScopedRequest

Request model for stack 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@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: UserScopedResponse[ComponentResponseBody, ComponentResponseMetadata, ComponentResponseResources]

Response model for stack 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.

environment: Dict[str, str] property

The environment property.

Returns:

Type Description
Dict[str, 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.

secrets: List[UUID] property

The secrets property.

Returns:

Type Description
List[UUID]

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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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
277
278
279
280
281
282
283
284
285
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: UserScopedResponseBody

Response body for stack components.

ComponentResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for stack components.

ComponentResponseResources

Bases: UserScopedResponseResources

Response resources for stack components.

ComponentUpdate

Bases: BaseUpdate

Update model for stack components.

CuratedVisualizationRequest

Bases: ProjectScopedRequest

Request model for curated visualizations.

Each curated visualization links a pre-rendered artifact visualization to a single ZenML resource to surface it in the appropriate UI context. Supported resources include: - Deployments - Models - Pipelines - Pipeline Runs - Pipeline Snapshots - Projects

CuratedVisualizationResponse

Bases: ProjectScopedResponse[CuratedVisualizationResponseBody, CuratedVisualizationResponseMetadata, CuratedVisualizationResponseResources]

Response model for curated visualizations.

Attributes
artifact_version_id: UUID property

The artifact version ID.

Returns:

Type Description
UUID

The artifact version ID if available.

artifact_visualization: ArtifactVisualizationResponse property

The curated artifact visualization resource.

Returns:

Type Description
ArtifactVisualizationResponse

The artifact visualization resource.

artifact_visualization_id: UUID property

The artifact visualization ID.

Returns:

Type Description
UUID

The artifact visualization ID.

display_name: Optional[str] property

The display name of the visualization.

Returns:

Type Description
Optional[str]

The display name of the visualization.

display_order: Optional[int] property

The display order of the visualization.

Returns:

Type Description
Optional[int]

The display order of the visualization.

layout_size: CuratedVisualizationSize property

The layout size of the visualization.

Returns:

Type Description
CuratedVisualizationSize

The layout size of the visualization.

resource_id: UUID property

The identifier of the linked resource.

Returns:

Type Description
UUID

The resource identifier associated with this visualization.

resource_type: VisualizationResourceTypes property

The type of the linked resource.

Returns:

Type Description
VisualizationResourceTypes

The resource type associated with this visualization.

Functions
get_hydrated_version() -> CuratedVisualizationResponse

Get the hydrated version of this curated visualization.

Returns:

Type Description
CuratedVisualizationResponse

A hydrated instance of the same entity.

Source code in src/zenml/models/v2/core/curated_visualization.py
188
189
190
191
192
193
194
195
196
197
def get_hydrated_version(self) -> "CuratedVisualizationResponse":
    """Get the hydrated version of this curated visualization.

    Returns:
        A hydrated instance of the same entity.
    """
    from zenml.client import Client

    client = Client()
    return client.zen_store.get_curated_visualization(self.id)
CuratedVisualizationResponseBody

Bases: ProjectScopedResponseBody

Response body for curated visualizations.

CuratedVisualizationResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for curated visualizations.

CuratedVisualizationResponseResources

Bases: ProjectScopedResponseResources

Response resources included for curated visualizations.

CuratedVisualizationUpdate

Bases: BaseUpdate

Update model for curated visualizations.

DefaultComponentRequest

Bases: ComponentRequest

Internal component request model used only for default stack components.

DefaultStackRequest

Bases: StackRequest

Internal stack request model used only for default stacks.

DeployedStack

Bases: BaseModel

Information about a deployed stack.

DeploymentFilter

Bases: ProjectScopedFilter, TaggableFilter

Model to enable advanced filtering of deployments.

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/deployment.py
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
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
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 (
        DeploymentSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == "pipeline":
        query = query.outerjoin(
            PipelineSnapshotSchema,
            DeploymentSchema.snapshot_id == PipelineSnapshotSchema.id,
        ).outerjoin(
            PipelineSchema,
            PipelineSnapshotSchema.pipeline_id == PipelineSchema.id,
        )
        column: Any = PipelineSchema.name
    elif sort_by == "snapshot":
        query = query.outerjoin(
            PipelineSnapshotSchema,
            DeploymentSchema.snapshot_id == PipelineSnapshotSchema.id,
        )
        column = PipelineSnapshotSchema.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/deployment.py
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
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 (
        DeploymentSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
    )

    custom_filters = super().get_custom_filters(table)

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

    return custom_filters
DeploymentOperationalState

Bases: BaseModel

Operational state of a deployment.

DeploymentRequest

Bases: ProjectScopedRequest

Request model for deployments.

DeploymentResponse

Bases: ProjectScopedResponse[DeploymentResponseBody, DeploymentResponseMetadata, DeploymentResponseResources]

Response model for deployments.

Attributes
auth_key: Optional[str] property

The auth key of the deployment.

Returns:

Type Description
Optional[str]

The auth key of the deployment.

deployer: Optional[ComponentResponse] property

The deployer.

Returns:

Type Description
Optional[ComponentResponse]

The deployer.

deployer_id: Optional[UUID] property

The deployer ID.

Returns:

Type Description
Optional[UUID]

The deployer ID.

deployment_metadata: Dict[str, Any] property

The metadata of the deployment.

Returns:

Type Description
Dict[str, Any]

The metadata of the deployment.

pipeline: Optional[PipelineResponse] property

The pipeline.

Returns:

Type Description
Optional[PipelineResponse]

The pipeline.

snapshot: Optional[PipelineSnapshotResponse] property

The pipeline snapshot.

Returns:

Type Description
Optional[PipelineSnapshotResponse]

The pipeline snapshot.

snapshot_id: Optional[UUID] property

The pipeline snapshot ID.

Returns:

Type Description
Optional[UUID]

The pipeline snapshot ID.

stack: Optional[StackResponse] property

The stack.

Returns:

Type Description
Optional[StackResponse]

The stack.

status: Optional[DeploymentStatus] property

The status of the deployment.

Returns:

Type Description
Optional[DeploymentStatus]

The status of the deployment.

url: Optional[str] property

The URL of the deployment.

Returns:

Type Description
Optional[str]

The URL of the deployment.

visualizations: List[CuratedVisualizationResponse] property

The visualizations of the deployment.

Returns:

Type Description
List[CuratedVisualizationResponse]

The visualizations of the deployment.

Functions
get_hydrated_version() -> DeploymentResponse

Get the hydrated version of this deployment.

Returns:

Type Description
DeploymentResponse

an instance of the same entity with the metadata and resources fields

DeploymentResponse

attached.

Source code in src/zenml/models/v2/core/deployment.py
237
238
239
240
241
242
243
244
245
246
247
def get_hydrated_version(self) -> "DeploymentResponse":
    """Get the hydrated version of this deployment.

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

    client = Client()
    return client.get_deployment(self.id)
tags() -> List[TagResponse]

The tags of the deployment.

Returns:

Type Description
List[TagResponse]

The tags of the deployment.

Source code in src/zenml/models/v2/core/deployment.py
313
314
315
316
317
318
319
def tags(self) -> List["TagResponse"]:
    """The tags of the deployment.

    Returns:
        The tags of the deployment.
    """
    return self.get_resources().tags
DeploymentResponseBody

Bases: ProjectScopedResponseBody

Response body for deployments.

DeploymentResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for deployments.

DeploymentResponseResources

Bases: ProjectScopedResponseResources

Response resources for deployments.

DeploymentUpdate

Bases: BaseUpdate

Update model for deployments.

Functions
from_operational_state(operational_state: DeploymentOperationalState) -> DeploymentUpdate classmethod

Create an update from an operational state.

Parameters:

Name Type Description Default
operational_state DeploymentOperationalState

The operational state to create an update from.

required

Returns:

Type Description
DeploymentUpdate

The update.

Source code in src/zenml/models/v2/core/deployment.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
@classmethod
def from_operational_state(
    cls, operational_state: DeploymentOperationalState
) -> "DeploymentUpdate":
    """Create an update from an operational state.

    Args:
        operational_state: The operational state to create an update from.

    Returns:
        The update.
    """
    return cls(
        status=operational_state.status,
        url=operational_state.url,
        deployment_metadata=operational_state.metadata,
    )
EventSourceFilter

Bases: ProjectScopedFilter

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: ProjectScopedRequest

BaseModel for all event sources.

EventSourceResponse

Bases: ProjectScopedResponse[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: ProjectScopedResponseBody

ResponseBody for event sources.

EventSourceResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for event sources.

EventSourceResponseResources

Bases: ProjectScopedResponseResources

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

EventSourceUpdate

Bases: BaseUpdate

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,
    )
ExceptionInfo

Bases: BaseModel

Exception information.

ExternalArtifact

Bases: ExternalArtifactConfiguration

External artifacts can be used to provide values as input to ZenML steps.

ZenML steps accept either artifacts (=outputs of other steps), parameters (raw, JSON serializable values) or external artifacts. External artifacts can be used to provide any value as input to a step without needing to write an additional step that returns this value.

The external artifact needs to have a value associated with it that will be uploaded to the artifact store.

Parameters:

Name Type Description Default
value

The artifact value.

required
materializer

The materializer to use for saving the artifact value to the artifact store. Only used when value is provided.

required
store_artifact_metadata

Whether metadata for the artifact should be stored. Only used when value is provided.

required
store_artifact_visualizations

Whether visualizations for the artifact should be stored. Only used when value is provided.

required

Example:

from zenml import step, pipeline
from zenml.artifacts.external_artifact import ExternalArtifact
import numpy as np

@step
def my_step(value: np.ndarray) -> None:
  print(value)

my_array = np.array([1, 2, 3])

@pipeline
def my_pipeline():
  my_step(value=ExternalArtifact(my_array))
Attributes
config: ExternalArtifactConfiguration property

Returns the lightweight config without hard for JSON properties.

Returns:

Type Description
ExternalArtifactConfiguration

The config object to be evaluated in runtime by step interface.

Functions
external_artifact_validator() -> ExternalArtifact

Model validator for the external artifact.

Raises:

Type Description
ValueError

If an ID was set.

Returns:

Type Description
ExternalArtifact

The validated instance.

Source code in src/zenml/artifacts/external_artifact.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@model_validator(mode="after")
def external_artifact_validator(self) -> "ExternalArtifact":
    """Model validator for the external artifact.

    Raises:
        ValueError: If an ID was set.

    Returns:
        The validated instance.
    """
    if self.id:
        raise ValueError(
            "External artifacts can only be initialized with a value."
        )

    return self
upload_by_value() -> UUID

Uploads the artifact by value.

Returns:

Type Description
UUID

The uploaded artifact ID.

Source code in src/zenml/artifacts/external_artifact.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def upload_by_value(self) -> UUID:
    """Uploads the artifact by value.

    Returns:
        The uploaded artifact ID.
    """
    from zenml.artifacts.utils import save_artifact

    artifact_name = f"external_{uuid4()}"
    uri = os.path.join("external_artifacts", artifact_name)
    logger.info("Uploading external artifact to '%s'.", uri)

    artifact = save_artifact(
        name=artifact_name,
        data=self.value,
        extract_metadata=self.store_artifact_metadata,
        include_visualizations=self.store_artifact_visualizations,
        materializer=self.materializer,
        uri=uri,
        has_custom_name=False,
        save_type=ArtifactSaveType.EXTERNAL,
    )

    # To avoid duplicate uploads, switch to referencing the uploaded
    # artifact by ID
    self.id = artifact.id
    self.value = None

    logger.info("Finished uploading external artifact %s.", self.id)
    return self.id
ExternalUserModel

Bases: BaseModel

External user model.

FlavorFilter

Bases: UserScopedFilter

Model to enable advanced stack component flavor filtering.

FlavorRequest

Bases: UserScopedRequest

Request model for stack component flavors.

FlavorResponse

Bases: UserScopedResponse[FlavorResponseBody, FlavorResponseMetadata, FlavorResponseResources]

Response model for stack component 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.

display_name: str property

The display_name property.

Returns:

Type Description
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.

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
265
266
267
268
269
270
271
272
273
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 stack component flavors.

FlavorResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for stack component flavors.

FlavorResponseResources

Bases: UserScopedResponseResources

Response resources for stack component flavors.

FlavorUpdate

Bases: BaseUpdate

Update model for stack component flavors.

LoadedVisualization

Bases: BaseModel

Model for loaded visualizations.

LogsRequest

Bases: BaseRequest

Request model for logs.

Functions
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@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.
    """
    if value is not None:
        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: Optional[UUID] property

The artifact_store_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

log_store_id: Optional[UUID] property

The log_store_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

pipeline_run_id: Optional[UUID] property

The pipeline_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

source: str property

The source property.

Returns:

Type Description
str

the value of the property.

step_run_id: Optional[UUID] property

The step_run_id property.

Returns:

Type Description
Optional[UUID]

the value of the property.

uri: Optional[str] property

The uri property.

Returns:

Type Description
Optional[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
133
134
135
136
137
138
139
140
141
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.

Model

Bases: BaseModel

Model class to pass into pipeline or step to set it into a model context.

name: The name of the model. license: The license under which the model is created. description: The description of the model. audience: The target audience of the model. use_cases: The use cases of the model. limitations: The known limitations of the model. trade_offs: The tradeoffs of the model. ethics: The ethical implications of the model. tags: Tags associated with the model. version: The version name, version number or stage is optional and points model context to a specific version/stage. If skipped new version will be created. version also supports placeholders: standard {date} and {time} and any custom placeholders that are passed as substitutions in the pipeline or step decorators. save_models_to_registry: Whether to save all ModelArtifacts to Model Registry, if available in active stack.

Attributes
id: UUID property

Get version id from the Model Control Plane.

Returns:

Type Description
UUID

ID of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name).

Raises:

Type Description
RuntimeError

if model version doesn't exist and cannot be fetched from the Model Control Plane.

model_id: UUID property

Get model id from the Model Control Plane.

Returns:

Type Description
UUID

The UUID of the model containing this model version.

number: int property

Get version number from the Model Control Plane.

Returns:

Type Description
int

Number of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name).

Raises:

Type Description
KeyError

if model version doesn't exist and cannot be fetched from the Model Control Plane.

run_metadata: Dict[str, MetadataType] property

Get model version run metadata.

Returns:

Type Description
Dict[str, MetadataType]

The model version run metadata.

Raises:

Type Description
RuntimeError

If the model version run metadata cannot be fetched.

stage: Optional[ModelStages] property

Get version stage from the Model Control Plane.

Returns:

Type Description
Optional[ModelStages]

Stage of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name).

Functions
delete_all_artifacts(only_link: bool = True, delete_from_artifact_store: bool = False) -> None

Delete all artifacts linked to this model version.

Parameters:

Name Type Description Default
only_link bool

Whether to only delete the link to the artifact.

True
delete_from_artifact_store bool

Whether to delete the artifact from the artifact store.

False
Source code in src/zenml/model/model.py
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
def delete_all_artifacts(
    self,
    only_link: bool = True,
    delete_from_artifact_store: bool = False,
) -> None:
    """Delete all artifacts linked to this model version.

    Args:
        only_link: Whether to only delete the link to the artifact.
        delete_from_artifact_store: Whether to delete the artifact from
            the artifact store.
    """
    from zenml.client import Client

    client = Client()

    mv = self._get_or_create_model_version()

    if not only_link and delete_from_artifact_store:
        artifact_versions = pagination_utils.depaginate(
            client.list_artifact_versions,
            model_version_id=mv.id,
            project=mv.project_id,
        )
        for artifact_version in artifact_versions:
            client._delete_artifact_from_artifact_store(
                artifact_version=artifact_version
            )

    client.delete_all_model_version_artifact_links(mv.id, only_link)
delete_artifact(name: str, version: Optional[str] = None, only_link: bool = True, delete_metadata: bool = True, delete_from_artifact_store: bool = False) -> None

Delete the artifact linked to this model version.

Parameters:

Name Type Description Default
name str

The name of the artifact to delete.

required
version Optional[str]

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

None
only_link bool

Whether to only delete the link to the artifact.

True
delete_metadata bool

Whether to delete the metadata of the artifact.

True
delete_from_artifact_store bool

Whether to delete the artifact from the artifact store.

False
Source code in src/zenml/model/model.py
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
def delete_artifact(
    self,
    name: str,
    version: Optional[str] = None,
    only_link: bool = True,
    delete_metadata: bool = True,
    delete_from_artifact_store: bool = False,
) -> None:
    """Delete the artifact linked to this model version.

    Args:
        name: The name of the artifact to delete.
        version: The version of the artifact to delete (None for
            latest/non-versioned)
        only_link: Whether to only delete the link to the artifact.
        delete_metadata: Whether to delete the metadata of the artifact.
        delete_from_artifact_store: Whether to delete the artifact from the
            artifact store.
    """
    from zenml.client import Client
    from zenml.models import ArtifactVersionResponse

    artifact_version = self.get_artifact(name, version)
    if isinstance(artifact_version, ArtifactVersionResponse):
        client = Client()
        client.delete_model_version_artifact_link(
            model_version_id=self.id,
            artifact_version_id=artifact_version.id,
        )
        if not only_link:
            client.delete_artifact_version(
                name_id_or_prefix=artifact_version.id,
                delete_metadata=delete_metadata,
                delete_from_artifact_store=delete_from_artifact_store,
            )
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 the artifact or placeholder in the design time of the pipeline.

Source code in src/zenml/model/model.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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 the artifact or placeholder in the design time
            of the pipeline.
    """
    if lazy := self._lazy_artifact_get(name, version):
        return lazy

    return self._get_or_create_model_version().get_artifact(
        name=name,
        version=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 placeholder in the design

Optional[ArtifactVersionResponse]

time of the pipeline.

Source code in src/zenml/model/model.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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 placeholder in the design
        time of the pipeline.
    """
    if lazy := self._lazy_artifact_get(name, version):
        return lazy

    return self._get_or_create_model_version().get_data_artifact(
        name=name,
        version=version,
    )
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 placeholder in the

Optional[ArtifactVersionResponse]

design time of the pipeline.

Source code in src/zenml/model/model.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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 placeholder in the
        design time of the pipeline.
    """
    if lazy := self._lazy_artifact_get(name, version):
        return lazy

    return self._get_or_create_model_version().get_deployment_artifact(
        name=name,
        version=version,
    )
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 placeholder in the design time of the pipeline.

Source code in src/zenml/model/model.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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 placeholder in the design
            time of the pipeline.
    """
    if lazy := self._lazy_artifact_get(name, version):
        return lazy

    return self._get_or_create_model_version().get_model_artifact(
        name=name,
        version=version,
    )
load_artifact(name: str, version: Optional[str] = None) -> Any

Load artifact from the Model Control Plane.

Parameters:

Name Type Description Default
name str

Name of the artifact to load.

required
version Optional[str]

Version of the artifact to load.

None

Returns:

Type Description
Any

The loaded artifact.

Raises:

Type Description
ValueError

if the model version is not linked to any artifact with the given name and version.

Source code in src/zenml/model/model.py
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
def load_artifact(self, name: str, version: Optional[str] = None) -> Any:
    """Load artifact from the Model Control Plane.

    Args:
        name: Name of the artifact to load.
        version: Version of the artifact to load.

    Returns:
        The loaded artifact.

    Raises:
        ValueError: if the model version is not linked to any artifact with
            the given name and version.
    """
    from zenml.artifacts.utils import load_artifact
    from zenml.models import ArtifactVersionResponse

    artifact = self.get_artifact(name=name, version=version)

    if not isinstance(artifact, ArtifactVersionResponse):
        raise ValueError(
            f"Version {self.version} of model {self.name} does not have "
            f"an artifact with name {name} and version {version}."
        )

    return load_artifact(artifact.id, str(artifact.version))
log_metadata(metadata: Dict[str, MetadataType]) -> None

Log model version metadata.

This function can be used to log metadata for current model version.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
Source code in src/zenml/model/model.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
def log_metadata(
    self,
    metadata: Dict[str, "MetadataType"],
) -> None:
    """Log model version metadata.

    This function can be used to log metadata for current model version.

    Args:
        metadata: The metadata to log.
    """
    from zenml.client import Client
    from zenml.models import RunMetadataResource

    response = self._get_or_create_model_version()
    Client().create_run_metadata(
        metadata=metadata,
        resources=[
            RunMetadataResource(
                id=response.id, type=MetadataResourceTypes.MODEL_VERSION
            )
        ],
    )
set_stage(stage: Union[str, ModelStages], force: bool = False) -> None

Sets this Model 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
Source code in src/zenml/model/model.py
306
307
308
309
310
311
312
313
314
315
316
def set_stage(
    self, stage: Union[str, ModelStages], force: bool = False
) -> None:
    """Sets this Model 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.
    """
    self._get_or_create_model_version().set_stage(stage=stage, force=force)
ModelFilter

Bases: ProjectScopedFilter, TaggableFilter

Model to enable advanced filtering of all models.

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
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
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: ProjectScopedRequest

Request model for models.

ModelResponse

Bases: ProjectScopedResponse[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.

visualizations: List[CuratedVisualizationResponse] property

The visualizations property.

Returns:

Type Description
List[CuratedVisualizationResponse]

the value of the property.

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
209
210
211
212
213
214
215
216
217
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: ProjectScopedResponseBody

Response body for models.

ModelResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for models.

ModelResponseResources

Bases: ProjectScopedResponseResources

Class for all resource models associated with the model entity.

ModelUpdate

Bases: BaseUpdate

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: ProjectScopedFilter, TaggableFilter, RunMetadataFilterMixin

Filter model for model 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/model_version.py
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
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.
    """
    from sqlalchemy import and_

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

    custom_filters = super().get_custom_filters(table)

    if self.model:
        model_filter = and_(
            ModelVersionSchema.model_id == ModelSchema.id,  # type: ignore[arg-type]
            self.generate_name_or_id_query_conditions(
                value=self.model, table=ModelSchema
            ),
        )
        custom_filters.append(model_filter)

    return custom_filters
ModelVersionIdentifier

Bases: VersionedIdentifier

Class for model version identifier group.

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
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
207
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: ProjectScopedRequest

Request model for model versions.

ModelVersionResponse

Bases: ProjectScopedResponse[ModelVersionResponseBody, ModelVersionResponseMetadata, ModelVersionResponseResources]

Response model for model versions.

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

Data artifacts linked to this model version.

Returns:

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

Data artifacts linked to this model version.

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

Deployment artifacts linked to this model version.

Returns:

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

Deployment artifacts linked to this model version.

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

Model artifacts linked to this model version.

Returns:

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

Model artifacts linked to this model version.

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

Pipeline runs linked to this model version.

Returns:

Type Description
Dict[str, UUID]

Pipeline runs linked to this model version.

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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
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
263
264
265
266
267
268
269
270
271
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
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)
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
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
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
274
275
276
277
278
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
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: ProjectScopedResponseBody

Response body for model versions.

ModelVersionResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for model versions.

ModelVersionResponseResources

Bases: ProjectScopedResponseResources

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

ModelVersionUpdate

Bases: BaseUpdate

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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
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
423
424
425
426
427
428
429
430
431
432
433
434
435
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
409
410
411
412
413
414
415
416
417
418
419
420
421
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.

OAuthDeviceTokenRequest

Bases: BaseModel

OAuth2 device authorization grant request.

OAuthDeviceUpdate

Bases: BaseUpdate

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
107
108
109
110
111
112
113
114
115
116
117
118
119
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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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: ProjectScopedFilter

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
528
529
530
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
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, ProjectScopedRequest

Request model for pipelines builds.

PipelineBuildResponse

Bases: ProjectScopedResponse[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.

duration: Optional[int] property

The duration property.

Returns:

Type Description
Optional[int]

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
251
252
253
254
255
256
257
258
259
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
319
320
321
322
323
324
325
326
327
328
329
330
331
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
@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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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
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
289
290
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",
                "project",
            }
        )
    )
    yaml_dict.update(images)
    return yaml_dict
PipelineBuildResponseBody

Bases: ProjectScopedResponseBody

Response body for pipeline builds.

PipelineBuildResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for pipeline builds.

PipelineBuildResponseResources

Bases: ProjectScopedResponseResources

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

PipelineFilter

Bases: ProjectScopedFilter, TaggableFilter

Pipeline filter model.

Attributes
filter_by_latest_execution: bool property

Property returning whether filtering considers latest pipeline execution.

Returns:

Type Description
bool

True if latest pipeline execution filters are used (e.g. latest_run_status).

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
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
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
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,
        UserSchema,
    )

    if self.filter_by_latest_execution:
        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,
            ),
        )

        if self.latest_run_user:
            query = query.join(
                UserSchema, UserSchema.id == PipelineRunSchema.user_id
            )

            query = query.where(
                self.generate_name_or_id_query_conditions(
                    value=self.latest_run_user,
                    table=UserSchema,
                )
            )

        if self.latest_run_status:
            query = query.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
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
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: ProjectScopedRequest

Request model for pipelines.

PipelineResponse

Bases: ProjectScopedResponse[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
154
155
156
157
158
159
160
161
162
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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: ProjectScopedResponseBody

Response body for pipelines.

PipelineResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for pipelines.

PipelineResponseResources

Bases: ProjectScopedResponseResources

Class for all resource models associated with the pipeline entity.

PipelineRunDAG

Bases: BaseModel

Pipeline run DAG.

Classes
Edge

Bases: BaseModel

Edge in the pipeline run DAG.

Node

Bases: BaseModel

Node in the pipeline run DAG.

PipelineRunFilter

Bases: ProjectScopedFilter, TaggableFilter, RunMetadataFilterMixin

Model to enable advanced filtering of all pipeline runs.

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
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
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,
        PipelineRunSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
        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(
            PipelineSnapshotSchema,
            PipelineRunSchema.snapshot_id == PipelineSnapshotSchema.id,
        ).outerjoin(
            StackSchema,
            PipelineSnapshotSchema.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
 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
 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
 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
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
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,
        DeploymentSchema,
        ModelSchema,
        ModelVersionPipelineRunSchema,
        ModelVersionSchema,
        PipelineBuildSchema,
        PipelineRunSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
        ScheduleSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
        StepRunSchema,
    )

    if self.code_repository_id:
        code_repo_filter = and_(
            PipelineRunSchema.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.stack_id == StackSchema.id,
            StackSchema.id == self.stack_id,
        )
        custom_filters.append(stack_filter)

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

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

    if self.template_id:
        run_template_filter = and_(
            PipelineRunSchema.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.template_id == self.template_id,
        )
        custom_filters.append(run_template_filter)

    if self.source_snapshot_id:
        source_snapshot_filter = and_(
            PipelineRunSchema.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.source_snapshot_id
            == self.source_snapshot_id,
        )
        custom_filters.append(source_snapshot_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.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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.snapshot_id == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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.snapshot_id == PipelineSnapshotSchema.id,
                PipelineSnapshotSchema.build_id == PipelineBuildSchema.id,
                col(PipelineBuildSchema.is_local).is_(False),
                col(PipelineBuildSchema.stack_id).is_not(None),
            )
        else:
            templatable_filter = or_(
                col(PipelineRunSchema.snapshot_id).is_(None),
                and_(
                    PipelineRunSchema.snapshot_id
                    == PipelineSnapshotSchema.id,
                    col(PipelineSnapshotSchema.build_id).is_(None),
                ),
                and_(
                    PipelineRunSchema.snapshot_id
                    == PipelineSnapshotSchema.id,
                    PipelineSnapshotSchema.build_id
                    == PipelineBuildSchema.id,
                    or_(
                        col(PipelineBuildSchema.is_local).is_(True),
                        col(PipelineBuildSchema.stack_id).is_(None),
                    ),
                ),
            )

        custom_filters.append(templatable_filter)

    if self.triggered_by_step_run_id:
        trigger_filter = and_(
            PipelineRunSchema.triggered_by == StepRunSchema.id,
            PipelineRunSchema.triggered_by_type
            == PipelineRunTriggeredByType.STEP_RUN.value,
            self.generate_custom_query_conditions_for_column(
                value=self.triggered_by_step_run_id,
                table=StepRunSchema,
                column="id",
            ),
        )
        custom_filters.append(trigger_filter)

    if self.triggered_by_deployment_id:
        trigger_filter = and_(
            PipelineRunSchema.triggered_by == DeploymentSchema.id,
            PipelineRunSchema.triggered_by_type
            == PipelineRunTriggeredByType.DEPLOYMENT.value,
            self.generate_custom_query_conditions_for_column(
                value=self.triggered_by_deployment_id,
                table=DeploymentSchema,
                column="id",
            ),
        )
        custom_filters.append(trigger_filter)

    if self.linked_to_model_version_id:
        linked_to_model_version_filter = and_(
            PipelineRunSchema.id
            == ModelVersionPipelineRunSchema.pipeline_run_id,
            ModelVersionPipelineRunSchema.model_version_id
            == ModelVersionSchema.id,
            self.generate_custom_query_conditions_for_column(
                value=self.linked_to_model_version_id,
                table=ModelVersionSchema,
                column="id",
            ),
        )
        custom_filters.append(linked_to_model_version_filter)

    return custom_filters
PipelineRunIdentifier

Bases: BaseModel

Class grouping different pipeline run identifiers.

Attributes
value: str | UUID property

Resolves the set value out of id, name, prefix etc.

Returns:

Type Description
str | UUID

The id/name/prefix (if set, in this exact order).

PipelineRunRequest

Bases: ProjectScopedRequest

Request model for pipeline runs.

Attributes
is_placeholder_request: bool property

Whether the request is a placeholder request.

Returns:

Type Description
bool

Whether the request is a placeholder request.

PipelineRunResponse

Bases: ProjectScopedResponse[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, Any] property

The client_environment property.

Returns:

Type Description
Dict[str, Any]

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.

enable_heartbeat: bool property

The enable_heartbeat property.

Returns:

Type Description
bool

the value of the property.

end_time: Optional[datetime] property

The end_time property.

Returns:

Type Description
Optional[datetime]

the value of the property.

exception_info: Optional[ExceptionInfo] property

The exception_info property.

Returns:

Type Description
Optional[ExceptionInfo]

the value of the property.

in_progress: bool property

The in_progress property.

Returns:

Type Description
bool

the value of the property.

index: int property

The index property.

Returns:

Type Description
int

the value of the property.

is_templatable: bool property

The is_templatable property.

Returns:

Type Description
bool

the value of the property.

log_collection: Optional[List[LogsResponse]] property

The log_collection property.

Returns:

Type Description
Optional[List[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.

orchestrator_environment: Dict[str, Any] property

The orchestrator_environment property.

Returns:

Type Description
Dict[str, Any]

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.

snapshot: Optional[PipelineSnapshotResponse] property

The snapshot property.

Returns:

Type Description
Optional[PipelineSnapshotResponse]

the value of the property.

source_snapshot: Optional[PipelineSnapshotResponse] property

The source_snapshot property.

Returns:

Type Description
Optional[PipelineSnapshotResponse]

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.

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.

trigger_info: Optional[PipelineRunTriggerInfo] property

The trigger_info property.

Returns:

Type Description
Optional[PipelineRunTriggerInfo]

the value of the property.

triggered_by_deployment: bool property

The triggered_by_deployment property.

Returns:

Type Description
bool

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
358
359
360
361
362
363
364
365
366
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)
PipelineRunResponseBody

Bases: ProjectScopedResponseBody

Response body for pipeline runs.

PipelineRunResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for pipeline runs.

PipelineRunResponseResources

Bases: ProjectScopedResponseResources

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

PipelineRunTriggerInfo

Bases: BaseZenModel

Trigger information model.

PipelineRunUpdate

Bases: BaseUpdate

Pipeline run update model.

PipelineSnapshotBase

Bases: BaseZenModel

Base model for pipeline snapshots.

PipelineSnapshotFilter

Bases: ProjectScopedFilter, TaggableFilter

Model for filtering pipeline snapshots.

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_snapshot.py
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
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 (
        DeploymentSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
        StackSchema,
    )

    sort_by, operand = self.sorting_params

    if sort_by == "pipeline":
        query = query.outerjoin(
            PipelineSchema,
            PipelineSnapshotSchema.pipeline_id == PipelineSchema.id,
        )
        column = PipelineSchema.name
    elif sort_by == "stack":
        query = query.outerjoin(
            StackSchema,
            PipelineSnapshotSchema.stack_id == StackSchema.id,
        )
        column = StackSchema.name
    elif sort_by == "deployment":
        query = query.outerjoin(
            DeploymentSchema,
            PipelineSnapshotSchema.id == DeploymentSchema.snapshot_id,
        )
        column = DeploymentSchema.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_snapshot.py
706
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
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
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_, col, not_, select

    from zenml.zen_stores.schemas import (
        DeploymentSchema,
        PipelineBuildSchema,
        PipelineSchema,
        PipelineSnapshotSchema,
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    custom_filters = super().get_custom_filters(table)

    if self.named_only:
        custom_filters.append(
            col(PipelineSnapshotSchema.name).is_not(None)
        )

    if self.pipeline:
        pipeline_filter = and_(
            PipelineSnapshotSchema.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_(
            PipelineSnapshotSchema.stack_id == StackSchema.id,
            self.generate_name_or_id_query_conditions(
                value=self.stack,
                table=StackSchema,
            ),
        )
        custom_filters.append(stack_filter)

    if self.runnable is True:
        runnable_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.
            PipelineSnapshotSchema.build_id == PipelineBuildSchema.id,
            col(PipelineBuildSchema.is_local).is_(False),
            col(PipelineBuildSchema.stack_id).is_not(None),
        )

        custom_filters.append(runnable_filter)

    if self.deployable is True:
        deployer_exists = (
            select(StackComponentSchema.id)
            .where(
                StackComponentSchema.type
                == StackComponentType.DEPLOYER.value
            )
            .where(
                StackCompositionSchema.component_id
                == StackComponentSchema.id
            )
            .where(
                StackCompositionSchema.stack_id
                == PipelineSnapshotSchema.stack_id
            )
            .exists()
        )
        deployable_filter = and_(
            col(PipelineSnapshotSchema.build_id).is_not(None),
            deployer_exists,
        )

        custom_filters.append(deployable_filter)

    if self.deployed is not None:
        deployment_exists = (
            select(DeploymentSchema.id)
            .where(
                DeploymentSchema.snapshot_id == PipelineSnapshotSchema.id
            )
            .exists()
        )
        if self.deployed is True:
            deployed_filter = and_(deployment_exists)
        else:
            deployed_filter = and_(not_(deployment_exists))
        custom_filters.append(deployed_filter)

    return custom_filters
PipelineSnapshotRequest

Bases: PipelineSnapshotBase, ProjectScopedRequest

Request model for pipeline snapshots.

PipelineSnapshotResponse

Bases: ProjectScopedResponse[PipelineSnapshotResponseBody, PipelineSnapshotResponseMetadata, PipelineSnapshotResponseResources]

Response model for pipeline snapshots.

Attributes
build: Optional[PipelineBuildResponse] property

The build property.

Returns:

Type Description
Optional[PipelineBuildResponse]

the value of the property.

client_environment: Dict[str, Any] property

The client_environment property.

Returns:

Type Description
Dict[str, Any]

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.

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.

deployable: bool property

The deployable property.

Returns:

Type Description
bool

the value of the property.

deployment: Optional[DeploymentResponse] property

The deployment property.

Returns:

Type Description
Optional[DeploymentResponse]

the value of the property.

description: Optional[str] property

The description property.

Returns:

Type Description
Optional[str]

the value of the property.

is_dynamic: bool property

The is_dynamic property.

Returns:

Type Description
bool

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.

latest_run_user: Optional[UserResponse] property

The latest_run_user property.

Returns:

Type Description
Optional[UserResponse]

the value of the property.

pipeline: PipelineResponse property

The pipeline property.

Returns:

Type Description
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.

runnable: bool property

The runnable property.

Returns:

Type Description
bool

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.

source_code: Optional[str] property

The source_code property.

Returns:

Type Description
Optional[str]

the value of the property.

source_snapshot_id: Optional[UUID] property

The source_snapshot_id property.

Returns:

Type Description
Optional[UUID]

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.

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.

Functions
get_hydrated_version() -> PipelineSnapshotResponse

Return the hydrated version of this pipeline snapshot.

Returns:

Type Description
PipelineSnapshotResponse

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

Source code in src/zenml/models/v2/core/pipeline_snapshot.py
367
368
369
370
371
372
373
374
375
def get_hydrated_version(self) -> "PipelineSnapshotResponse":
    """Return the hydrated version of this pipeline snapshot.

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

    return Client().zen_store.get_snapshot(self.id)
PipelineSnapshotResponseBody

Bases: ProjectScopedResponseBody

Response body for pipeline snapshots.

PipelineSnapshotResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for pipeline snapshots.

PipelineSnapshotResponseResources

Bases: ProjectScopedResponseResources

Run snapshot resources.

PipelineSnapshotRunRequest

Bases: BaseZenModel

Request model for running a pipeline snapshot.

PipelineSnapshotUpdate

Bases: BaseUpdate

Pipeline snapshot update model.

PipelineUpdate

Bases: BaseUpdate

Update model for pipelines.

ProjectFilter

Bases: BaseFilter

Model to enable advanced filtering of all projects.

ProjectRequest

Bases: BaseRequest

Request model for projects.

ProjectResponse

Bases: BaseIdentifiedResponse[ProjectResponseBody, ProjectResponseMetadata, ProjectResponseResources]

Response model for projects.

Attributes
description: str property

The description property.

Returns:

Type Description
str

the value of the property.

display_name: str property

The display_name property.

Returns:

Type Description
str

the value of the property.

Functions
get_hydrated_version() -> ProjectResponse

Get the hydrated version of this project.

Returns:

Type Description
ProjectResponse

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

Source code in src/zenml/models/v2/core/project.py
158
159
160
161
162
163
164
165
166
def get_hydrated_version(self) -> "ProjectResponse":
    """Get the hydrated version of this project.

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

    return Client().zen_store.get_project(self.id)
ProjectResponseBody

Bases: BaseDatedResponseBody

Response body for projects.

ProjectResponseMetadata

Bases: BaseResponseMetadata

Response metadata for projects.

ProjectScopedFilter

Bases: UserScopedFilter

Model to enable advanced scoping with project.

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.

Raises:

Type Description
ValueError

If the project scope is missing from the filter.

Source code in src/zenml/models/v2/base/scoped.py
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
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.

    Raises:
        ValueError: If the project scope is missing from the filter.
    """
    query = super().apply_filter(query=query, table=table)

    # The project scope must always be set and must be a UUID. If the
    # client sets this to a string, the server will try to resolve it to a
    # project ID.
    #
    # If not set by the client, the server will fall back to using the
    # user's default project or even the server's default project, if
    # they are configured. If this also fails to yield a project, this
    # method will raise a ValueError.
    #
    # See: SqlZenStore._set_filter_project_id

    if not self.project:
        raise ValueError("Project scope missing from the filter.")

    if not isinstance(self.project, UUID):
        raise ValueError(
            f"Project scope must be a UUID, got {type(self.project)}."
        )

    scope_filter = getattr(table, "project_id") == self.project
    query = query.where(scope_filter)

    return query
ProjectScopedRequest

Bases: UserScopedRequest

Base project-scoped request domain model.

Used as a base class for all domain models that are project-scoped.

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

Fetches the analytics metadata for project scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
91
92
93
94
95
96
97
98
99
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for project scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["project_id"] = self.project
    return metadata
ProjectScopedResponse

Bases: UserScopedResponse[ProjectBody, ProjectMetadata, ProjectResources], Generic[ProjectBody, ProjectMetadata, ProjectResources]

Base project-scoped domain model.

Used as a base class for all domain models that are project-scoped.

Attributes
project: ProjectResponse property

The project property.

Returns:

Type Description
ProjectResponse

the value of the property.

project_id: UUID property

The project ID property.

Returns:

Type Description
UUID

the value of the property.

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

Fetches the analytics metadata for project scoped models.

Returns:

Type Description
Dict[str, Any]

The analytics metadata.

Source code in src/zenml/models/v2/base/scoped.py
333
334
335
336
337
338
339
340
341
def get_analytics_metadata(self) -> Dict[str, Any]:
    """Fetches the analytics metadata for project scoped models.

    Returns:
        The analytics metadata.
    """
    metadata = super().get_analytics_metadata()
    metadata["project_id"] = self.project_id
    return metadata
ProjectScopedResponseBody

Bases: UserScopedResponseBody

Base project-scoped body.

ProjectScopedResponseMetadata

Bases: UserScopedResponseMetadata

Base project-scoped metadata.

ProjectScopedResponseResources

Bases: UserScopedResponseResources

Base project-scoped resources.

ProjectStatistics

Bases: BaseZenModel

Project statistics.

ProjectUpdate

Bases: BaseUpdate

Update model for projects.

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.

RunMetadataFilterMixin

Bases: BaseFilter

Model to enable filtering and sorting by run metadata.

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

Get custom run metadata 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
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
704
705
706
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
def get_custom_filters(
    self, table: Type["AnySchema"]
) -> List["ColumnElement[bool]"]:
    """Get custom run metadata filters.

    Args:
        table: The query table.

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

    if self.run_metadata is not None:
        from sqlmodel import exists, select

        from zenml.enums import MetadataResourceTypes
        from zenml.zen_stores.schemas import (
            ArtifactVersionSchema,
            ModelVersionSchema,
            PipelineRunSchema,
            RunMetadataResourceSchema,
            RunMetadataSchema,
            ScheduleSchema,
            StepRunSchema,
        )

        resource_type_mapping = {
            ArtifactVersionSchema: MetadataResourceTypes.ARTIFACT_VERSION,
            ModelVersionSchema: MetadataResourceTypes.MODEL_VERSION,
            PipelineRunSchema: MetadataResourceTypes.PIPELINE_RUN,
            StepRunSchema: MetadataResourceTypes.STEP_RUN,
            ScheduleSchema: MetadataResourceTypes.SCHEDULE,
        }

        # Create an EXISTS subquery for each run_metadata filter
        for entry in self.run_metadata:
            # Split at the first colon to get the key
            key, value = entry.split(":", 1)

            # Create an exists subquery
            exists_subquery = exists(
                select(RunMetadataResourceSchema.id)
                .join(
                    RunMetadataSchema,
                    RunMetadataSchema.id  # type: ignore[arg-type]
                    == RunMetadataResourceSchema.run_metadata_id,
                )
                .where(
                    RunMetadataResourceSchema.resource_id == table.id,
                    RunMetadataResourceSchema.resource_type
                    == resource_type_mapping[table].value,
                    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",
                    ),
                )
            )
            custom_filters.append(exists_subquery)

    return custom_filters
validate_run_metadata_format() -> RunMetadataFilterMixin

Validates that run_metadata entries are in the correct format.

Each run_metadata entry must be in one of the following formats: 1. "key:value" - Direct equality comparison (key equals value) 2. "key:filterop:value" - Where filterop is one of the GenericFilterOps: - equals: Exact match - notequals: Not equal to - contains: String contains value - startswith: String starts with value - endswith: String ends with value - oneof: Value is one of the specified options - gte: Greater than or equal to - gt: Greater than - lte: Less than or equal to - lt: Less than - in: Value is in a list

Examples: - "status:completed" - Find entries where status equals "completed" - "name:contains:test" - Find entries where name contains "test" - "duration:gt:10" - Find entries where duration is greater than 10

Returns:

Type Description
RunMetadataFilterMixin

self

Raises:

Type Description
ValueError

If any entry in run_metadata does not contain a colon.

Source code in src/zenml/models/v2/base/scoped.py
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
@model_validator(mode="after")
def validate_run_metadata_format(self) -> "RunMetadataFilterMixin":
    """Validates that run_metadata entries are in the correct format.

    Each run_metadata entry must be in one of the following formats:
    1. "key:value" - Direct equality comparison (key equals value)
    2. "key:filterop:value" - Where filterop is one of the GenericFilterOps:
       - equals: Exact match
       - notequals: Not equal to
       - contains: String contains value
       - startswith: String starts with value
       - endswith: String ends with value
       - oneof: Value is one of the specified options
       - gte: Greater than or equal to
       - gt: Greater than
       - lte: Less than or equal to
       - lt: Less than
       - in: Value is in a list

    Examples:
    - "status:completed" - Find entries where status equals "completed"
    - "name:contains:test" - Find entries where name contains "test"
    - "duration:gt:10" - Find entries where duration is greater than 10

    Returns:
        self

    Raises:
        ValueError: If any entry in run_metadata does not contain a colon.
    """
    if self.run_metadata:
        for entry in self.run_metadata:
            if ":" not in entry:
                raise ValueError(
                    f"Invalid run_metadata entry format: '{entry}'. "
                    "Entry must be in format 'key:value' for direct "
                    "equality comparison or 'key:filterop:value' where "
                    "filterop is one of: equals, notequals, "
                    f"contains, startswith, endswith, oneof, gte, gt, "
                    f"lte, lt, in."
                )
    return self
RunMetadataRequest

Bases: ProjectScopedRequest

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: ProjectScopedFilter, 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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
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

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

    if self.hidden is not None:
        custom_filters.append(
            col(RunTemplateSchema.hidden).is_(self.hidden)
        )

    if self.code_repository_id:
        code_repo_filter = and_(
            RunTemplateSchema.source_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.stack_id == self.stack_id,
        )
        custom_filters.append(stack_filter)

    if self.build_id:
        build_filter = and_(
            RunTemplateSchema.source_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.build_id == self.build_id,
        )
        custom_filters.append(build_filter)

    if self.pipeline_id:
        pipeline_filter = and_(
            RunTemplateSchema.source_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.pipeline_id == self.pipeline_id,
        )
        custom_filters.append(pipeline_filter)

    if self.pipeline:
        pipeline_filter = and_(
            RunTemplateSchema.source_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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_snapshot_id
            == PipelineSnapshotSchema.id,
            PipelineSnapshotSchema.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: ProjectScopedRequest

Request model for run templates.

RunTemplateResponse

Bases: ProjectScopedResponse[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.

hidden: bool property

The hidden property.

Returns:

Type Description
bool

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_snapshot: Optional[PipelineSnapshotResponse] property

The source_snapshot property.

Returns:

Type Description
Optional[PipelineSnapshotResponse]

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
198
199
200
201
202
203
204
205
206
207
208
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: ProjectScopedResponseBody

Response body for run templates.

RunTemplateResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for run templates.

RunTemplateResponseResources

Bases: ProjectScopedResponseResources

All resource models associated with the run template.

RunTemplateUpdate

Bases: BaseUpdate

Run template update model.

ScheduleFilter

Bases: ProjectScopedFilter

Model to enable advanced filtering of all Users.

ScheduleRequest

Bases: ProjectScopedRequest

Request model for schedules.

ScheduleResponse

Bases: ProjectScopedResponse[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.

is_archived: bool property

The is_archived property.

Returns:

Type Description
bool

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
180
181
182
183
184
185
186
187
188
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: ProjectScopedResponseBody

Response body for schedules.

ScheduleResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for schedules.

ScheduleResponseResources

Bases: ProjectScopedResponseResources

Class for all resource models associated with the schedule entity.

ScheduleUpdate

Bases: BaseUpdate

Update model for schedules.

SecretFilter

Bases: UserScopedFilter

Model to enable advanced secret filtering.

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/secret.py
275
276
277
278
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
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.
    """
    # The secret user scoping works a bit differently than the other
    # scoped filters. We have to filter out all private secrets that are
    # not owned by the current user.
    if not self.scope_user:
        return super().apply_filter(query=query, table=table)

    scope_user = self.scope_user

    # First we apply the inherited filters without the user scoping
    # applied.
    self.scope_user = None
    query = super().apply_filter(query=query, table=table)
    self.scope_user = scope_user

    # Then we apply the user scoping filter.
    if self.scope_user:
        from sqlmodel import and_, or_

        query = query.where(
            or_(
                and_(
                    getattr(table, "user_id") == self.scope_user,
                    getattr(table, "private") == True,  # noqa: E712
                ),
                getattr(table, "private") == False,  # noqa: E712
            )
        )

    else:
        query = query.where(getattr(table, "private") == False)  # noqa: E712

    return query
SecretRequest

Bases: UserScopedRequest

Request model 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: UserScopedResponse[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.

private: bool property

The private property.

Returns:

Type Description
bool

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
225
226
227
228
229
230
231
232
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 secret.

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
164
165
166
167
168
169
170
171
172
def get_hydrated_version(self) -> "SecretResponse":
    """Get the hydrated version of this secret.

    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
234
235
236
237
238
239
240
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
242
243
244
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
246
247
248
249
250
251
252
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: UserScopedResponseBody

Response body for secrets.

SecretResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for secrets.

SecretResponseResources

Bases: UserScopedResponseResources

Response resources for secrets.

SecretUpdate

Bases: BaseUpdate

Update model for secrets.

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
109
110
111
112
113
114
115
116
117
118
119
120
121
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: BaseUpdate

Model for updating server settings.

ServerStatistics

Bases: BaseZenModel

Server statistics.

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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
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
ServiceAccountInternalRequest

Bases: ServiceAccountRequest

Internal request model for service accounts.

ServiceAccountInternalUpdate

Bases: ServiceAccountUpdate

Internal update model for service accounts.

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.

avatar_url: Optional[str] property

The avatar_url property.

Returns:

Type Description
Optional[str]

the value of the property.

description: str property

The description property.

Returns:

Type Description
str

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.

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
178
179
180
181
182
183
184
185
186
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
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
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,
            avatar_url=self.avatar_url,
            full_name=self.full_name,
        ),
        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.

ServiceConnectorConfiguration

Bases: Dict[str, Any]

Model for service connector configuration.

Attributes
non_secrets: Dict[str, Any] property

Get the non-secrets from the configuration.

Returns:

Type Description
Dict[str, Any]

A dictionary of non-secrets.

plain: Dict[str, Any] property

Get the configuration with secrets unpacked.

Returns:

Type Description
Dict[str, Any]

A dictionary of configuration with secrets unpacked.

plain_secrets: Dict[str, str] property

Get the plain secrets from the configuration.

Returns:

Type Description
Dict[str, str]

A dictionary of secrets.

secrets: Dict[str, PlainSerializedSecretStr] property

Get the secrets from the configuration.

Returns:

Type Description
Dict[str, PlainSerializedSecretStr]

A dictionary of secrets.

Functions
add_secrets(secrets: Dict[str, str]) -> None

Add the secrets to the configuration.

Parameters:

Name Type Description Default
secrets Dict[str, str]

The secrets to add to the configuration.

required
Source code in src/zenml/models/v2/core/service_connector.py
125
126
127
128
129
130
131
def add_secrets(self, secrets: Dict[str, str]) -> None:
    """Add the secrets to the configuration.

    Args:
        secrets: The secrets to add to the configuration.
    """
    self.update({k: SecretStr(v) for k, v in secrets.items()})
from_dict(data: Dict[str, Any]) -> ServiceConnectorConfiguration classmethod

Create a configuration model from a dictionary.

Parameters:

Name Type Description Default
data Dict[str, Any]

The dictionary to create the configuration model from.

required

Returns:

Type Description
ServiceConnectorConfiguration

A configuration model.

Source code in src/zenml/models/v2/core/service_connector.py
53
54
55
56
57
58
59
60
61
62
63
64
65
@classmethod
def from_dict(
    cls, data: Dict[str, Any]
) -> "ServiceConnectorConfiguration":
    """Create a configuration model from a dictionary.

    Args:
        data: The dictionary to create the configuration model from.

    Returns:
        A configuration model.
    """
    return cls(**data)
get_plain(key: str, default: Any = None) -> Any

Get the plain value for the given key.

Parameters:

Name Type Description Default
key str

The key to get the value for.

required
default Any

The default value to return if the key is not found.

None

Returns:

Type Description
Any

The plain value for the given key.

Source code in src/zenml/models/v2/core/service_connector.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
def get_plain(self, key: str, default: Any = None) -> Any:
    """Get the plain value for the given key.

    Args:
        key: The key to get the value for.
        default: The default value to return if the key is not found.

    Returns:
        The plain value for the given key.
    """
    result = self.get(key, default)
    if isinstance(result, SecretStr):
        return result.get_secret_value()
    return result
ServiceConnectorFilter

Bases: UserScopedFilter

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
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
@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: UserScopedRequest

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
236
237
238
239
240
241
242
243
244
245
246
247
248
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) -> 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
Source code in src/zenml/models/v2/core/service_connector.py
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
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,
) -> 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.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
    )
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: UserScopedResponse[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: ServiceConnectorConfiguration property

The configuration property.

Returns:

Type Description
ServiceConnectorConfiguration

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.

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.

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
add_secrets(secrets: Dict[str, str]) -> None

Add the secrets to the configuration.

Parameters:

Name Type Description Default
secrets Dict[str, str]

The secrets to add to the configuration.

required
Source code in src/zenml/models/v2/core/service_connector.py
839
840
841
842
843
844
845
def add_secrets(self, secrets: Dict[str, str]) -> None:
    """Add the secrets to the configuration.

    Args:
        secrets: The secrets to add to the configuration.
    """
    self.get_metadata().configuration.add_secrets(secrets)
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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
611
612
613
614
615
616
617
618
619
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)
remove_secrets() -> None

Remove the secrets from the configuration.

Source code in src/zenml/models/v2/core/service_connector.py
832
833
834
835
836
837
def remove_secrets(self) -> None:
    """Remove the secrets from the configuration."""
    metadata = self.get_metadata()
    metadata.configuration = ServiceConnectorConfiguration(
        **metadata.configuration.non_secrets
    )
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
703
704
705
706
707
708
709
710
711
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) -> 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
Source code in src/zenml/models/v2/core/service_connector.py
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
748
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,
) -> 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.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
    )
validate_configuration() -> None

Validate the configuration of the connector.

Source code in src/zenml/models/v2/core/service_connector.py
713
714
715
716
717
718
719
720
721
def validate_configuration(self) -> None:
    """Validate the configuration of the connector."""
    if isinstance(self.connector_type, ServiceConnectorTypeModel):
        self.validate_and_configure_resources(
            connector_type=self.connector_type,
            resource_types=self.resource_types,
            resource_id=self.resource_id,
            configuration=self.configuration,
        )
ServiceConnectorResponseBody

Bases: UserScopedResponseBody

Response body for service connectors.

ServiceConnectorResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for service connectors.

ServiceConnectorResponseResources

Bases: UserScopedResponseResources

Class for all resource models associated with the service connector entity.

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 field represents a full valid configuration update, not just a partial update. If it is set (i.e. not None) in the update, its values will replace the existing configuration values.
  • 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
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) -> 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
Source code in src/zenml/models/v2/core/service_connector.py
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
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,
) -> 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.
    """
    _validate_and_configure_resources(
        connector=self,
        connector_type=connector_type,
        resource_types=resource_types,
        resource_id=resource_id,
        configuration=configuration,
    )
ServiceFilter

Bases: ProjectScopedFilter

Model to enable advanced filtering of services.

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
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
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
468
469
470
471
472
473
474
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
460
461
462
463
464
465
466
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: ProjectScopedRequest

Request model for services.

ServiceResponse

Bases: ProjectScopedResponse[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.

model_version: Optional[ModelVersionResponse] property

The model_version property.

Returns:

Type Description
Optional[ModelVersionResponse]

the value of the property.

pipeline_run: Optional[PipelineRunResponse] property

The pipeline_run property.

Returns:

Type Description
Optional[PipelineRunResponse]

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
266
267
268
269
270
271
272
273
274
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: ProjectScopedResponseBody

Response body for services.

ServiceResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for services.

ServiceResponseResources

Bases: ProjectScopedResponseResources

Class for all resource models associated with the service entity.

ServiceType

Bases: BaseModel

Service type descriptor.

Attributes:

Name Type Description
type str

service type

flavor str

service flavor

name str

name of the service type

description str

description of the service type

logo_url str

logo of the service type

ServiceUpdate

Bases: BaseUpdate

Update model for stack components.

StackDeploymentConfig

Bases: BaseModel

Configuration about a stack deployment.

StackDeploymentInfo

Bases: BaseModel

Information about a stack deployment.

StackFilter

Bases: UserScopedFilter

Model to enable advanced stack filtering.

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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
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
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 (
        StackComponentSchema,
        StackCompositionSchema,
        StackSchema,
    )

    custom_filters = super().get_custom_filters(table)

    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: UserScopedRequest

Request model for stack creation.

StackResponse

Bases: UserScopedResponse[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.

environment: Dict[str, str] property

The environment property.

Returns:

Type Description
Dict[str, 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.

secrets: List[UUID] property

The secrets property.

Returns:

Type Description
List[UUID]

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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
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
288
289
290
291
292
293
294
295
296
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
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 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: UserScopedResponseBody

Response body for stacks.

StackResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for stacks.

StackResponseResources

Bases: UserScopedResponseResources

Response resources for stacks.

StackUpdate

Bases: BaseUpdate

Update model for stacks.

StepHeartbeatResponse

Bases: BaseModel

Light-weight model for Step Heartbeat responses.

StepRunFilter

Bases: ProjectScopedFilter, RunMetadataFilterMixin

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
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
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 (
        ModelSchema,
        ModelVersionSchema,
        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.exclude_retried:
        custom_filters.append(
            col(StepRunSchema.status) != ExecutionStatus.RETRIED.value
        )

    if self.cache_expired is True:
        cache_expiration_filter = and_(
            col(StepRunSchema.cache_expires_at).is_not(None),
            col(StepRunSchema.cache_expires_at) < utc_now(),
        )
        custom_filters.append(cache_expiration_filter)
    elif self.cache_expired is False:
        cache_expiration_filter = or_(
            col(StepRunSchema.cache_expires_at) > utc_now(),
            col(StepRunSchema.cache_expires_at).is_(None),
        )
        custom_filters.append(cache_expiration_filter)

    return custom_filters
StepRunIdentifier

Bases: BaseModel

Class grouping different step run identifiers.

StepRunRequest

Bases: ProjectScopedRequest

Request model for step runs.

StepRunResponse

Bases: ProjectScopedResponse[StepRunResponseBody, StepRunResponseMetadata, StepRunResponseResources]

Response model for step runs.

Attributes
cache_expires_at: Optional[datetime] property

The cache_expires_at property.

Returns:

Type Description
Optional[datetime]

the value of the property.

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.

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.

heartbeat_threshold: Optional[int] property

The heartbeat_threshold property.

Returns:

Type Description
Optional[int]

the value of the property.

input: StepRunInputResponse property

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

Returns:

Type Description
StepRunInputResponse

The input artifact.

Raises:

Type Description
ValueError

If there were zero or multiple inputs to this step.

inputs: Dict[str, List[StepRunInputResponse]] property

The inputs property.

Returns:

Type Description
Dict[str, List[StepRunInputResponse]]

the value of the property.

is_retriable: bool property

The is_retriable property.

Returns:

Type Description
bool

the value of the property.

latest_heartbeat: Optional[datetime] property

The latest_heartbeat property.

Returns:

Type Description
Optional[datetime]

the value of the property.

log_collection: Optional[List[LogsResponse]] property

The log_collection property.

Returns:

Type Description
Optional[List[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.

regular_inputs: Dict[str, List[StepRunInputResponse]] property

Returns the regular step inputs of the step run.

Regular step inputs are the inputs that are defined in the step function signature, and are not manually loaded during the step execution.

Returns:

Type Description
Dict[str, List[StepRunInputResponse]]

The regular step inputs.

regular_outputs: Dict[str, ArtifactVersionResponse] property

Returns the regular step outputs of the step run.

Regular step outputs are the outputs that are defined in the step function signature, and are not manually saved during the step execution.

Raises:

Type Description
ValueError

If there were multiple regular output artifacts for the same output name.

Returns:

Type Description
Dict[str, ArtifactVersionResponse]

The regular step outputs.

run_metadata: Dict[str, MetadataType] property

The run_metadata property.

Returns:

Type Description
Dict[str, MetadataType]

the value of the property.

snapshot_id: UUID property

The snapshot_id property.

Returns:

Type Description
UUID

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.

substitutions: Dict[str, str] property

The substitutions property.

Returns:

Type Description
Dict[str, str]

the value of the property.

version: int property

The version property.

Returns:

Type Description
int

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
356
357
358
359
360
361
362
363
364
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: ProjectScopedResponseBody

Response body for step runs.

StepRunResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for step runs.

StepRunResponseResources

Bases: ProjectScopedResponseResources

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

StepRunUpdate

Bases: BaseUpdate

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
@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.

Source code in src/zenml/models/v2/base/filter.py
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
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.
    """
    # Handle numeric comparisons (GT, LT, GTE, LTE)
    if self.operation in {
        GenericFilterOps.GT,
        GenericFilterOps.LT,
        GenericFilterOps.GTE,
        GenericFilterOps.LTE,
    }:
        return self._handle_numeric_comparison(column)

    # Handle operations that need special treatment for JSON-encoded columns
    is_json_encoded = self._check_if_column_is_json_encoded(column)

    # Handle list operations
    if self.operation == GenericFilterOps.ONEOF:
        assert isinstance(self.value, list)
        return self._handle_oneof(column, is_json_encoded)

    # Handle pattern matching operations
    if self.operation == GenericFilterOps.CONTAINS:
        return column.like(f"%{self.value}%")

    if self.operation == GenericFilterOps.STARTSWITH:
        return self._handle_startswith(column, is_json_encoded)

    if self.operation == GenericFilterOps.ENDSWITH:
        return self._handle_endswith(column, is_json_encoded)

    if self.operation == GenericFilterOps.NOT_EQUALS:
        return self._handle_not_equals(column, is_json_encoded)

    # Default case (EQUALS)
    return self._handle_equals(column, is_json_encoded)
Tag

Bases: BaseModel

A model representing a tag.

Functions
to_request() -> TagRequest

Convert the tag to a TagRequest.

Returns:

Type Description
TagRequest

The tag as a TagRequest.

Source code in src/zenml/utils/tag_utils.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def to_request(self) -> "TagRequest":
    """Convert the tag to a TagRequest.

    Returns:
        The tag as a TagRequest.
    """
    from zenml.models import TagRequest

    request = TagRequest(name=self.name)
    if self.color is not None:
        request.color = self.color

    if self.exclusive is not None:
        request.exclusive = self.exclusive
    return request
TagFilter

Bases: UserScopedFilter

Model to enable advanced filtering of all tags.

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/tag.py
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
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 exists, select

    from zenml.zen_stores.schemas import (
        TagResourceSchema,
        TagSchema,
    )

    if self.resource_type:
        # Filter for tags that have at least one association with the specified resource type
        resource_type_filter = exists(
            select(TagResourceSchema).where(
                TagResourceSchema.tag_id == TagSchema.id,
                TagResourceSchema.resource_type
                == self.resource_type.value,
            )
        )
        custom_filters.append(resource_type_filter)

    return custom_filters
TagRequest

Bases: UserScopedRequest

Request model for tags.

Functions
validate_name_not_uuid(value: str) -> str classmethod

Validates that the tag name is not a UUID.

Parameters:

Name Type Description Default
value str

The tag name to validate.

required

Returns:

Type Description
str

The validated tag name.

Raises:

Type Description
ValueError

If the tag name can be converted to a UUID.

Source code in src/zenml/models/v2/core/tag.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@field_validator("name")
@classmethod
def validate_name_not_uuid(cls, value: str) -> str:
    """Validates that the tag name is not a UUID.

    Args:
        value: The tag name to validate.

    Returns:
        The validated tag name.

    Raises:
        ValueError: If the tag name can be converted
            to a UUID.
    """
    if is_valid_uuid(value):
        raise ValueError(
            "Tag names cannot be UUIDs or strings that "
            "can be converted to UUIDs."
        )
    return value
TagResource

Bases: BaseModel

Utility class to help identify resources to tag.

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: UserScopedResponse[TagResponseBody, TagResponseMetadata, TagResponseResources]

Response model for tags.

Attributes
color: ColorVariants property

The color property.

Returns:

Type Description
ColorVariants

the value of the property.

exclusive: bool property

The exclusive property.

Returns:

Type Description
bool

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
154
155
156
157
158
159
160
161
162
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: UserScopedResponseBody

Response body for tags.

TagResponseMetadata

Bases: UserScopedResponseMetadata

Response metadata for tags.

TagResponseResources

Bases: UserScopedResponseResources

Class for all resource models associated with the tag entity.

TagUpdate

Bases: BaseUpdate

Update model for tags.

Functions
validate_name_not_uuid(value: Optional[str]) -> Optional[str] classmethod

Validates that the tag name is not a UUID.

Parameters:

Name Type Description Default
value Optional[str]

The tag name to validate.

required

Returns:

Type Description
Optional[str]

The validated tag name.

Raises:

Type Description
ValueError

If the tag name can be converted to a UUID.

Source code in src/zenml/models/v2/core/tag.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
@field_validator("name")
@classmethod
def validate_name_not_uuid(cls, value: Optional[str]) -> Optional[str]:
    """Validates that the tag name is not a UUID.

    Args:
        value: The tag name to validate.

    Returns:
        The validated tag name.

    Raises:
        ValueError: If the tag name can be converted to a UUID.
    """
    if value is not None and is_valid_uuid(value):
        raise ValueError(
            "Tag names cannot be UUIDs or strings that "
            "can be converted to UUIDs."
        )
    return value
TaggableFilter

Bases: BaseFilter

Model to enable filtering and sorting by tags.

Functions
add_tag_to_tags() -> TaggableFilter

Deprecated the tag attribute in favor of the tags attribute.

Returns:

Type Description
TaggableFilter

self

Source code in src/zenml/models/v2/base/scoped.py
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
@model_validator(mode="after")
def add_tag_to_tags(self) -> "TaggableFilter":
    """Deprecated the tag attribute in favor of the tags attribute.

    Returns:
        self
    """
    if self.tag is not None:
        logger.warning(
            "The `tag` attribute is deprecated in favor of the `tags` attribute. "
            "Please update your code to use the `tags` attribute instead."
        )
        if self.tags is not None:
            self.tags.append(self.tag)
        else:
            self.tags = [self.tag]

        self.tag = None

    return self
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
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 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.tags:
        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
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
607
608
609
610
611
612
613
614
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,
            DeploymentSchema,
            ModelSchema,
            ModelVersionSchema,
            PipelineRunSchema,
            PipelineSchema,
            PipelineSnapshotSchema,
            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,
            PipelineSnapshotSchema: TaggableResourceTypes.PIPELINE_SNAPSHOT,
            DeploymentSchema: TaggableResourceTypes.DEPLOYMENT,
        }

        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
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
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.
    """
    custom_filters = super().get_custom_filters(table)

    if self.tags:
        from sqlmodel import exists, select

        from zenml.zen_stores.schemas import TagResourceSchema, TagSchema

        for tag in self.tags:
            condition = self.generate_custom_query_conditions_for_column(
                value=tag, table=TagSchema, column="name"
            )
            exists_subquery = exists(
                select(TagResourceSchema)
                .join(TagSchema, TagSchema.id == TagResourceSchema.tag_id)  # type: ignore[arg-type]
                .where(
                    TagResourceSchema.resource_id == table.id, condition
                )
            )
            custom_filters.append(exists_subquery)

    return custom_filters
TriggerExecutionFilter

Bases: ProjectScopedFilter

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: ProjectScopedFilter

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: ProjectScopedRequest

Model for creating a new trigger.

TriggerResponse

Bases: ProjectScopedResponse[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: ProjectScopedResponseBody

Response body for triggers.

TriggerResponseMetadata

Bases: ProjectScopedResponseMetadata

Response metadata for triggers.

TriggerResponseResources

Bases: ProjectScopedResponseResources

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
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
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
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.

avatar_url: Optional[str] property

The avatar_url property.

Returns:

Type Description
Optional[str]

the value of the property.

default_project_id: Optional[UUID] property

The default_project_id property.

Returns:

Type Description
Optional[UUID]

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
346
347
348
349
350
351
352
353
354
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
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
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
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
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
197
198
199
200
201
202
203
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
72
73
74
75
76
77
78
79
80
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.

user_id: Optional[UUID] property

The user ID property.

Returns:

Type Description
Optional[UUID]

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
139
140
141
142
143
144
145
146
147
148
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 user_id := self.user_id:
        metadata["user_id"] = user_id
    return metadata
UserScopedResponseBody

Bases: BaseDatedResponseBody

Base user-owned body.

UserScopedResponseMetadata

Bases: BaseResponseMetadata

Base user-owned metadata.

UserUpdate

Bases: UserBase, BaseUpdate

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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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
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
@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
Functions
add_tags(tags: Union[str, Tag, List[Union[str, Tag]]], pipeline: Optional[Union[UUID, str]] = None, run: Optional[Union[UUID, str]] = None, run_template: Optional[Union[UUID, str]] = None, snapshot: Optional[Union[UUID, str]] = None, deployment: Optional[Union[UUID, str]] = None, artifact: Optional[Union[UUID, str]] = None, artifact_version_id: Optional[UUID] = None, artifact_name: Optional[str] = None, artifact_version: Optional[str] = None, infer_artifact: Optional[bool] = None) -> None
add_tags(
    tags: Union[str, Tag, List[Union[str, Tag]]],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    run: Union[UUID, str],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    artifact: Union[UUID, str],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    artifact_version_id: UUID,
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    artifact_name: str,
    artifact_version: str,
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    infer_artifact: bool = False,
    artifact_name: Optional[str] = None,
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    pipeline: Union[UUID, str],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    run_template: Union[UUID, str],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    snapshot: Union[UUID, str],
) -> None
add_tags(
    *,
    tags: Union[str, Tag, List[Union[str, Tag]]],
    deployment: Union[UUID, str],
) -> None

Add tags to various resource types in a generalized way.

Parameters:

Name Type Description Default
tags Union[str, Tag, List[Union[str, Tag]]]

The tags to add.

required
pipeline Optional[Union[UUID, str]]

The ID or the name of the pipeline.

None
run Optional[Union[UUID, str]]

The id, name or prefix of the run.

None
run_template Optional[Union[UUID, str]]

The ID or the name of the run template.

None
snapshot Optional[Union[UUID, str]]

The ID of the snapshot.

None
deployment Optional[Union[UUID, str]]

The ID or the name of the deployment.

None
artifact Optional[Union[UUID, str]]

The ID or the name of the artifact.

None
artifact_version_id Optional[UUID]

The ID of the artifact version.

None
artifact_name Optional[str]

The name of the artifact.

None
artifact_version Optional[str]

The version of the artifact.

None
infer_artifact Optional[bool]

Flag deciding whether the artifact version should be inferred from the step context.

None

Raises:

Type Description
ValueError

If no identifiers are provided and the function is not called from within a step, or if exclusive is provided for a resource type that doesn't support it.

Source code in src/zenml/utils/tag_utils.py
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
276
277
278
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
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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
def add_tags(
    tags: Union[str, Tag, List[Union[str, Tag]]],
    # Pipelines
    pipeline: Optional[Union[UUID, str]] = None,
    # Runs
    run: Optional[Union[UUID, str]] = None,
    # Run Templates
    run_template: Optional[Union[UUID, str]] = None,
    # Snapshots
    snapshot: Optional[Union[UUID, str]] = None,
    # Deployments
    deployment: Optional[Union[UUID, str]] = None,
    # Artifacts
    artifact: Optional[Union[UUID, str]] = None,
    # Artifact Versions
    artifact_version_id: Optional[UUID] = None,
    artifact_name: Optional[str] = None,
    artifact_version: Optional[str] = None,
    infer_artifact: Optional[bool] = None,
) -> None:
    """Add tags to various resource types in a generalized way.

    Args:
        tags: The tags to add.
        pipeline: The ID or the name of the pipeline.
        run: The id, name or prefix of the run.
        run_template: The ID or the name of the run template.
        snapshot: The ID of the snapshot.
        deployment: The ID or the name of the deployment.
        artifact: The ID or the name of the artifact.
        artifact_version_id: The ID of the artifact version.
        artifact_name: The name of the artifact.
        artifact_version: The version of the artifact.
        infer_artifact: Flag deciding whether the artifact version should be
            inferred from the step context.

    Raises:
        ValueError: If no identifiers are provided and the function is not
            called from within a step, or if exclusive is provided for a
            resource type that doesn't support it.
    """
    from zenml.client import Client
    from zenml.models.v2.misc.tag import TagResource

    client = Client()
    resource_id = None
    resource_type = None

    if isinstance(tags, (str, Tag)):
        tags = [tags]

    # Tag a pipeline
    if pipeline is not None and all(
        v is None
        for v in [
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        pipeline_model = client.get_pipeline(name_id_or_prefix=pipeline)
        resource_id = pipeline_model.id
        resource_type = TaggableResourceTypes.PIPELINE

    # Tag a run by ID
    elif run is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        run_model = client.get_pipeline_run(name_id_or_prefix=run)
        resource_id = run_model.id
        resource_type = TaggableResourceTypes.PIPELINE_RUN

    # Tag a run template
    elif run_template is not None and all(
        v is None
        for v in [
            pipeline,
            run,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        run_template_model = client.get_run_template(
            name_id_or_prefix=run_template
        )
        resource_id = run_template_model.id
        resource_type = TaggableResourceTypes.RUN_TEMPLATE

    # Tag a snapshot
    elif snapshot is not None and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        snapshot_model = client.get_snapshot(
            name_id_or_prefix=snapshot, allow_prefix_match=False
        )
        resource_id = snapshot_model.id
        resource_type = TaggableResourceTypes.PIPELINE_SNAPSHOT

    # Tag a deployment
    elif deployment is not None and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        deployment_model = client.get_deployment(name_id_or_prefix=deployment)
        resource_id = deployment_model.id
        resource_type = TaggableResourceTypes.DEPLOYMENT

    # Tag an artifact
    elif artifact is not None and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        artifact_model = client.get_artifact(name_id_or_prefix=artifact)
        resource_id = artifact_model.id
        resource_type = TaggableResourceTypes.ARTIFACT

    # Tag an artifact version by its ID
    elif artifact_version_id is not None and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        resource_id = artifact_version_id
        resource_type = TaggableResourceTypes.ARTIFACT_VERSION

    # Tag an artifact version by its name and version
    elif (artifact_name is not None and artifact_version is not None) and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            infer_artifact,
        ]
    ):
        artifact_version_model = client.get_artifact_version(
            name_id_or_prefix=artifact_name, version=artifact_version
        )
        resource_id = artifact_version_model.id
        resource_type = TaggableResourceTypes.ARTIFACT_VERSION

    # Tag an artifact version through the step context
    elif infer_artifact is True and all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_version,
        ]
    ):
        resource_type = TaggableResourceTypes.ARTIFACT_VERSION

        try:
            from zenml.steps.step_context import get_step_context

            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                "When you are using the `infer_artifact` option when you call "
                "`add_tags`, it must be called inside a step with outputs."
                "Otherwise, you can provide a `artifact_version_id` or a "
                "combination of `artifact_name` and `artifact_version`."
            )

        step_output_names = list(step_context._outputs.keys())

        if artifact_name is not None:
            # If a name provided, ensure it is in the outputs
            if artifact_name not in step_output_names:
                raise ValueError(
                    f"The provided artifact name`{artifact_name}` does not "
                    f"exist in the step outputs: {step_output_names}."
                )
        else:
            # If no name provided, ensure there is only one output
            if len(step_output_names) > 1:
                raise ValueError(
                    "There is more than one output. If you would like to use "
                    "the `infer_artifact` option, you need to define an "
                    "`artifact_name`."
                )

            if len(step_output_names) == 0:
                raise ValueError("The step does not have any outputs.")

            artifact_name = step_output_names[0]

        step_context.add_output_tags(
            tags=[t.name if isinstance(t, Tag) else t for t in tags],
            output_name=artifact_name,
        )

    # If every additional value is None, that means we are calling it bare bones
    # and this call needs to happen during a step execution. We will use the
    # step context to fetch the run and attach the tags accordingly.
    elif all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        try:
            from zenml.steps.step_context import get_step_context

            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                f"""
                You are calling 'add_tags()' outside of a step execution. 
                If you would like to add tags to a ZenML entity outside 
                of the step execution, please provide the required 
                identifiers.\n{add_tags_warning}
                """
            )

        # Tag the pipeline run, not the step
        resource_id = step_context.pipeline_run.id
        resource_type = TaggableResourceTypes.PIPELINE_RUN

    else:
        raise ValueError(
            f"""
            Unsupported way to call the `add_tags`. Possible combinations "
            include: \n{add_tags_warning}
            """
        )

    if resource_id:
        for tag in tags:
            client.attach_tag(
                tag=tag,
                resources=[TagResource(id=resource_id, type=resource_type)],
            )
bulk_log_metadata(metadata: Dict[str, MetadataType], pipeline_runs: list[PipelineRunIdentifier] | None = None, step_runs: list[StepRunIdentifier] | None = None, artifact_versions: list[ArtifactVersionIdentifier] | None = None, model_versions: list[ModelVersionIdentifier] | None = None, infer_models: bool = False, infer_artifacts: bool = False) -> None

Logs metadata for multiple entities in a single invocation.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
pipeline_runs list[PipelineRunIdentifier] | None

A list of pipeline runs to log metadata for.

None
step_runs list[StepRunIdentifier] | None

A list of step runs to log metadata for.

None
artifact_versions list[ArtifactVersionIdentifier] | None

A list of artifact versions to log metadata for.

None
model_versions list[ModelVersionIdentifier] | None

A list of model versions to log metadata for.

None
infer_models bool

Flag - when enabled infer model to log metadata for from step context.

False
infer_artifacts bool

Flag - when enabled infer artifact to log metadata for from step context.

False

Raises:

Type Description
ValueError

If options are not passed correctly (empty metadata or no identifier options) or invocation with infer options is done outside of a step context.

Source code in src/zenml/utils/metadata_utils.py
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
450
451
452
453
454
455
456
457
458
459
460
461
462
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def bulk_log_metadata(
    metadata: Dict[str, MetadataType],
    pipeline_runs: list[PipelineRunIdentifier] | None = None,
    step_runs: list[StepRunIdentifier] | None = None,
    artifact_versions: list[ArtifactVersionIdentifier] | None = None,
    model_versions: list[ModelVersionIdentifier] | None = None,
    infer_models: bool = False,
    infer_artifacts: bool = False,
) -> None:
    """Logs metadata for multiple entities in a single invocation.

    Args:
        metadata: The metadata to log.
        pipeline_runs: A list of pipeline runs to log metadata for.
        step_runs: A list of step runs to log metadata for.
        artifact_versions: A list of artifact versions to log metadata for.
        model_versions: A list of model versions to log metadata for.
        infer_models: Flag - when enabled infer model to log metadata for from step context.
        infer_artifacts: Flag - when enabled infer artifact to log metadata for from step context.

    Raises:
        ValueError: If options are not passed correctly (empty metadata or no identifier options) or
            invocation with `infer` options is done outside of a step context.
    """
    client = Client()

    resources: Set[RunMetadataResource] = set()

    if not metadata:
        raise ValueError("You must provide metadata to log.")

    if not any(
        bool(v)
        for v in [
            pipeline_runs,
            step_runs,
            artifact_versions,
            model_versions,
            infer_models,
            infer_artifacts,
        ]
    ):
        raise ValueError(
            "You must select at least one entity to log metadata to."
        )

    try:
        step_context = get_step_context()
    except RuntimeError:
        step_context = None

    if (infer_models or infer_artifacts) and step_context is None:
        raise ValueError(
            "Infer options can be used only within a step function code."
        )

    # resolve pipeline runs and add metadata resources

    for run in pipeline_runs or []:
        if not run.id:
            run.id = client.get_pipeline_run(name_id_or_prefix=run.value).id
        resources.add(
            RunMetadataResource(
                id=run.id, type=MetadataResourceTypes.PIPELINE_RUN
            )
        )

    # resolve step runs and add metadata resources

    for step in step_runs or []:
        if not step.id and (step.name and step.run):
            run_model = client.get_pipeline_run(
                name_id_or_prefix=step.run.value
            )
            step.id = client.list_run_steps(
                pipeline_run_id=run_model.id, name=step.name
            )[0].id

        resources.add(
            RunMetadataResource(
                id=step.id, type=MetadataResourceTypes.STEP_RUN
            )
        )

    # resolve artifacts and add metadata resources

    for artifact_version in artifact_versions or []:
        if not artifact_version.id and (
            artifact_version.name and artifact_version.version
        ):
            artifact_version.id = client.get_artifact_version(
                name_id_or_prefix=artifact_version.name,
                version=artifact_version.version,
            ).id
        resources.add(
            RunMetadataResource(
                id=artifact_version.id,
                type=MetadataResourceTypes.ARTIFACT_VERSION,
            )
        )

    # resolve models and add metadata resources

    for model_version in model_versions or []:
        if not model_version.id:
            model_version.id = client.get_model_version(
                model_name_or_id=model_version.name,
                model_version_name_or_number_or_id=model_version.version,
            ).id
        resources.add(
            RunMetadataResource(
                id=model_version.id, type=MetadataResourceTypes.MODEL_VERSION
            )
        )

    # infer models - resolve from step context

    if infer_models and step_context and not step_context.model_version:
        raise ValueError(
            "The step context does not feature any model versions."
        )
    elif infer_models and step_context and step_context.model_version:
        resources.add(
            RunMetadataResource(
                id=step_context.model_version.id,
                type=MetadataResourceTypes.MODEL_VERSION,
            )
        )

    # infer artifacts - resolve from step context

    if infer_artifacts and step_context:
        step_output_names = list(step_context._outputs.keys())

        for artifact_name in step_output_names:
            step_context.add_output_metadata(
                metadata=metadata, output_name=artifact_name
            )

    if not resources:
        return

    client.create_run_metadata(
        metadata=metadata,
        resources=list(resources),
        publisher_step_id=None,
    )
get_pipeline_context() -> PipelineContext

Get the context of the current pipeline.

Returns:

Type Description
PipelineContext

The context of the current pipeline.

Raises:

Type Description
RuntimeError

If no active pipeline is found.

RuntimeError

If inside a running step.

Source code in src/zenml/pipelines/pipeline_context.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def get_pipeline_context() -> "PipelineContext":
    """Get the context of the current pipeline.

    Returns:
        The context of the current pipeline.

    Raises:
        RuntimeError: If no active pipeline is found.
        RuntimeError: If inside a running step.
    """
    from zenml.pipelines.compilation_context import PipelineCompilationContext

    context = PipelineCompilationContext.get()

    if context is None:
        try:
            from zenml.steps.step_context import get_step_context

            get_step_context()
        except RuntimeError:
            raise RuntimeError("No active pipeline found.")
        else:
            raise RuntimeError(
                "Inside a step use `from zenml import get_step_context` "
                "instead."
            )

    return PipelineContext(
        pipeline_configuration=context.pipeline.configuration
    )
get_step_context() -> StepContext

Get the context of the currently running step.

Returns:

Type Description
StepContext

The context of the currently running step.

Raises:

Type Description
RuntimeError

If no step is currently running.

Source code in src/zenml/steps/step_context.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def get_step_context() -> "StepContext":
    """Get the context of the currently running step.

    Returns:
        The context of the currently running step.

    Raises:
        RuntimeError: If no step is currently running.
    """
    if ctx := StepContext.get():
        return ctx

    raise RuntimeError(
        "The step context is only available inside a step function."
    )

Link the artifact to the model.

Parameters:

Name Type Description Default
artifact_version ArtifactVersionResponse

The artifact version to link.

required
model Optional[Model]

The model to link to.

None

Raises:

Type Description
RuntimeError

If called outside a step.

Source code in src/zenml/model/utils.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def link_artifact_to_model(
    artifact_version: ArtifactVersionResponse,
    model: Optional["Model"] = None,
) -> None:
    """Link the artifact to the model.

    Args:
        artifact_version: The artifact version to link.
        model: The model to link to.

    Raises:
        RuntimeError: If called outside a step.
    """
    if not model:
        is_issue = False
        try:
            step_context = get_step_context()
            model = step_context.model
        except StepContextError:
            is_issue = True

        if model is None or is_issue:
            raise RuntimeError(
                "`link_artifact_to_model` called without `model` parameter "
                "and configured model context cannot be identified. Consider "
                "passing the `model` explicitly or configuring it in "
                "@step or @pipeline decorator."
            )

    model_version = model._get_or_create_model_version()
    link_artifact_version_to_model_version(
        artifact_version=artifact_version,
        model_version=model_version,
    )
load_artifact(name_or_id: Union[str, UUID], version: Optional[str] = None) -> Any

Load an artifact.

Parameters:

Name Type Description Default
name_or_id Union[str, UUID]

The name or ID of the artifact to load.

required
version Optional[str]

The version of the artifact to load, if name_or_id is a name. If not provided, the latest version will be loaded.

None

Returns:

Type Description
Any

The loaded artifact.

Source code in src/zenml/artifacts/utils.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def load_artifact(
    name_or_id: Union[str, UUID],
    version: Optional[str] = None,
) -> Any:
    """Load an artifact.

    Args:
        name_or_id: The name or ID of the artifact to load.
        version: The version of the artifact to load, if `name_or_id` is a
            name. If not provided, the latest version will be loaded.

    Returns:
        The loaded artifact.
    """
    artifact = Client().get_artifact_version(name_or_id, version)
    return load_artifact_from_response(artifact)
log_artifact_metadata(metadata: Dict[str, MetadataType], artifact_name: Optional[str] = None, artifact_version: Optional[str] = None) -> None

Log artifact metadata.

This function can be used to log metadata for either existing artifact versions or artifact versions that are newly created in the same step.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
artifact_name Optional[str]

The name of the artifact to log metadata for. Can be omitted when being called inside a step with only one output.

None
artifact_version Optional[str]

The version of the artifact to log metadata for. If not provided, when being called inside a step that produces an artifact named artifact_name, the metadata will be associated to the corresponding newly created artifact.

None

Raises:

Type Description
ValueError

If no artifact name is provided and the function is not called inside a step with a single output, or, if neither an artifact nor an output with the given name exists.

Source code in src/zenml/artifacts/utils.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
def log_artifact_metadata(
    metadata: Dict[str, "MetadataType"],
    artifact_name: Optional[str] = None,
    artifact_version: Optional[str] = None,
) -> None:
    """Log artifact metadata.

    This function can be used to log metadata for either existing artifact
    versions or artifact versions that are newly created in the same step.

    Args:
        metadata: The metadata to log.
        artifact_name: The name of the artifact to log metadata for. Can
            be omitted when being called inside a step with only one output.
        artifact_version: The version of the artifact to log metadata for. If
            not provided, when being called inside a step that produces an
            artifact named `artifact_name`, the metadata will be associated to
            the corresponding newly created artifact.

    Raises:
        ValueError: If no artifact name is provided and the function is not
            called inside a step with a single output, or, if neither an
            artifact nor an output with the given name exists.

    """
    logger.warning(
        "The `log_artifact_metadata` function is deprecated and will soon be "
        "removed. Instead, you can consider using: "
        "`log_metadata(metadata={...}, infer_artifact=True, ...)` instead. For more "
        "info: https://docs.zenml.io/how-to/model-management-metrics/track-metrics-metadata/attach-metadata-to-an-artifact"
    )

    from zenml import log_metadata

    if artifact_name and artifact_version:
        assert artifact_name is not None

        log_metadata(
            metadata=metadata,
            artifact_name=artifact_name,
            artifact_version=artifact_version,
        )

    step_context = None
    with contextlib.suppress(RuntimeError):
        step_context = get_step_context()

    if step_context and artifact_name in step_context._outputs.keys():
        log_metadata(
            metadata=metadata,
            artifact_name=artifact_name,
            infer_artifact=True,
        )
    elif step_context and len(step_context._outputs) == 1:
        single_output_name = list(step_context._outputs.keys())[0]

        log_metadata(
            metadata=metadata,
            artifact_name=single_output_name,
            infer_artifact=True,
        )
    elif artifact_name:
        client = Client()
        logger.warning(
            "Deprecation warning! Currently, you are calling "
            "`log_artifact_metadata` from a context, where we use the "
            "`artifact_name` to fetch it and link the metadata to its "
            "latest version. This behavior is deprecated and will be "
            "removed in the future. To circumvent this, please check"
            "the `log_metadata` function."
        )
        artifact_version_model = client.get_artifact_version(
            name_id_or_prefix=artifact_name
        )
        log_metadata(
            metadata=metadata,
            artifact_version_id=artifact_version_model.id,
        )
    else:
        raise ValueError(
            "You need to call `log_artifact_metadata` either within a step "
            "(potentially with an artifact name) or outside of a step with an "
            "artifact name (and/or version)."
        )
log_metadata(metadata: Dict[str, MetadataType], step_id: Optional[UUID] = None, step_name: Optional[str] = None, run_id_name_or_prefix: Optional[Union[UUID, str]] = None, artifact_version_id: Optional[UUID] = None, artifact_name: Optional[str] = None, artifact_version: Optional[str] = None, infer_artifact: bool = False, model_version_id: Optional[UUID] = None, model_name: Optional[str] = None, model_version: Optional[Union[ModelStages, int, str]] = None, infer_model: bool = False) -> None
log_metadata(metadata: Dict[str, MetadataType]) -> None
log_metadata(
    *, metadata: Dict[str, MetadataType], step_id: UUID
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    step_name: str,
    run_id_name_or_prefix: Union[UUID, str],
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    run_id_name_or_prefix: Union[UUID, str],
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    artifact_version_id: UUID,
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    artifact_name: str,
    artifact_version: Optional[str] = None,
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    infer_artifact: bool = False,
    artifact_name: Optional[str] = None,
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    model_version_id: UUID,
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    model_name: str,
    model_version: Union[ModelStages, int, str],
) -> None
log_metadata(
    *,
    metadata: Dict[str, MetadataType],
    infer_model: bool = False,
) -> None

Logs metadata for various resource types in a generalized way.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
step_id Optional[UUID]

The ID of the step.

None
step_name Optional[str]

The name of the step.

None
run_id_name_or_prefix Optional[Union[UUID, str]]

The id, name or prefix of the run

None
artifact_version_id Optional[UUID]

The ID of the artifact version

None
artifact_name Optional[str]

The name of the artifact.

None
artifact_version Optional[str]

The version of the artifact.

None
infer_artifact bool

Flag deciding whether the artifact version should be inferred from the step context.

False
model_version_id Optional[UUID]

The ID of the model version.

None
model_name Optional[str]

The name of the model.

None
model_version Optional[Union[ModelStages, int, str]]

The version of the model.

None
infer_model bool

Flag deciding whether the model version should be inferred from the step context.

False

Raises:

Type Description
ValueError

If no identifiers are provided and the function is not called from within a step.

Source code in src/zenml/utils/metadata_utils.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
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
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
276
277
278
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
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
def log_metadata(
    metadata: Dict[str, MetadataType],
    # Steps and runs
    step_id: Optional[UUID] = None,
    step_name: Optional[str] = None,
    run_id_name_or_prefix: Optional[Union[UUID, str]] = None,
    # Artifacts
    artifact_version_id: Optional[UUID] = None,
    artifact_name: Optional[str] = None,
    artifact_version: Optional[str] = None,
    infer_artifact: bool = False,
    # Models
    model_version_id: Optional[UUID] = None,
    model_name: Optional[str] = None,
    model_version: Optional[Union[ModelStages, int, str]] = None,
    infer_model: bool = False,
) -> None:
    """Logs metadata for various resource types in a generalized way.

    Args:
        metadata: The metadata to log.
        step_id: The ID of the step.
        step_name: The name of the step.
        run_id_name_or_prefix: The id, name or prefix of the run
        artifact_version_id: The ID of the artifact version
        artifact_name: The name of the artifact.
        artifact_version: The version of the artifact.
        infer_artifact: Flag deciding whether the artifact version should be
            inferred from the step context.
        model_version_id: The ID of the model version.
        model_name: The name of the model.
        model_version: The version of the model.
        infer_model: Flag deciding whether the model version should be
            inferred from the step context.

    Raises:
        ValueError: If no identifiers are provided and the function is not
            called from within a step.
    """
    client = Client()

    resources: List[RunMetadataResource] = []
    publisher_step_id = None

    # Log metadata to a step by ID
    if step_id is not None:
        resources = [
            RunMetadataResource(
                id=step_id, type=MetadataResourceTypes.STEP_RUN
            )
        ]

    # Log metadata to a step by name and run ID
    elif step_name is not None and run_id_name_or_prefix is not None:
        run = client.get_pipeline_run(name_id_or_prefix=run_id_name_or_prefix)
        step_model_id = client.list_run_steps(
            pipeline_run_id=run.id, name=step_name
        )[0].id
        resources = [
            RunMetadataResource(
                id=step_model_id, type=MetadataResourceTypes.STEP_RUN
            )
        ]

    # Log metadata to a run by ID
    elif run_id_name_or_prefix is not None:
        run_model = client.get_pipeline_run(
            name_id_or_prefix=run_id_name_or_prefix
        )
        resources = [
            RunMetadataResource(
                id=run_model.id, type=MetadataResourceTypes.PIPELINE_RUN
            )
        ]

    # Log metadata to a model version by name and version
    elif model_name is not None and model_version is not None:
        model_version_model = client.get_model_version(
            model_name_or_id=model_name,
            model_version_name_or_number_or_id=model_version,
        )
        resources = [
            RunMetadataResource(
                id=model_version_model.id,
                type=MetadataResourceTypes.MODEL_VERSION,
            )
        ]

    # Log metadata to a model version by id
    elif model_version_id is not None:
        resources = [
            RunMetadataResource(
                id=model_version_id,
                type=MetadataResourceTypes.MODEL_VERSION,
            )
        ]

    # Log metadata to a model through the step context
    elif infer_model is True:
        try:
            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                "If you are using the `infer_model` option, the function must "
                "be called inside a step with configured `model` in decorator."
                "Otherwise, you can provide a `model_version_id` or a "
                "combination of `model_name` and `model_version`."
            )

        if step_context.model_version is None:
            raise ValueError(
                "The step context does not feature any model versions."
            )

        resources = [
            RunMetadataResource(
                id=step_context.model_version.id,
                type=MetadataResourceTypes.MODEL_VERSION,
            )
        ]

    # Log metadata to an artifact version by its name and version
    elif artifact_name is not None and artifact_version is not None:
        artifact_version_model = client.get_artifact_version(
            name_id_or_prefix=artifact_name, version=artifact_version
        )
        resources = [
            RunMetadataResource(
                id=artifact_version_model.id,
                type=MetadataResourceTypes.ARTIFACT_VERSION,
            )
        ]

    # Log metadata to an artifact version by its ID
    elif artifact_version_id is not None:
        resources = [
            RunMetadataResource(
                id=artifact_version_id,
                type=MetadataResourceTypes.ARTIFACT_VERSION,
            )
        ]

    # Log metadata to an artifact version through the step context
    elif infer_artifact is True:
        try:
            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                "When you are using the `infer_artifact` option when you call "
                "`log_metadata`, it must be called inside a step with outputs."
                "Otherwise, you can provide a `artifact_version_id` or a "
                "combination of `artifact_name` and `artifact_version`."
            )

        step_output_names = list(step_context._outputs.keys())

        if artifact_name is not None:
            # If a name provided, ensure it is in the outputs
            if artifact_name not in step_output_names:
                raise ValueError(
                    f"The provided artifact name`{artifact_name}` does not "
                    f"exist in the step outputs: {step_output_names}."
                )
        else:
            # If no name provided, ensure there is only one output
            if len(step_output_names) > 1:
                raise ValueError(
                    "There is more than one output. If you would like to use "
                    "the `infer_artifact` option, you need to define an "
                    "`artifact_name`."
                )

            if len(step_output_names) == 0:
                raise ValueError("The step does not have any outputs.")

            artifact_name = step_output_names[0]

        step_context.add_output_metadata(
            metadata=metadata, output_name=artifact_name
        )
        return

    # If every additional value is None, that means we are calling it bare bones
    # and this call needs to happen during a step execution. We will use the
    # step context to fetch the step, run and possibly the model version and
    # attach the metadata accordingly.
    elif all(
        v is None
        for v in [
            step_id,
            step_name,
            run_id_name_or_prefix,
            artifact_version_id,
            artifact_name,
            artifact_version,
            model_version_id,
            model_name,
            model_version,
        ]
    ):
        try:
            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                "You are calling 'log_metadata()' outside of a step execution. "
                "If you would like to add metadata to a ZenML entity outside "
                "of the step execution, please provide the required "
                "identifiers."
            )

        resources = [
            RunMetadataResource(
                id=step_context.step_run.id,
                type=MetadataResourceTypes.STEP_RUN,
            )
        ]
        publisher_step_id = step_context.step_run.id

    else:
        raise ValueError(
            """
            Unsupported way to call the `log_metadata`. Possible combinations "
            include:

            # Automatic logging to a step (within a step)
            log_metadata(metadata={})

            # Manual logging to a step
            log_metadata(metadata={}, step_name=..., run_id_name_or_prefix=...)
            log_metadata(metadata={}, step_id=...)

            # Manual logging to a run
            log_metadata(metadata={}, run_id_name_or_prefix=...)

            # Automatic logging to a model (within a step)
            log_metadata(metadata={}, infer_model=True)

            # Manual logging to a model
            log_metadata(metadata={}, model_name=..., model_version=...)
            log_metadata(metadata={}, model_version_id=...)

            # Automatic logging to an artifact (within a step)
            log_metadata(metadata={}, infer_artifact=True)  # step with single output
            log_metadata(metadata={}, artifact_name=..., infer_artifact=True)  # specific output of a step

            # Manual logging to an artifact
            log_metadata(metadata={}, artifact_name=..., artifact_version=...)
            log_metadata(metadata={}, artifact_version_id=...)
            """
        )

    client.create_run_metadata(
        metadata=metadata,
        resources=resources,
        publisher_step_id=publisher_step_id,
    )
log_model_metadata(metadata: Dict[str, MetadataType], model_name: Optional[str] = None, model_version: Optional[Union[ModelStages, int, str]] = None) -> None

Log model version metadata.

This function can be used to log metadata for existing model versions.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
model_name Optional[str]

The name of the model to log metadata for. Can be omitted when being called inside a step with configured model in decorator.

None
model_version Optional[Union[ModelStages, int, str]]

The version of the model to log metadata for. Can be omitted when being called inside a step with configured model in decorator.

None

Raises:

Type Description
ValueError

If the function is not called with proper input.

Source code in src/zenml/model/utils.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def log_model_metadata(
    metadata: Dict[str, "MetadataType"],
    model_name: Optional[str] = None,
    model_version: Optional[Union[ModelStages, int, str]] = None,
) -> None:
    """Log model version metadata.

    This function can be used to log metadata for existing model versions.

    Args:
        metadata: The metadata to log.
        model_name: The name of the model to log metadata for. Can
            be omitted when being called inside a step with configured
            `model` in decorator.
        model_version: The version of the model to log metadata for. Can
            be omitted when being called inside a step with configured
            `model` in decorator.

    Raises:
        ValueError: If the function is not called with proper input.
    """
    logger.warning(
        "The `log_model_metadata` function is deprecated and will soon be "
        "removed. Instead, you can consider using: "
        "`log_metadata(metadata={...}, infer_model=True)` instead. For more "
        "info: https://docs.zenml.io/concepts/metadata#attaching-metadata-to-models"
    )

    from zenml import log_metadata

    if model_name and model_version:
        log_metadata(
            metadata=metadata,
            model_version=model_version,
            model_name=model_name,
        )
    elif model_name is None and model_version is None:
        log_metadata(
            metadata=metadata,
            infer_model=True,
        )
    else:
        raise ValueError(
            "You can call `log_model_metadata` by either providing both "
            "`model_name` and `model_version` or keeping both of them None."
        )
log_step_metadata(metadata: Dict[str, MetadataType], step_name: Optional[str] = None, pipeline_name_id_or_prefix: Optional[Union[str, UUID]] = None, run_id: Optional[str] = None) -> None

Logs step metadata.

Parameters:

Name Type Description Default
metadata Dict[str, MetadataType]

The metadata to log.

required
step_name Optional[str]

The name of the step to log metadata for. Can be omitted when being called inside a step.

None
pipeline_name_id_or_prefix Optional[Union[str, UUID]]

The name of the pipeline to log metadata for. Can be omitted when being called inside a step.

None
run_id Optional[str]

The ID of the run to log metadata for. Can be omitted when being called inside a step.

None

Raises:

Type Description
ValueError

If no step name is provided and the function is not called from within a step or if no pipeline name or ID is provided and the function is not called from within a step.

Source code in src/zenml/steps/utils.py
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
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 log_step_metadata(
    metadata: Dict[str, "MetadataType"],
    step_name: Optional[str] = None,
    pipeline_name_id_or_prefix: Optional[Union[str, UUID]] = None,
    run_id: Optional[str] = None,
) -> None:
    """Logs step metadata.

    Args:
        metadata: The metadata to log.
        step_name: The name of the step to log metadata for. Can be omitted
            when being called inside a step.
        pipeline_name_id_or_prefix: The name of the pipeline to log metadata
            for. Can be omitted when being called inside a step.
        run_id: The ID of the run to log metadata for. Can be omitted when
            being called inside a step.

    Raises:
        ValueError: If no step name is provided and the function is not called
            from within a step or if no pipeline name or ID is provided and
            the function is not called from within a step.
    """
    logger.warning(
        "The `log_step_metadata` function is deprecated and will soon be "
        "removed. Please use `log_metadata` instead."
    )

    step_context = None
    if not step_name:
        with contextlib.suppress(RuntimeError):
            step_context = get_step_context()
            step_name = step_context.step_name
    # not running within a step and no user-provided step name
    if not step_name:
        raise ValueError(
            "No step name provided and you are not running "
            "within a step. Please provide a step name."
        )

    client = Client()
    if step_context:
        step_run_id = step_context.step_run.id
    elif run_id:
        step_run_id = UUID(int=int(run_id))
    else:
        if not pipeline_name_id_or_prefix:
            raise ValueError(
                "No pipeline name or ID provided and you are not running "
                "within a step. Please provide a pipeline name or ID, or "
                "provide a run ID."
            )
        pipeline_run = client.get_pipeline(
            name_id_or_prefix=pipeline_name_id_or_prefix,
        ).last_run
        step_run_id = pipeline_run.steps[step_name].id
    client.create_run_metadata(
        metadata=metadata,
        resources=[
            RunMetadataResource(
                id=step_run_id, type=MetadataResourceTypes.STEP_RUN
            )
        ],
    )
pipeline(_func: Optional[F] = None, *, name: Optional[str] = None, dynamic: Optional[bool] = None, depends_on: Optional[List[BaseStep]] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_step_logs: Optional[bool] = None, enable_heartbeat: Optional[bool] = None, environment: Optional[Dict[str, Any]] = None, secrets: Optional[List[Union[UUID, str]]] = None, enable_pipeline_logs: Optional[bool] = None, settings: Optional[Dict[str, SettingsOrDict]] = None, tags: Optional[List[Union[str, Tag]]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, on_init: Optional[InitHookSpecification] = None, on_init_kwargs: Optional[Dict[str, Any]] = None, on_cleanup: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, execution_mode: Optional[ExecutionMode] = None, cache_policy: Optional[CachePolicyOrString] = None) -> Union[Pipeline, Callable[[F], Pipeline]]
pipeline(_func: F) -> Pipeline
pipeline(
    *,
    name: Optional[str] = None,
    dynamic: Optional[bool] = None,
    depends_on: Optional[List[BaseStep]] = None,
    enable_cache: Optional[bool] = None,
    enable_artifact_metadata: Optional[bool] = None,
    enable_step_logs: Optional[bool] = None,
    enable_heartbeat: Optional[bool] = None,
    environment: Optional[Dict[str, Any]] = None,
    secrets: Optional[List[Union[UUID, str]]] = None,
    enable_pipeline_logs: Optional[bool] = None,
    settings: Optional[Dict[str, SettingsOrDict]] = None,
    tags: Optional[List[Union[str, Tag]]] = None,
    extra: Optional[Dict[str, Any]] = None,
    on_failure: Optional[HookSpecification] = None,
    on_success: Optional[HookSpecification] = None,
    on_init: Optional[InitHookSpecification] = None,
    on_init_kwargs: Optional[Dict[str, Any]] = None,
    on_cleanup: Optional[HookSpecification] = None,
    model: Optional[Model] = None,
    retry: Optional[StepRetryConfig] = None,
    substitutions: Optional[Dict[str, str]] = None,
    execution_mode: Optional[ExecutionMode] = None,
    cache_policy: Optional[CachePolicyOrString] = None,
) -> Callable[[F], Pipeline]

Decorator to create a pipeline.

Parameters:

Name Type Description Default
_func Optional[F]

The decorated function.

None
name Optional[str]

The name of the pipeline. If left empty, the name of the decorated function will be used as a fallback.

None
dynamic Optional[bool]

Whether this is a dynamic pipeline or not.

None
depends_on Optional[List[BaseStep]]

The steps that this pipeline depends on.

None
enable_cache Optional[bool]

Whether to use caching or not.

None
enable_artifact_metadata Optional[bool]

Whether to enable artifact metadata or not.

None
enable_step_logs Optional[bool]

If step logs should be enabled for this pipeline.

None
enable_heartbeat Optional[bool]

If heartbeat should be enabled for this pipeline.

None
environment Optional[Dict[str, Any]]

Environment variables to set when running this pipeline.

None
secrets Optional[List[Union[UUID, str]]]

Secrets to set as environment variables when running this pipeline.

None
enable_pipeline_logs Optional[bool]

If pipeline logs should be enabled for this pipeline.

None
settings Optional[Dict[str, SettingsOrDict]]

Settings for this pipeline.

None
tags Optional[List[Union[str, Tag]]]

Tags to apply to runs of the pipeline.

None
extra Optional[Dict[str, Any]]

Extra configurations for this pipeline.

None
on_failure Optional[HookSpecification]

Callback function in event of failure of the step. Can be a function with a single argument of type BaseException, or a source path to such a function (e.g. module.my_function).

None
on_success Optional[HookSpecification]

Callback function in event of success of the step. Can be a function with no arguments, or a source path to such a function (e.g. module.my_function).

None
on_init Optional[InitHookSpecification]

Callback function to run on initialization of the pipeline. Can be a function with no arguments, or a source path to such a function (e.g. module.my_function) if the function returns a value, it will be stored as the pipeline state.

None
on_init_kwargs Optional[Dict[str, Any]]

Arguments for the init hook.

None
on_cleanup Optional[HookSpecification]

Callback function to run on cleanup of the pipeline. Can be a function with no arguments, or a source path to such a function (e.g. module.my_function).

None
model Optional[Model]

configuration of the model in the Model Control Plane.

None
retry Optional[StepRetryConfig]

Retry configuration for the pipeline steps.

None
substitutions Optional[Dict[str, str]]

Extra substitutions for pipeline run, model and artifact name placeholders.

None
execution_mode Optional[ExecutionMode]

The execution mode to use for the pipeline.

None
cache_policy Optional[CachePolicyOrString]

Cache policy for this pipeline.

None

Returns:

Type Description
Union[Pipeline, Callable[[F], Pipeline]]

A pipeline instance.

Source code in src/zenml/pipelines/pipeline_decorator.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
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
def pipeline(
    _func: Optional["F"] = None,
    *,
    name: Optional[str] = None,
    dynamic: Optional[bool] = None,
    depends_on: Optional[List["BaseStep"]] = None,
    enable_cache: Optional[bool] = None,
    enable_artifact_metadata: Optional[bool] = None,
    enable_step_logs: Optional[bool] = None,
    enable_heartbeat: Optional[bool] = None,
    environment: Optional[Dict[str, Any]] = None,
    secrets: Optional[List[Union[UUID, str]]] = None,
    enable_pipeline_logs: Optional[bool] = None,
    settings: Optional[Dict[str, "SettingsOrDict"]] = None,
    tags: Optional[List[Union[str, "Tag"]]] = None,
    extra: Optional[Dict[str, Any]] = None,
    on_failure: Optional["HookSpecification"] = None,
    on_success: Optional["HookSpecification"] = None,
    on_init: Optional["InitHookSpecification"] = None,
    on_init_kwargs: Optional[Dict[str, Any]] = None,
    on_cleanup: Optional["HookSpecification"] = None,
    model: Optional["Model"] = None,
    retry: Optional["StepRetryConfig"] = None,
    substitutions: Optional[Dict[str, str]] = None,
    execution_mode: Optional["ExecutionMode"] = None,
    cache_policy: Optional["CachePolicyOrString"] = None,
) -> Union["Pipeline", Callable[["F"], "Pipeline"]]:
    """Decorator to create a pipeline.

    Args:
        _func: The decorated function.
        name: The name of the pipeline. If left empty, the name of the
            decorated function will be used as a fallback.
        dynamic: Whether this is a dynamic pipeline or not.
        depends_on: The steps that this pipeline depends on.
        enable_cache: Whether to use caching or not.
        enable_artifact_metadata: Whether to enable artifact metadata or not.
        enable_step_logs: If step logs should be enabled for this pipeline.
        enable_heartbeat: If heartbeat should be enabled for this pipeline.
        environment: Environment variables to set when running this pipeline.
        secrets: Secrets to set as environment variables when running this
            pipeline.
        enable_pipeline_logs: If pipeline logs should be enabled for this pipeline.
        settings: Settings for this pipeline.
        tags: Tags to apply to runs of the pipeline.
        extra: Extra configurations for this pipeline.
        on_failure: Callback function in event of failure of the step. Can be a
            function with a single argument of type `BaseException`, or a source
            path to such a function (e.g. `module.my_function`).
        on_success: Callback function in event of success of the step. Can be a
            function with no arguments, or a source path to such a function
            (e.g. `module.my_function`).
        on_init: Callback function to run on initialization of the pipeline. Can
            be a function with no arguments, or a source path to such a function
            (e.g. `module.my_function`) if the function returns a value, it will
            be stored as the pipeline state.
        on_init_kwargs: Arguments for the init hook.
        on_cleanup: Callback function to run on cleanup of the pipeline. Can be a
            function with no arguments, or a source path to such a function
            (e.g. `module.my_function`).
        model: configuration of the model in the Model Control Plane.
        retry: Retry configuration for the pipeline steps.
        substitutions: Extra substitutions for pipeline run, model and
            artifact name placeholders.
        execution_mode: The execution mode to use for the pipeline.
        cache_policy: Cache policy for this pipeline.

    Returns:
        A pipeline instance.
    """

    def inner_decorator(func: "F") -> "Pipeline":
        from zenml.pipelines.pipeline_definition import Pipeline

        PipelineClass = Pipeline
        pipeline_args: Dict[str, Any] = {}

        if dynamic:
            from zenml.pipelines.dynamic.pipeline_definition import (
                DynamicPipeline,
            )

            PipelineClass = DynamicPipeline

            pipeline_args = {
                "depends_on": depends_on,
            }
        elif depends_on:
            logger.warning(
                "The `depends_on` argument is not supported "
                "for static pipelines and will be ignored."
            )

        p = PipelineClass(
            name=name or func.__name__,
            entrypoint=func,
            enable_cache=enable_cache,
            enable_artifact_metadata=enable_artifact_metadata,
            enable_step_logs=enable_step_logs,
            enable_heartbeat=enable_heartbeat,
            environment=environment,
            secrets=secrets,
            enable_pipeline_logs=enable_pipeline_logs,
            settings=settings,
            tags=tags,
            extra=extra,
            on_failure=on_failure,
            on_success=on_success,
            on_init=on_init,
            on_init_kwargs=on_init_kwargs,
            on_cleanup=on_cleanup,
            model=model,
            retry=retry,
            substitutions=substitutions,
            execution_mode=execution_mode,
            cache_policy=cache_policy,
            **pipeline_args,
        )

        p.__doc__ = func.__doc__
        return p

    return inner_decorator if _func is None else inner_decorator(_func)
register_artifact(folder_or_file_uri: str, name: str, version: Optional[Union[int, str]] = None, artifact_type: Optional[ArtifactType] = None, tags: Optional[List[str]] = None, has_custom_name: bool = True, artifact_metadata: Dict[str, MetadataType] = {}) -> ArtifactVersionResponse

Register existing data stored in the artifact store as a ZenML Artifact.

Parameters:

Name Type Description Default
folder_or_file_uri str

The full URI within the artifact store to the folder or to the file.

required
name str

The name of the artifact.

required
version Optional[Union[int, str]]

The version of the artifact. If not provided, a new auto-incremented version will be used.

None
artifact_type Optional[ArtifactType]

The artifact type. If not given, the type will default to data.

None
tags Optional[List[str]]

Tags to associate with the artifact.

None
has_custom_name bool

If the artifact name is custom and should be listed in the dashboard "Artifacts" tab.

True
artifact_metadata Dict[str, MetadataType]

Metadata dictionary to attach to the artifact version.

{}

Returns:

Type Description
ArtifactVersionResponse

The saved artifact response.

Raises:

Type Description
FileNotFoundError

If the folder URI is outside the artifact store bounds.

Source code in src/zenml/artifacts/utils.py
317
318
319
320
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
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
def register_artifact(
    folder_or_file_uri: str,
    name: str,
    version: Optional[Union[int, str]] = None,
    artifact_type: Optional[ArtifactType] = None,
    tags: Optional[List[str]] = None,
    has_custom_name: bool = True,
    artifact_metadata: Dict[str, "MetadataType"] = {},
) -> "ArtifactVersionResponse":
    """Register existing data stored in the artifact store as a ZenML Artifact.

    Args:
        folder_or_file_uri: The full URI within the artifact store to the folder
            or to the file.
        name: The name of the artifact.
        version: The version of the artifact. If not provided, a new
            auto-incremented version will be used.
        artifact_type: The artifact type. If not given, the type will default
            to `data`.
        tags: Tags to associate with the artifact.
        has_custom_name: If the artifact name is custom and should be listed in
            the dashboard "Artifacts" tab.
        artifact_metadata: Metadata dictionary to attach to the artifact version.

    Returns:
        The saved artifact response.

    Raises:
        FileNotFoundError: If the folder URI is outside the artifact store
            bounds.
    """
    client = Client()

    # Get the current artifact store
    artifact_store = client.active_stack.artifact_store

    if not folder_or_file_uri.startswith(artifact_store.path):
        raise FileNotFoundError(
            f"Folder `{folder_or_file_uri}` is outside of "
            f"artifact store bounds `{artifact_store.path}`"
        )

    _check_if_artifact_with_given_uri_already_registered(
        artifact_store=artifact_store,
        uri=folder_or_file_uri,
        name=name,
    )

    artifact_version_request = ArtifactVersionRequest(
        artifact_name=name,
        version=version,
        tags=tags,
        type=artifact_type or ArtifactType.DATA,
        save_type=ArtifactSaveType.PREEXISTING,
        uri=folder_or_file_uri,
        materializer=source_utils.resolve(PreexistingDataMaterializer),
        data_type=source_utils.resolve(Path),
        project=Client().active_project.id,
        artifact_store_id=artifact_store.id,
        has_custom_name=has_custom_name,
        metadata=validate_metadata(artifact_metadata)
        if artifact_metadata
        else None,
    )
    artifact_version = client.zen_store.create_artifact_version(
        artifact_version=artifact_version_request
    )

    _link_artifact_version_to_the_step_and_model(
        artifact_version=artifact_version,
    )

    return artifact_version
remove_tags(tags: Union[str, List[str]], pipeline: Optional[Union[UUID, str]] = None, run: Optional[Union[UUID, str]] = None, run_template: Optional[Union[UUID, str]] = None, snapshot: Optional[Union[UUID, str]] = None, deployment: Optional[Union[UUID, str]] = None, artifact: Optional[Union[UUID, str]] = None, artifact_version_id: Optional[UUID] = None, artifact_name: Optional[str] = None, artifact_version: Optional[str] = None, infer_artifact: Optional[bool] = None) -> None
remove_tags(tags: Union[str, List[str]]) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    pipeline: Union[UUID, str],
) -> None
remove_tags(
    *, tags: Union[str, List[str]], run: Union[UUID, str]
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    run_template: Union[UUID, str],
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    snapshot: Union[UUID, str],
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    deployment: Union[UUID, str],
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    artifact: Union[UUID, str],
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    artifact_version_id: UUID,
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    artifact_name: str,
    artifact_version: str,
) -> None
remove_tags(
    *,
    tags: Union[str, List[str]],
    infer_artifact: bool = False,
    artifact_name: Optional[str] = None,
) -> None

Remove tags from various resource types in a generalized way.

Parameters:

Name Type Description Default
tags Union[str, List[str]]

The tags to remove.

required
pipeline Optional[Union[UUID, str]]

The ID or the name of the pipeline.

None
run Optional[Union[UUID, str]]

The id, name or prefix of the run.

None
run_template Optional[Union[UUID, str]]

The ID or the name of the run template.

None
snapshot Optional[Union[UUID, str]]

The ID of the snapshot.

None
deployment Optional[Union[UUID, str]]

The ID or the name of the deployment.

None
artifact Optional[Union[UUID, str]]

The ID or the name of the artifact.

None
artifact_version_id Optional[UUID]

The ID of the artifact version.

None
artifact_name Optional[str]

The name of the artifact.

None
artifact_version Optional[str]

The version of the artifact.

None
infer_artifact Optional[bool]

Flag deciding whether the artifact version should be inferred from the step context.

None

Raises:

Type Description
ValueError

If no identifiers are provided and the function is not called from within a step.

Source code in src/zenml/utils/tag_utils.py
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
704
705
706
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
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
def remove_tags(
    tags: Union[str, List[str]],
    # Pipelines
    pipeline: Optional[Union[UUID, str]] = None,
    # Runs
    run: Optional[Union[UUID, str]] = None,
    # Run Templates
    run_template: Optional[Union[UUID, str]] = None,
    # Snapshots
    snapshot: Optional[Union[UUID, str]] = None,
    # Deployments
    deployment: Optional[Union[UUID, str]] = None,
    # Artifacts
    artifact: Optional[Union[UUID, str]] = None,
    # Artifact Versions
    artifact_version_id: Optional[UUID] = None,
    artifact_name: Optional[str] = None,
    artifact_version: Optional[str] = None,
    infer_artifact: Optional[bool] = None,
) -> None:
    """Remove tags from various resource types in a generalized way.

    Args:
        tags: The tags to remove.
        pipeline: The ID or the name of the pipeline.
        run: The id, name or prefix of the run.
        run_template: The ID or the name of the run template.
        snapshot: The ID of the snapshot.
        deployment: The ID or the name of the deployment.
        artifact: The ID or the name of the artifact.
        artifact_version_id: The ID of the artifact version.
        artifact_name: The name of the artifact.
        artifact_version: The version of the artifact.
        infer_artifact: Flag deciding whether the artifact version should be
            inferred from the step context.

    Raises:
        ValueError: If no identifiers are provided and the function is not
            called from within a step.
    """
    from zenml.client import Client
    from zenml.models.v2.misc.tag import TagResource

    client = Client()
    resource_id = None
    resource_type = None

    if isinstance(tags, str):
        tags = [tags]

    # Remove tags from a pipeline
    if pipeline is not None and all(
        v is None
        for v in [
            run_template,
            snapshot,
            deployment,
            run,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        pipeline_model = client.get_pipeline(name_id_or_prefix=pipeline)
        resource_id = pipeline_model.id
        resource_type = TaggableResourceTypes.PIPELINE

    # Remove tags from a run template
    elif run_template is not None and all(
        v is None
        for v in [
            pipeline,
            snapshot,
            deployment,
            run,
            artifact,
            artifact_version_id,
            artifact_version,
            artifact_name,
            infer_artifact,
        ]
    ):
        run_template_model = client.get_run_template(
            name_id_or_prefix=run_template
        )
        resource_id = run_template_model.id
        resource_type = TaggableResourceTypes.RUN_TEMPLATE

    # Remove tags from a snapshot
    elif snapshot is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            deployment,
            run,
            artifact,
            artifact_version_id,
            artifact_version,
            artifact_name,
            infer_artifact,
        ]
    ):
        snapshot_model = client.get_snapshot(
            name_id_or_prefix=snapshot, allow_prefix_match=False
        )
        resource_id = snapshot_model.id
        resource_type = TaggableResourceTypes.PIPELINE_SNAPSHOT

    # Remove tags from a deployment
    elif deployment is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            run,
            artifact,
            artifact_version_id,
            artifact_version,
            artifact_name,
            infer_artifact,
        ]
    ):
        deployment_model = client.get_deployment(name_id_or_prefix=deployment)
        resource_id = deployment_model.id
        resource_type = TaggableResourceTypes.DEPLOYMENT

    # Remove tags from a run
    elif run is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        run_model = client.get_pipeline_run(name_id_or_prefix=run)
        resource_id = run_model.id
        resource_type = TaggableResourceTypes.PIPELINE_RUN

    # Remove tags from an artifact
    elif artifact is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            run,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        artifact_model = client.get_artifact(name_id_or_prefix=artifact)
        resource_id = artifact_model.id
        resource_type = TaggableResourceTypes.ARTIFACT

    # Remove tags from an artifact version by its ID
    elif artifact_version_id is not None and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            run,
            artifact,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        resource_id = artifact_version_id
        resource_type = TaggableResourceTypes.ARTIFACT_VERSION

    # Remove tags from an artifact version by its name and version
    elif (artifact_name is not None and artifact_version is not None) and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            run,
            artifact,
            artifact_version_id,
            infer_artifact,
        ]
    ):
        artifact_version_model = client.get_artifact_version(
            name_id_or_prefix=artifact_name, version=artifact_version
        )
        resource_id = artifact_version_model.id
        resource_type = TaggableResourceTypes.ARTIFACT_VERSION

    # Remove tags from an artifact version through the step context
    elif infer_artifact is True and all(
        v is None
        for v in [
            pipeline,
            run_template,
            snapshot,
            deployment,
            run,
            artifact,
            artifact_version_id,
            artifact_version,
        ]
    ):
        try:
            from zenml.steps.step_context import get_step_context

            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                "When you are using the `infer_artifact` option when you call "
                "`remove_tags`, it must be called inside a step with outputs."
                "Otherwise, you can provide a `artifact_version_id` or a "
                "combination of `artifact_name` and `artifact_version`."
            )

        step_output_names = list(step_context._outputs.keys())

        if artifact_name is not None:
            # If a name provided, ensure it is in the outputs
            if artifact_name not in step_output_names:
                raise ValueError(
                    f"The provided artifact name`{artifact_name}` does not "
                    f"exist in the step outputs: {step_output_names}."
                )
        else:
            # If no name provided, ensure there is only one output
            if len(step_output_names) > 1:
                raise ValueError(
                    "There is more than one output. If you would like to use "
                    "the `infer_artifact` option, you need to define an "
                    "`artifact_name`."
                )

            if len(step_output_names) == 0:
                raise ValueError("The step does not have any outputs.")

            artifact_name = step_output_names[0]

        step_context.remove_output_tags(
            tags=tags,
            output_name=artifact_name,
        )
        return

    # If every additional value is None, that means we are calling it bare bones
    # and this call needs to happen during a step execution. We will use the
    # step context to fetch the run and detach the tags accordingly.
    elif all(
        v is None
        for v in [
            pipeline,
            run,
            run_template,
            snapshot,
            deployment,
            artifact,
            artifact_version_id,
            artifact_name,
            artifact_version,
            infer_artifact,
        ]
    ):
        try:
            from zenml.steps.step_context import get_step_context

            step_context = get_step_context()
        except RuntimeError:
            raise ValueError(
                f"""
                You are calling 'remove_tags()' outside of a step execution. 
                If you would like to remove tags from a ZenML entity outside 
                of the step execution, please provide the required 
                identifiers. \n{remove_tags_warning}
                """
            )

        # Tag the pipeline run, not the step
        resource_id = step_context.pipeline_run.id
        resource_type = TaggableResourceTypes.PIPELINE_RUN

    else:
        raise ValueError(
            f"""
            Unsupported way to call the `remove_tags`. Possible combinations "
            include: \n{remove_tags_warning}
            """
        )

    # Remove tags from resource
    for tag_name in tags:
        try:
            # Get the tag
            tag = client.get_tag(tag_name, allow_name_prefix_match=False)

            # Detach tag from resources
            client.detach_tag(
                tag_name_or_id=tag.id,
                resources=[TagResource(id=resource_id, type=resource_type)],
            )

        except KeyError:
            # Tag doesn't exist, nothing to remove
            pass
save_artifact(data: Any, name: str, version: Optional[Union[int, str]] = None, artifact_type: Optional[ArtifactType] = None, tags: Optional[List[str]] = None, extract_metadata: bool = True, include_visualizations: bool = True, user_metadata: Optional[Dict[str, MetadataType]] = None, materializer: Optional[MaterializerClassOrSource] = None, uri: Optional[str] = None, save_type: ArtifactSaveType = ArtifactSaveType.MANUAL, has_custom_name: bool = True) -> ArtifactVersionResponse

Upload and publish an artifact.

Parameters:

Name Type Description Default
name str

The name of the artifact.

required
data Any

The artifact data.

required
version Optional[Union[int, str]]

The version of the artifact. If not provided, a new auto-incremented version will be used.

None
tags Optional[List[str]]

Tags to associate with the artifact.

None
artifact_type Optional[ArtifactType]

The artifact type. If not given, the type will be defined by the materializer that is used to save the artifact.

None
extract_metadata bool

If artifact metadata should be extracted and returned.

True
include_visualizations bool

If artifact visualizations should be generated.

True
user_metadata Optional[Dict[str, MetadataType]]

User-provided metadata to store with the artifact.

None
materializer Optional[MaterializerClassOrSource]

The materializer to use for saving the artifact to the artifact store.

None
uri Optional[str]

The URI within the artifact store to upload the artifact to. If not provided, the artifact will be uploaded to custom_artifacts/{name}/{version}.

None
save_type ArtifactSaveType

The type of save operation that created the artifact version.

MANUAL
has_custom_name bool

If the artifact name is custom and should be listed in the dashboard "Artifacts" tab.

True

Returns:

Type Description
ArtifactVersionResponse

The saved artifact response.

Source code in src/zenml/artifacts/utils.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
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
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
def save_artifact(
    data: Any,
    name: str,
    version: Optional[Union[int, str]] = None,
    artifact_type: Optional[ArtifactType] = None,
    tags: Optional[List[str]] = None,
    extract_metadata: bool = True,
    include_visualizations: bool = True,
    user_metadata: Optional[Dict[str, "MetadataType"]] = None,
    materializer: Optional["MaterializerClassOrSource"] = None,
    uri: Optional[str] = None,
    # TODO: remove these once external artifact does not use this function anymore
    save_type: ArtifactSaveType = ArtifactSaveType.MANUAL,
    has_custom_name: bool = True,
) -> "ArtifactVersionResponse":
    """Upload and publish an artifact.

    Args:
        name: The name of the artifact.
        data: The artifact data.
        version: The version of the artifact. If not provided, a new
            auto-incremented version will be used.
        tags: Tags to associate with the artifact.
        artifact_type: The artifact type. If not given, the type will be defined
            by the materializer that is used to save the artifact.
        extract_metadata: If artifact metadata should be extracted and returned.
        include_visualizations: If artifact visualizations should be generated.
        user_metadata: User-provided metadata to store with the artifact.
        materializer: The materializer to use for saving the artifact to the
            artifact store.
        uri: The URI within the artifact store to upload the artifact
            to. If not provided, the artifact will be uploaded to
            `custom_artifacts/{name}/{version}`.
        save_type: The type of save operation that created the artifact version.
        has_custom_name: If the artifact name is custom and should be listed in
            the dashboard "Artifacts" tab.

    Returns:
        The saved artifact response.
    """
    from zenml.materializers.materializer_registry import (
        materializer_registry,
    )
    from zenml.utils import source_utils

    client = Client()
    artifact_store = client.active_stack.artifact_store

    if not uri:
        uri = os.path.join("custom_artifacts", name, str(uuid4()))
    if not uri.startswith(artifact_store.path):
        uri = os.path.join(artifact_store.path, uri)

    if save_type == ArtifactSaveType.MANUAL:
        # This check is only necessary for manual saves as we already check
        # it when creating the directory for step output artifacts
        _check_if_artifact_with_given_uri_already_registered(
            artifact_store=artifact_store,
            uri=uri,
            name=name,
        )

    if isinstance(materializer, type):
        materializer_class = materializer
    elif materializer:
        materializer_class = source_utils.load_and_validate_class(
            materializer, expected_class=BaseMaterializer
        )
    else:
        materializer_class = materializer_registry[type(data)]

    artifact_version_request = _store_artifact_data_and_prepare_request(
        data=data,
        name=name,
        uri=uri,
        materializer_class=materializer_class,
        save_type=save_type,
        version=version,
        artifact_type=artifact_type,
        tags=tags,
        store_metadata=extract_metadata,
        store_visualizations=include_visualizations,
        has_custom_name=has_custom_name,
        metadata=user_metadata,
    )
    artifact_version = client.zen_store.create_artifact_version(
        artifact_version=artifact_version_request
    )

    if save_type == ArtifactSaveType.MANUAL:
        _link_artifact_version_to_the_step_and_model(
            artifact_version=artifact_version,
        )

    return artifact_version
show(local: bool = False, ngrok_token: Optional[str] = None) -> None

Show the ZenML dashboard.

Parameters:

Name Type Description Default
local bool

Whether to show the dashboard for the local server or the one for the active server.

False
ngrok_token Optional[str]

An ngrok auth token to use for exposing the ZenML dashboard on a public domain. Primarily used for accessing the dashboard in Colab.

None

Raises:

Type Description
RuntimeError

If no server is connected.

Source code in src/zenml/utils/dashboard_utils.py
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
def show_dashboard(
    local: bool = False,
    ngrok_token: Optional[str] = None,
) -> None:
    """Show the ZenML dashboard.

    Args:
        local: Whether to show the dashboard for the local server or the
            one for the active server.
        ngrok_token: An ngrok auth token to use for exposing the ZenML
            dashboard on a public domain. Primarily used for accessing the
            dashboard in Colab.

    Raises:
        RuntimeError: If no server is connected.
    """
    from zenml.utils.networking_utils import get_or_create_ngrok_tunnel

    url: Optional[str] = None
    if not local:
        gc = GlobalConfiguration()
        if gc.store_configuration.type == StoreType.REST:
            url = gc.store_configuration.url

    if not url:
        # Else, check for local servers
        server = get_local_server()
        if server and server.status and server.status.url:
            url = server.status.url

    if not url:
        raise RuntimeError(
            "ZenML is not connected to any server right now. Please use "
            "`zenml login` to connect to a server or spin up a new local server "
            "via `zenml login --local`."
        )

    if ngrok_token:
        parsed_url = urlparse(url)

        ngrok_url = get_or_create_ngrok_tunnel(
            ngrok_token=ngrok_token, port=parsed_url.port or 80
        )
        logger.debug(f"Tunneling dashboard from {url} to {ngrok_url}.")
        url = ngrok_url

    show_dashboard_with_url(url)
step(_func: Optional[F] = None, *, name: Optional[str] = None, enable_cache: Optional[bool] = None, enable_artifact_metadata: Optional[bool] = None, enable_artifact_visualization: Optional[bool] = None, enable_step_logs: Optional[bool] = None, experiment_tracker: Optional[Union[bool, str]] = None, step_operator: Optional[Union[bool, str]] = None, output_materializers: Optional[OutputMaterializersSpecification] = None, environment: Optional[Dict[str, Any]] = None, secrets: Optional[List[Union[UUID, str]]] = None, settings: Optional[Dict[str, SettingsOrDict]] = None, extra: Optional[Dict[str, Any]] = None, on_failure: Optional[HookSpecification] = None, on_success: Optional[HookSpecification] = None, model: Optional[Model] = None, retry: Optional[StepRetryConfig] = None, substitutions: Optional[Dict[str, str]] = None, cache_policy: Optional[CachePolicyOrString] = None, runtime: Optional[StepRuntime] = None, heartbeat_healthy_threshold: Optional[int] = None, group: Optional[Union[GroupInfo, str]] = None) -> Union[BaseStep, Callable[[F], BaseStep]]
step(_func: F) -> BaseStep
step(
    *,
    name: Optional[str] = None,
    enable_cache: Optional[bool] = None,
    enable_artifact_metadata: Optional[bool] = None,
    enable_artifact_visualization: Optional[bool] = None,
    enable_step_logs: Optional[bool] = None,
    experiment_tracker: Optional[Union[bool, str]] = None,
    step_operator: Optional[Union[bool, str]] = None,
    output_materializers: Optional[
        OutputMaterializersSpecification
    ] = None,
    environment: Optional[Dict[str, Any]] = None,
    secrets: Optional[List[Union[UUID, str]]] = None,
    settings: Optional[Dict[str, SettingsOrDict]] = None,
    extra: Optional[Dict[str, Any]] = None,
    on_failure: Optional[HookSpecification] = None,
    on_success: Optional[HookSpecification] = None,
    model: Optional[Model] = None,
    retry: Optional[StepRetryConfig] = None,
    substitutions: Optional[Dict[str, str]] = None,
    cache_policy: Optional[CachePolicyOrString] = None,
    runtime: Optional[StepRuntime] = None,
    heartbeat_healthy_threshold: Optional[int] = None,
    group: Optional[Union[GroupInfo, str]] = None,
) -> Callable[[F], BaseStep]

Decorator to create a ZenML step.

Parameters:

Name Type Description Default
_func Optional[F]

The decorated function.

None
name Optional[str]

The name of the step. If left empty, the name of the decorated function will be used as a fallback.

None
enable_cache Optional[bool]

Specify whether caching is enabled for this step. If no value is passed, caching is enabled by default.

None
enable_artifact_metadata Optional[bool]

Specify whether metadata is enabled for this step. If no value is passed, metadata is enabled by default.

None
enable_artifact_visualization Optional[bool]

Specify whether visualization is enabled for this step. If no value is passed, visualization is enabled by default.

None
enable_step_logs Optional[bool]

Specify whether step logs are enabled for this step.

None
experiment_tracker Optional[Union[bool, str]]

The experiment tracker to use for this step.

None
step_operator Optional[Union[bool, str]]

The step operator to use for this step.

None
output_materializers Optional[OutputMaterializersSpecification]

Output materializers for this step. If given as a dict, the keys must be a subset of the output names of this step. If a single value (type or string) is given, the materializer will be used for all outputs.

None
environment Optional[Dict[str, Any]]

Environment variables to set when running this step.

None
secrets Optional[List[Union[UUID, str]]]

Secrets to set as environment variables when running this step.

None
settings Optional[Dict[str, SettingsOrDict]]

Settings for this step.

None
extra Optional[Dict[str, Any]]

Extra configurations for this step.

None
on_failure Optional[HookSpecification]

Callback function in event of failure of the step. Can be a function with a single argument of type BaseException, or a source path to such a function (e.g. module.my_function).

None
on_success Optional[HookSpecification]

Callback function in event of success of the step. Can be a function with no arguments, or a source path to such a function (e.g. module.my_function).

None
model Optional[Model]

configuration of the model in the Model Control Plane.

None
retry Optional[StepRetryConfig]

configuration of step retry in case of step failure.

None
substitutions Optional[Dict[str, str]]

Extra substitutions for model and artifact name placeholders.

None
cache_policy Optional[CachePolicyOrString]

Cache policy for this step.

None
runtime Optional[StepRuntime]

The step runtime. If not configured, the step will run inline unless a step operator or docker/resource settings are configured. This is only applicable for dynamic pipelines.

None
heartbeat_healthy_threshold Optional[int]

The amount of time (in minutes) that a running step has not received heartbeat and is considered healthy. By default, set to 30 minutes.

None
group Optional[Union[GroupInfo, str]]

The group information for this step.

None

Returns:

Type Description
Union[BaseStep, Callable[[F], BaseStep]]

The step instance.

Source code in src/zenml/steps/step_decorator.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
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 step(
    _func: Optional["F"] = None,
    *,
    name: Optional[str] = None,
    enable_cache: Optional[bool] = None,
    enable_artifact_metadata: Optional[bool] = None,
    enable_artifact_visualization: Optional[bool] = None,
    enable_step_logs: Optional[bool] = None,
    experiment_tracker: Optional[Union[bool, str]] = None,
    step_operator: Optional[Union[bool, str]] = None,
    output_materializers: Optional["OutputMaterializersSpecification"] = None,
    environment: Optional[Dict[str, Any]] = None,
    secrets: Optional[List[Union[UUID, str]]] = None,
    settings: Optional[Dict[str, "SettingsOrDict"]] = None,
    extra: Optional[Dict[str, Any]] = None,
    on_failure: Optional["HookSpecification"] = None,
    on_success: Optional["HookSpecification"] = None,
    model: Optional["Model"] = None,
    retry: Optional["StepRetryConfig"] = None,
    substitutions: Optional[Dict[str, str]] = None,
    cache_policy: Optional["CachePolicyOrString"] = None,
    runtime: Optional[StepRuntime] = None,
    heartbeat_healthy_threshold: Optional[int] = None,
    group: Optional[Union["GroupInfo", str]] = None,
) -> Union["BaseStep", Callable[["F"], "BaseStep"]]:
    """Decorator to create a ZenML step.

    Args:
        _func: The decorated function.
        name: The name of the step. If left empty, the name of the decorated
            function will be used as a fallback.
        enable_cache: Specify whether caching is enabled for this step. If no
            value is passed, caching is enabled by default.
        enable_artifact_metadata: Specify whether metadata is enabled for this
            step. If no value is passed, metadata is enabled by default.
        enable_artifact_visualization: Specify whether visualization is enabled
            for this step. If no value is passed, visualization is enabled by
            default.
        enable_step_logs: Specify whether step logs are enabled for this step.
        experiment_tracker: The experiment tracker to use for this step.
        step_operator: The step operator to use for this step.
        output_materializers: Output materializers for this step. If
            given as a dict, the keys must be a subset of the output names
            of this step. If a single value (type or string) is given, the
            materializer will be used for all outputs.
        environment: Environment variables to set when running this step.
        secrets: Secrets to set as environment variables when running this step.
        settings: Settings for this step.
        extra: Extra configurations for this step.
        on_failure: Callback function in event of failure of the step. Can be a
            function with a single argument of type `BaseException`, or a source
            path to such a function (e.g. `module.my_function`).
        on_success: Callback function in event of success of the step. Can be a
            function with no arguments, or a source path to such a function
            (e.g. `module.my_function`).
        model: configuration of the model in the Model Control Plane.
        retry: configuration of step retry in case of step failure.
        substitutions: Extra substitutions for model and artifact name
            placeholders.
        cache_policy: Cache policy for this step.
        runtime: The step runtime. If not configured, the step will
            run inline unless a step operator or docker/resource settings
            are configured. This is only applicable for dynamic
            pipelines.
        heartbeat_healthy_threshold: The amount of time (in minutes) that a
            running step has not received heartbeat and is considered healthy.
            By default, set to 30 minutes.
        group: The group information for this step.

    Returns:
        The step instance.
    """

    def inner_decorator(func: "F") -> "BaseStep":
        from zenml.steps.decorated_step import _DecoratedStep

        class_: Type["BaseStep"] = type(
            func.__name__,
            (_DecoratedStep,),
            {
                "entrypoint": staticmethod(func),
                "__module__": func.__module__,
                "__doc__": func.__doc__,
            },
        )

        step_instance = class_(
            name=name or func.__name__,
            enable_cache=enable_cache,
            enable_artifact_metadata=enable_artifact_metadata,
            enable_artifact_visualization=enable_artifact_visualization,
            enable_step_logs=enable_step_logs,
            experiment_tracker=experiment_tracker,
            step_operator=step_operator,
            output_materializers=output_materializers,
            environment=environment,
            secrets=secrets,
            settings=settings,
            extra=extra,
            on_failure=on_failure,
            on_success=on_success,
            model=model,
            retry=retry,
            substitutions=substitutions,
            cache_policy=cache_policy,
            runtime=runtime,
            heartbeat_healthy_threshold=heartbeat_healthy_threshold,
            group=group,
        )

        return step_instance

    if _func is None:
        return inner_decorator
    else:
        return inner_decorator(_func)
unmapped(value: T) -> _Unmapped[T]

Helper function to pass an input without mapping over it.

Wrap any step input with this function and then pass it to step.map(...) to pass the full value to all steps.

Parameters:

Name Type Description Default
value T

The value to wrap.

required

Returns:

Type Description
_Unmapped[T]

The wrapped value.

Source code in src/zenml/execution/pipeline/dynamic/utils.py
46
47
48
49
50
51
52
53
54
55
56
57
58
def unmapped(value: T) -> _Unmapped[T]:
    """Helper function to pass an input without mapping over it.

    Wrap any step input with this function and then pass it to `step.map(...)`
    to pass the full value to all steps.

    Args:
        value: The value to wrap.

    Returns:
        The wrapped value.
    """
    return _Unmapped(value)
Modules