<@ULVA73B9P> is it possible to send prefect artifa...
# ask-marvin
a
@Marvin is it possible to send prefect artifacts to snowflake?
m
thought for 146.8 seconds
Yes — but not natively. Prefect artifacts can be mirrored to Snowflake, but Prefect does not have a built-in “artifact sink” or automatic export to Snowflake. In Prefect 3.x, artifacts are mainly for UI/observability in Prefect Cloud/server. What this means in practice - Create the artifact in Prefect - Then, in the same flow/task, write the same data to Snowflake yourself - Or fetch the artifact later via the Prefect client/API and load it into Snowflake Recommended pattern If you already have data you want both: - visible in Prefect UI, and - stored in Snowflake …then the best approach is usually to write both at the same time instead of treating Prefect artifacts as the primary storage layer. Example shape:
Copy code
from prefect import flow, task
from prefect.artifacts import create_table_artifact
from prefect_snowflake import SnowflakeConnector
import json

@task
def write_to_snowflake(rows, connector_block_name):
    with SnowflakeConnector.load(connector_block_name) as conn:
        conn.execute("""
            CREATE TABLE IF NOT EXISTS prefect_artifacts_export (
                artifact_key STRING,
                artifact_type STRING,
                artifact_data VARIANT
            )
        """)
        conn.execute(
            """
            INSERT INTO prefect_artifacts_export
            (artifact_key, artifact_type, artifact_data)
            VALUES (?, ?, ?)
            """,
            parameters=(
                "sales-summary",
                "table",
                json.dumps(rows),
            ),
        )

@flow
def my_flow():
    rows = [
        {"region": "NA", "revenue": 100},
        {"region": "EU", "revenue": 200},
    ]

    create_table_artifact(
        key="sales-summary",
        table=rows,
        description="Sales summary"
    )

    write_to_snowflake(rows, "my-snowflake-connector")
Useful links - Artifacts concept: Prefect artifacts - Creating artifacts: How to create artifacts - Artifacts REST API: Artifacts API - Snowflake integration: prefect-snowflake Short answer - Possible? Yes - Built-in? No - Best practice? Treat artifacts as UI metadata, and write the same underlying data to Snowflake directly If you want, I can give you: 1. a full Prefect 3 example using
prefect-snowflake
, or 2. an example that reads existing artifacts from Prefect and bulk-loads them into Snowflake.