Martijn Sanderse
09/04/2025, 10:09 AMfrom prefect.deployments import run_deployment
from prefect.client.schemas.objects import State
from prefect.client.orchestration import get_client
import dotenv
dotenv.load_dotenv() # loads prefect api url from .env
if __name__ == "__main__":
state: State = run_deployment(_name_="hello_flow/hello_deploy", _parameters_={"name": "Masa"})
print("result", type(state), type(state.state))
print ("state", state)
How do I get what is returned by the flow?Marvin
09/04/2025, 10:10 AMMarvin
09/04/2025, 10:12 AMrun_deployment(...)
returns a FlowRun
object (not a State
). To get the Python value your flow returned, resolve the final state’s result.
Example:
from prefect.deployments import run_deployment
from prefect.states import get_state_result
if __name__ == "__main__":
flow_run = run_deployment(
name="hello_flow/hello_deploy",
parameters={"name": "Masa"},
)
print("final state:", flow_run.state.type, flow_run.state.name)
result = get_state_result(flow_run.state) # raises if the run failed
print("flow result:", result)
Notes:
- If you want to avoid raising on failures, use get_state_result(flow_run.state, raise_on_failure=False)
and check flow_run.state.type
.
- Make sure your flow’s return value is serializable by your configured result serializer (JSON by default). If not, configure a different serializer.
Docs:
- run_deployment: API
- get_state_result: API
- Results overview: Concepts