# Flow Run

# FlowRunView



(flow_run_id, name, flow_id, labels, parameters, context, state, states, updated_at, run_config, task_runs=None)[source]

A view of Flow Run data stored in the Prefect API.

Provides lazy loading of Task Runs from the flow run.

This object is designed to be an immutable view of the data stored in the Prefect backend API at the time it is created. However, each time a task run is retrieved the latest data for that task will be pulled since they are loaded lazily. Finished task runs will be cached in this object to reduce the amount of network IO.


  • flow_run_id: The uuid of the flow run
  • name: The name of the flow run
  • flow_id: The uuid of the flow this run is associated with
  • state: The state of the flow run
  • labels: The labels assigned to this flow run
  • parameters: Parameter overrides for this flow run
  • context: Context overrides for this flow run
  • updated_at: When this flow run was last updated in the backend
  • run_config: The RunConfig this flow run was configured with
  • states: A sorted list of past states the flow run has been in
  • task_runs: An iterable of task run metadata to cache in this view



(flow_run_id, load_static_tasks=False, _cached_task_runs=None)[source]

Get an instance of this class filled with information by querying for the given flow run id


  • flow_run_id: the flow run id to lookup
  • load_static_tasks: Pre-populate the task runs with results from flow tasks that are unmapped.
  • _cached_task_runs: Pre-populate the task runs with an existing iterable of task runs
Returns: A populated FlowRunView instance



Get all task runs for this flow run in a single query. Finished task run data is cached so future lookups do not query the backend.

Returns: A list of TaskRunView objects



Flow metadata for the flow associated with this flow run. Retrieved from the API on first call then cached for future calls.


  • no_cache: If set, the cached FlowView will be ignored and the latest data for the flow will be pulled.
Returns: FlowView: A view of the Flow metadata for the Flow this run is from



Get the a new copy of this object with the latest data from the API. Cached TaskRunView objects will be passed to the new object. Only finished tasks are cached so the cached data cannot be stale.

This will not mutate the current object.


  • load_static_tasks: Pre-populate the task runs with results from flow tasks that are unmapped. Defaults to False because it may be wasteful to query for task run data when cached tasks are already copied over from the old object.
Returns: A new instance of FlowRunView


(start_time=None, end_time=None)[source]

Get logs for this flow run from start_time to end_time.


  • start_time (optional): A time to start the log query at, useful for limiting the scope. If not provided, all logs up to updated_at are retrieved.
  • end_time (optional): A time to end the log query at. By default, this is set to self.updated_at which is the last time that the flow run was updated in the backend before this object was created.
Returns: A list of FlowRunLog objects sorted by timestamp


(task_slug=None, task_run_id=None, map_index=None)[source]

Get information about a task run from this flow run. Lookup is available by one of the arguments. If the task information is not available locally already, we will query the database for it. If multiple arguments are provided, we will validate that they are consistent with each other.

All retrieved task runs that are finished will be cached to avoid re-querying in repeated calls


  • task_slug: A task slug string to use for the lookup
  • task_run_id: A task run uuid to use for the lookup
  • map_index: If given a slug of a mapped task, an index may be provided to get the the task run for that child task instead of the parent. This value will only be used for a consistency check if passed with a task_run_id
Returns: A cached or newly constructed TaskRunView instance



Get all task run ids associated with this flow run. Lazily loaded at call time then cached for future calls.

Returns: A list of string task run ids

# Functions

top-level functions:                                                                                                                                                       


(flow_run_id, stream_states=True, stream_logs=True, max_duration=datetime.timedelta(seconds=43200))[source]

Watch execution of a flow run displaying state changes. This function will yield FlowRunLog objects until the flow run enters a 'Finished' state.

If both stream_states and stream_logs are False then this will just block until the flow run finishes.


  • flow_run_id: The flow run to watch
  • stream_states: If set, flow run state changes will be streamed as logs
  • stream_logs: If set, logs will be streamed from the flow run
  • max_duration: Duration to wait for flow run to complete. Defaults to 12 hours
Yields: FlowRunLog: Sorted log entriesRaises:
  • RuntimeError: if flow runtime exceeds max_duration

This documentation was auto-generated from commit ffa9a6c
on February 1, 2023 at 18:44 UTC