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[module], 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) 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