All Purpose Result Builders#
Result builders help you augment what is returned by the driver’s execute() function. Here are the generic ones.
- class hamilton.base.ResultMixin#
Abstract base class housing the static function.
Why a static function? That’s because certain frameworks can only pickle a static function, not an entire object. # TODO – fix this so this can carry state/act as a standard object.
All result builders should inherit from this class and implement the build_result function. Note that applicable_input_type and output_type are optional, but recommended, for backwards compatibility. They let us type-check this. They will default to Any, which means that they’ll connect to anything.
- abstract static build_result(**outputs: Dict[str, Any]) Any #
This function builds the result given the computed values.
- input_types() List[Type[Type]] #
Gives the applicable types to this result builder. This is optional for backwards compatibility, but is recommended.
- Returns:
A list of types that this can apply to.
- output_type() Type #
Returns the output type of this result builder :return: the type that this creates
- class hamilton.base.DictResult#
Simple function that returns the dict of column -> value results.
It returns the results as a dictionary, where the keys map to outputs requested, and values map to what was computed for those values.
Use this when you want to:
debug dataflows.
have heterogeneous return types.
Want to manually transform the result into something of your choosing.
from hamilton import base, driver dict_builder = base.DictResult() adapter = base.SimplePythonGraphAdapter(dict_builder) dr = driver.Driver(config, *modules, adapter=adapter) dict_result = dr.execute([...], inputs=...)
Note, if you just want the dict result + the SimplePythonGraphAdapter, you can use the DefaultAdapter
adapter = base.DefaultAdapter()
- static build_result(**outputs: Dict[str, Any]) Dict #
This function builds a simple dict of output -> computed values.
- input_types() List[Type[Type]] | None #
Gives the applicable types to this result builder. This is optional for backwards compatibility, but is recommended.
- Returns:
A list of types that this can apply to.
- output_type() Type #
Returns the output type of this result builder :return: the type that this creates