Skip to content

prefect.artifacts

Interface for creating and reading artifacts.

Create a link artifact.

Parameters:

Name Type Description Default
- link

The link to create.

required

Returns:

Type Description
UUID
  • The table artifact ID.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/artifacts.py
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
@sync_compatible
async def create_link_artifact(
    link: str,
    link_text: Optional[str] = None,
    key: Optional[str] = None,
    description: Optional[str] = None,
) -> UUID:
    """
    Create a link artifact.

    Args:
        - link: The link to create.

    Returns:
        - The table artifact ID.
    """
    formatted_link = f"[{link_text}]({link})" if link_text else f"[{link}]({link})"
    artifact = await _create_artifact(
        key=key,
        type="markdown",
        description=description,
        data=formatted_link,
    )

    return artifact.id

create_markdown_artifact async

Create a markdown artifact.

Parameters:

Name Type Description Default
- markdown

The markdown to create.

required

Returns:

Type Description
UUID
  • The table artifact ID.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/artifacts.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@sync_compatible
async def create_markdown_artifact(
    markdown: str,
    key: Optional[str] = None,
    description: Optional[str] = None,
) -> UUID:
    """
    Create a markdown artifact.

    Args:
        - markdown: The markdown to create.

    Returns:
        - The table artifact ID.
    """
    artifact = await _create_artifact(
        key=key,
        type="markdown",
        description=description,
        data=markdown,
    )

    return artifact.id

create_table_artifact async

Create a table artifact.

Parameters:

Name Type Description Default
- table

The table to create.

required

Returns:

Type Description
UUID
  • The table artifact ID.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/artifacts.py
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
@sync_compatible
async def create_table_artifact(
    table: Union[Dict[str, List[Any]], List[Dict[str, Any]]],
    key: Optional[str] = None,
    description: Optional[str] = None,
) -> UUID:
    """
    Create a table artifact.

    Args:
        - table: The table to create.

    Returns:
        - The table artifact ID.
    """

    def _sanitize_nan_values(container):
        if isinstance(container, list):
            for i, val in enumerate(container):
                if isinstance(val, float) and math.isnan(val):
                    container[i] = None
        elif isinstance(container, dict):
            for k, v in container.items():
                if isinstance(v, float) and math.isnan(v):
                    container[k] = None

    if isinstance(table, dict):
        for _, row in table.items():
            if not isinstance(row, list):
                raise TypeError(INVALID_TABLE_TYPE_ERROR)
            _sanitize_nan_values(row)
    elif isinstance(table, list):
        for row in table:
            if not isinstance(row, dict):
                raise TypeError(INVALID_TABLE_TYPE_ERROR)
            _sanitize_nan_values(row)
    else:
        raise TypeError(INVALID_TABLE_TYPE_ERROR)

    formatted_table = json.dumps(table)

    artifact = await _create_artifact(
        key=key,
        type="table",
        description=description,
        data=formatted_table,
    )

    return artifact.id