AsyncDriver

Use this driver in an async context. E.g. for use with FastAPI.

class hamilton.experimental.h_async.AsyncDriver(config, *modules, result_builder: ResultMixin | None = None)

Async driver. This is a driver that uses the AsyncGraphAdapter to execute the graph.

dr = h_async.AsyncDriver({}, async_module, result_builder=base.DictResult())
df = await dr.execute([...], inputs=...)
__init__(config, *modules, result_builder: ResultMixin | None = None)

Instantiates an asynchronous driver.

Parameters:
  • config – Config to build the graph

  • modules – Modules to crawl for fns/graph nodes

  • result_builder – Results mixin to compile the graph’s final results. TBD whether this should be included in the long run.

capture_constructor_telemetry(error: str | None, modules: Tuple[ModuleType], config: Dict[str, Any], adapter: HamiltonGraphAdapter)

Ensures we capture constructor telemetry the right way in an async context.

This is a simpler wrapper around what’s in the driver class.

Parameters:
  • error – sanitized error string, if any.

  • modules – tuple of modules to build DAG from.

  • config – config to create the driver.

  • adapter – adapter class object.

async execute(final_vars: List[str], overrides: Dict[str, Any] = None, display_graph: bool = False, inputs: Dict[str, Any] = None) Any

Executes computation.

Parameters:
  • final_vars – the final list of variables we want to compute.

  • overrides – values that will override β€œnodes” in the DAG.

  • display_graph – DEPRECATED. Whether we want to display the graph being computed.

  • inputs – Runtime inputs to the DAG.

Returns:

an object consisting of the variables requested, matching the type returned by the GraphAdapter. See constructor for how the GraphAdapter is initialized. The default one right now returns a pandas dataframe.

async raw_execute(final_vars: List[str], overrides: Dict[str, Any] = None, display_graph: bool = False, inputs: Dict[str, Any] = None, run_id: str = None) Dict[str, Any]

Executes the graph, returning a dictionary of strings (node keys) to final results.

Parameters:
  • final_vars – Variables to execute (+ upstream)

  • overrides – Overrides for nodes

  • display_graph – whether or not to display graph – this is not supported.

  • inputs – Inputs for DAG runtime calculation

Returns:

A dict of key -> result