<@ULVA73B9P> how to best create an artifact for zi...
# ask-marvin
s
@Marvin how to best create an artifact for zip file in prefect?
m
thought for 67.3 seconds
Great question. In Prefect 3.x, artifacts are meant for human-friendly outputs (links, markdown, tables, images, progress), not for storing raw binaries. The best pattern for a ZIP is: 1) Put the ZIP file somewhere accessible (e.g., S3, GCS, Azure Blob, or a web server) 2) Create a link artifact that points to it so it shows up in the Prefect UI Key API:
prefect.artifacts.create_link_artifact
Example: create a ZIP, upload to S3, and attach a link artifact (with a presigned URL)
Copy code
from prefect import flow
from prefect.artifacts import create_link_artifact
import boto3
import tempfile
import zipfile
from pathlib import Path

@flow
def make_and_link_zip():
    # 1) Create a ZIP file
    tmp_dir = tempfile.TemporaryDirectory()
    zip_path = Path(tmp_dir.name) / "output.zip"
    with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zf:
        # add some example content
        content_path = Path(tmp_dir.name) / "data.txt"
        content_path.write_text("hello from prefect")
        zf.write(content_path, arcname="data.txt")

    # 2) Upload the ZIP to S3
    bucket = "my-bucket"
    key = f"artifacts/{zip_path.name}"
    s3 = boto3.client("s3")
    s3.upload_file(str(zip_path), bucket, key)

    # 3) Create a presigned URL (optional if your object is public)
    presigned_url = s3.generate_presigned_url(
        "get_object",
        Params={"Bucket": bucket, "Key": key},
        ExpiresIn=7 * 24 * 3600,  # 7 days
    )

    # 4) Create a link artifact so it’s visible in the Prefect UI
    create_link_artifact(
        link=presigned_url,
        link_text="Download output.zip",
        description="ZIP produced by this flow run",
    )

if __name__ == "__main__":
    make_and_link_zip()
Notes and options - If your file is publicly accessible (e.g., via a public S3 object, CloudFront, or a web server), you can link directly to the permanent URL instead of a presigned URL. - You can also use
create_markdown_artifact
to include more context and a clickable link in one artifact. - For async flows, use
acreate_link_artifact
. - There is no “file/binary artifact” type—artifacts are not for uploading the ZIP itself. Docs - Artifacts overview: Artifacts in Prefect 3.x If you can share where you plan to store the ZIP (S3, GCS, Azure, or elsewhere), I can tailor the upload snippet for that storage.