plugins.h_rich.RichProgressBarΒΆ

Provides a progress bar for Hamilton execution. Must have rich installed to use it:

pip install sf-hamilton[rich] (use quotes if using zsh)

class hamilton.plugins.h_rich.RichProgressBar(run_desc: str = '', collect_desc: str = '', columns: list[str | ProgressColumn] | None = None, **kwargs)ΒΆ

An adapter that uses rich to show simple progress bars for the graph execution.

Note: you need to have rich installed for this to work. If you don’t have it installed, you can install it with pip install rich (or pip install sf-hamilton[rich] – use quotes if you’re using zsh).

from hamilton import driver
from hamilton.plugins import h_rich

dr = (
    driver.Builder()
    .with_config({})
    .with_modules(some_modules)
    .with_adapters(h_rich.RichProgressBar())
    .build()
)

and then when you call .execute() or .materialize() you’ll get a progress bar!

Additionally, this progress bar will also work with task-based execution, showing the progress of overall execution as well as the tasks within a parallelized group.

from hamilton import driver
from hamilton.execution import executors
from hamilton.plugins import h_rich

dr = (
    driver.Builder()
    .with_modules(__main__)
    .enable_dynamic_execution(allow_experimental_mode=True)
    .with_adapters(RichProgressBar())
    .with_local_executor(executors.SynchronousLocalTaskExecutor())
    .with_remote_executor(executors.SynchronousLocalTaskExecutor())
    .build()
)
__init__(run_desc: str = '', collect_desc: str = '', columns: list[str | ProgressColumn] | None = None, **kwargs) NoneΒΆ

Create a new Rich Progress Bar adapter.

Parameters:
  • run_desc – The description to show for the running phase.

  • collect_desc – The description to show for the collecting phase (if applicable).

  • columns – Column configuration for the progress bar. See rich docs for more info.

  • kwargs – Additional kwargs to pass to rich.progress.Progress. See rich docs for more info.

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.

post_node_execute(*, run_id: str, node_: Node, kwargs: Dict[str, Any], success: bool, error: Exception | None, result: Any | None, task_id: str | None = None)ΒΆ

Wraps the after_execution method, providing a bridge to an external-facing API. Do not override this!

post_task_execute(*, run_id: str, task_id: str, nodes: List[Node], results: Dict[str, Any] | None, success: bool, error: Exception, spawning_task_id: str | None, purpose: None)ΒΆ

Hook called immediately after task execution. Note that this is only useful in dynamic execution, although we reserve the right to add this back into the standard hamilton execution pattern.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_id – ID of the task

  • nodes – Nodes that were executed

  • results – Results of the task

  • success – Whether or not the task executed successfully

  • error – The error that was raised, if any

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

post_task_expand(*, run_id: str, task_id: str, parameters: Dict[str, Any])ΒΆ

Hook that is called immediately after a task is expanded into separate task. Note that this is only useful in dynamic execution.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_id – ID of the task.

  • parameters – Parameters that are being passed to each of the expanded tasks.

post_task_group(*, run_id: str, task_ids: List[str])ΒΆ

Hook that is called immediately after a task group is created. Note that this is only useful in dynamic execution, although we reserve the right to add this back into the standard hamilton execution pattern.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_ids – IDs of tasks that are in the group.

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.

pre_node_execute(*, run_id: str, node_: Node, kwargs: Dict[str, Any], task_id: str | None = None)ΒΆ

Wraps the before_execution method, providing a bridge to an external-facing API. Do not override this!

pre_task_execute(*, run_id: str, task_id: str, nodes: List[Node], inputs: Dict[str, Any], overrides: Dict[str, Any], spawning_task_id: str | None, purpose: None)ΒΆ

Hook that is called immediately prior to task execution. Note that this is only useful in dynamic execution, although we reserve the right to add this back into the standard hamilton execution pattern.

Parameters:
  • run_id – ID of the run, unique in scope of the driver.

  • task_id – ID of the task, unique in scope of the driver.

  • nodes – Nodes that are being executed

  • inputs – Inputs to the task

  • overrides – Overrides to task execution

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

run_after_graph_execution(**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

run_after_node_execution(**kwargs)ΒΆ

Hook that is executed post node execution.

Parameters:
  • node_name – Name of the node in question

  • node_tags – Tags of the node

  • node_kwargs – Keyword arguments passed to the node

  • node_return_type – Return type of the node

  • result – Output of the node, None if an error occurred

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

  • success – Whether the node executed successfully

  • task_id – The ID of the task, none if not in a task-based environment

  • 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

run_after_task_execution(*, purpose: NodeGroupPurpose, **kwargs)ΒΆ

Implement this to run something after task execution. See note in run_before_task_execution.

Parameters:
  • task_id – ID of the task that was just executed

  • run_id – ID of the run this was under.

  • nodes – Nodes that were part of this task

  • results – Results of the task, per-node

  • success – Whether the task was successful

  • error – The error the task threw, if any

  • future_kwargs – Reserved for backwards compatibility.

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group

run_after_task_expansion(*, parameters: dict[str, Any], **kwargs)ΒΆ

Hook that is called after task expansion. :param run_id: ID of the run, unique in scope of the driver. :param task_id: ID of the task that was expanded. :param parameters: Parameters that were passed to the task. :param future_kwargs: Additional keyword arguments – this is kept for backwards compatibility.

run_after_task_grouping(*, task_ids: List[str], **kwargs)ΒΆ

Hook that is called after task grouping. :param run_id: ID of the run, unique in scope of the driver. :param task_ids: List of tasks that were grouped together. :param future_kwargs: Additional keyword arguments – this is kept for backwards compatibility.

run_before_graph_execution(*, execution_path: Collection[str], **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

run_before_node_execution(**kwargs)ΒΆ

Hook that is executed prior to node execution.

Parameters:
  • node_name – Name of the node.

  • node_tags – Tags of the node

  • node_kwargs – Keyword arguments to pass to the node

  • node_return_type – Return type of the node

  • task_id – The ID of the task, none if not in a task-based environment

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

  • node_input_types – the input types to the node and what it is expecting

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

run_before_task_execution(*, purpose: NodeGroupPurpose, **kwargs)ΒΆ

Implement this to run something after task execution. Tasks are tols used to group nodes. Note that this is currently run inside the task, although we do not guarantee where it will be run (it could easily move to outside the task).

Parameters:
  • task_id – ID of the task we’re launching.

  • run_id – ID of the run this is under.

  • nodes – Nodes that are part of this task

  • inputs – Inputs to the task

  • overrides – Overrides passed to the task

  • future_kwargs – Reserved for backwards compatibility.

  • spawning_task_id – ID of the task that spawned this task

  • purpose – Purpose of the current task group