Sterling Baird
11/25/2025, 4:34 AMMarvin
11/25/2025, 4:34 AMNate
11/25/2025, 4:36 AMpersist_result=True on the flow you trigger. run_deployment(...).state.result() from the place you trigger to retrieve the actual valueMarvin
11/25/2025, 4:37 AMfrom prefect import flow
@flow(name="echo", persist_result=True)
def echo(msg: str) -> str:
return msg
- Trigger the deployment and fetch the result:
from prefect.deployments import run_deployment
flow_run = run_deployment(
name="echo/prod", # "<flow name>/<deployment name>"
parameters={"msg": "hi"},
timeout=None # wait until the run finishes
)
value = flow_run.state.result() # -> "hi"
print(value)
2) If you only have a flow_run_id later
from prefect.client.orchestration import get_client
client = get_client(sync_client=True)
flow_run = client.read_flow_run(flow_run_id)
value = flow_run.state.result() # -> your string
Notes:
- If you don’t enable persist_result=True (or set PREFECT_RESULTS_PERSIST_BY_DEFAULT=true), calling .result() on a state from another process will raise a “missing result” style error because the value was never written to result storage.
- If you’d prefer something UI-visible or JSON-only, consider emitting an artifact (e.g., a string or markdown artifact) from your flow and reading it via the API.
If you can share how you’re triggering the deployment (Python run_deployment, CLI/UI, or an automation) and whether you can modify the flow code, I can tailor the exact snippet for your setup.Nate
11/25/2025, 4:42 AMSterling Baird
11/25/2025, 4:45 AMMarvin
11/25/2025, 4:45 AMMarvin
11/25/2025, 4:47 AMstate.result() to work across devices. S3 (or similar, like GCS/Azure Blob) is the most common choice.
Details and options:
- Object storage (recommended): S3, GCS, Azure Blob via their Prefect blocks. Both machines just need outbound access to that service. Configure your flow with persist_result=True and a result_storage block.
- Other remote filesystems: Prefect’s RemoteFileSystem and SMB blocks can work if both devices can reach the endpoint (e.g., SFTP/WebDAV/SMB share), but that still requires a reachable network path.
- Local filesystems only work if the reader and writer are the same machine (or truly shared FS); otherwise, state.result() won’t be able to fetch the value.
Lightweight alternative for strings:
- If you only need to pass back a small string or JSON, you can emit an artifact (e.g., markdown or table). Artifacts are stored in the Prefect API (Cloud/Server), so no external storage is needed as long as both devices can reach the Prefect API. This avoids S3 entirely for small textual results.
Example with S3:
from prefect import flow
from prefect_aws.s3 import S3Bucket
# one-time setup
s3 = S3Bucket(bucket_name="my-results-bucket", basepath="prefect-results/")
s3.save("results-s3", overwrite=True)
@flow(persist_result=True, result_storage="s3-bucket/results-s3")
def echo(msg: str) -> str:
return msg
Then when you trigger the deployment from another machine and call flow_run.state.result(), Prefect will use the saved block to fetch from S3. You only need a Prefect API key to read the block config; you don’t need to hardcode AWS creds in the caller.
Artifact alternative (for small strings):
from prefect import flow
from prefect.artifacts import create_markdown_artifact
@flow
def echo(msg: str):
create_markdown_artifact(
key="echo-output",
markdown=f"Result: {msg}",
description="Echo result"
)
You can later read this artifact via the Prefect API without configuring external storage.
If you want, tell me which storage you prefer (S3, GCS, Azure, SFTP/SMB), and I’ll share a drop-in config snippet for your setup.