lifecycle.api.GraphExecutionHookΒΆ

class hamilton.lifecycle.api.GraphExecutionHookΒΆ

Implement this to execute code before and after graph execution. This is useful for logging, etc…

final post_graph_execute(*, run_id: str, graph: FunctionGraph, success: bool, error: Exception | None, results: Dict[str, Any] | None)ΒΆ

Just delegates to the interface method, passing in the right data.

final pre_graph_execute(*, run_id: str, graph: FunctionGraph, final_vars: List[str], inputs: Dict[str, Any], overrides: Dict[str, Any])ΒΆ

Implementation of the pre_graph_execute hook. This just converts the inputs to the format the user-facing hook is expecting – performing a walk of the DAG to pass in the set of nodes to execute. Delegates to the interface method.

abstract run_after_graph_execution(*, graph: HamiltonGraph, success: bool, error: Exception | None, results: Dict[str, Any] | None, run_id: str, **future_kwargs: Any)ΒΆ

This is run after graph execution. This allows you to do anything you want after the graph executes, knowing the results of the execution/any errors.

Parameters:
  • graph – Graph that is being executed

  • results – Results of the graph execution

  • error – Error that occurred, None if no error occurred

  • success – Whether the graph executed successfully

  • run_id – Run ID (unique in process scope) of the current run. Use this to track state.

  • future_kwargs – Additional keyword arguments – this is kept for backwards compatibility

abstract run_before_graph_execution(*, graph: HamiltonGraph, final_vars: List[str], inputs: Dict[str, Any], overrides: Dict[str, Any], execution_path: Collection[str], run_id: str, **future_kwargs: Any)ΒΆ

This is run prior to graph execution. This allows you to do anything you want before the graph executes, knowing the basic information that was passed in.

Parameters:
  • graph – Graph that is being executed

  • final_vars – Output variables of the graph

  • inputs – Input variables passed to the graph

  • overrides – Overrides passed to the graph

  • execution_path – Collection of nodes that will be executed – these are just the nodes (not input nodes) that will be run during the course of execution.

  • run_id – Run ID (unique in process scope) of the current run. Use this to track state.

  • future_kwargs – Additional keyword arguments – this is kept for backwards compatibility