<@ULVA73B9P> From a given flow run, can I retrieve...
# ask-marvin
t
@Marvin From a given flow run, can I retrieve an artifact created by another flow run? I see that you can set a key for an artifact and retrieve the artifact based on this, but I don't know if it is set on a per-flow run basis.
m
thought for 183.3 seconds
Short answer: yes. In Prefect 3.x, artifact keys are workspace-scoped, not per-flow-run. Any flow run can retrieve an artifact created by another flow run as long as they share the same workspace and you know the artifact’s key. What to know: - Keys are global within a workspace. They are not scoped to a flow, deployment, or run. - Creating a new artifact with an existing key creates a new version; it does not overwrite previous versions (except progress artifacts, which update in place). - Retrieving by key returns the latest version for that key. Example: create in one flow run, read in another
Copy code
from prefect.artifacts import create_markdown_artifact, Artifact

# Flow A: create or update an artifact
create_markdown_artifact(
    markdown="# Daily summary\nAll systems go.",
    key="reports/daily-summary",
    description="Daily ops report"
)

# Flow B (or any other run): read the latest artifact by key
artifact = Artifact.get(key="reports/daily-summary")
if artifact:
    print("Artifact type:", artifact.type)
    print("Updated:", artifact.updated)
    print("Data:", artifact.data)  # for markdown, this is the markdown string
else:
    print("No artifact found for that key")
CLI to inspect versions
Copy code
prefect artifact inspect "reports/daily-summary"
If you need a specific run’s artifact (not just the latest): - Easiest pattern: encode the run identifier (or a timestamp) into the key when writing, then read that exact key later. - Alternatively, you can query artifacts by
flow_run_id
via the REST API or the Python client filters. Docs and references: - Concepts: Artifacts concepts - How-to: Artifacts how-to - Python API: prefect.artifacts API - CLI reference: prefect artifact CLI