Skip to content

Types

zenml.types

Custom ZenML types.

Attributes

HookSpecification = Union[str, Source, FunctionType, Callable[..., None]] module-attribute

Classes

CSVString

Bases: str

Special string class to indicate a CSV string.

HTMLString

Bases: str

Special string class to indicate an HTML string.

JSONString

Bases: str

Special string class to indicate a JSON string.

MarkdownString

Bases: str

Special string class to indicate a Markdown string.

Source

Bases: BaseModel

Source specification.

A source specifies a module name as well as an optional attribute of that module. These values can be used to import the module and get the value of the attribute inside the module.

Example

The source Source(module="zenml.config.source", attribute="Source") references the class that this docstring is describing. This class is defined in the zenml.config.source module and the name of the attribute is the class name Source.

Attributes:

Name Type Description
module str

The module name.

attribute Optional[str]

Optional name of the attribute inside the module.

type SourceType

The type of the source.

Attributes
import_path: str property

The import path of the source.

Returns:

Type Description
str

The import path of the source.

is_internal: bool property

If the source is internal (=from the zenml package).

Returns:

Type Description
bool

True if the source is internal, False otherwise

is_module_source: bool property

If the source is a module source.

Returns:

Type Description
bool

If the source is a module source.

Functions
from_import_path(import_path: str, is_module_path: bool = False) -> Source classmethod

Creates a source from an import path.

Parameters:

Name Type Description Default
import_path str

The import path.

required
is_module_path bool

If the import path points to a module or not.

False

Raises:

Type Description
ValueError

If the import path is empty.

Returns:

Type Description
Source

The source.

Source code in src/zenml/config/source.py
 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
104
105
106
@classmethod
def from_import_path(
    cls, import_path: str, is_module_path: bool = False
) -> "Source":
    """Creates a source from an import path.

    Args:
        import_path: The import path.
        is_module_path: If the import path points to a module or not.

    Raises:
        ValueError: If the import path is empty.

    Returns:
        The source.
    """
    if not import_path:
        raise ValueError(
            "Invalid empty import path. The import path needs to refer "
            "to a Python module and an optional attribute of that module."
        )

    # Remove internal version pins for backwards compatibility
    if "@" in import_path:
        import_path = import_path.split("@", 1)[0]

    if is_module_path or "." not in import_path:
        module = import_path
        attribute = None
    else:
        module, attribute = import_path.rsplit(".", maxsplit=1)

    return Source(
        module=module, attribute=attribute, type=SourceType.UNKNOWN
    )
model_dump(**kwargs: Any) -> Dict[str, Any]

Dump the source as a dictionary.

Parameters:

Name Type Description Default
**kwargs Any

Additional keyword arguments.

{}

Returns:

Type Description
Dict[str, Any]

The source as a dictionary.

Source code in src/zenml/config/source.py
143
144
145
146
147
148
149
150
151
152
def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
    """Dump the source as a dictionary.

    Args:
        **kwargs: Additional keyword arguments.

    Returns:
        The source as a dictionary.
    """
    return super().model_dump(serialize_as_any=True, **kwargs)
model_dump_json(**kwargs: Any) -> str

Dump the source as a JSON string.

Parameters:

Name Type Description Default
**kwargs Any

Additional keyword arguments.

{}

Returns:

Type Description
str

The source as a JSON string.

Source code in src/zenml/config/source.py
154
155
156
157
158
159
160
161
162
163
def model_dump_json(self, **kwargs: Any) -> str:
    """Dump the source as a JSON string.

    Args:
        **kwargs: Additional keyword arguments.

    Returns:
        The source as a JSON string.
    """
    return super().model_dump_json(serialize_as_any=True, **kwargs)