---
title: RichProgressBar
description: Create a progress bar with rich text formatting.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.callbacks.RichProgressBar
---
# RichProgressBar {#richprogressbar}

### `class lightning.pytorch.callbacks.RichProgressBar(refresh_rate=100, leave=False, theme=RichProgressBarTheme(description='', progress_bar='#6206E0', progress_bar_finished='#6206E0', progress_bar_pulse='#6206E0', batch_progress='', time='dim', processing_speed='dim underline', metrics='italic', metrics_text_delimiter=' ', metrics_format='.3f'), console_kwargs=None)` {#lightning.pytorch.callbacks.RichProgressBar}

Bases: [`ProgressBar`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.ProgressBar.md#lightning.pytorch.callbacks.ProgressBar "lightning.pytorch.callbacks.progress.progress_bar.ProgressBar")

Create a progress bar with [rich text formatting](https://github.com/Textualize/rich).

Install it with pip:

```bash
pip install rich
```

```python
from lightning.pytorch import Trainer
from lightning.pytorch.callbacks import RichProgressBar

trainer = Trainer(callbacks=RichProgressBar())
```

Parameters:

*   **refresh\_rate** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Determines at which rate (per second) the progress bars get updated. Set it to `0` to disable the display. Default: 100
    
*   **leave** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Leaves the finished progress bar in the terminal at the end of the epoch. Default: False
    
*   **theme** (`RichProgressBarTheme`) – Contains styles used to stylize the progress bar.
    
*   **console\_kwargs** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")\]\]) – Args for constructing a Console
    

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If required rich package is not installed on the device.

Note

PyCharm users will need to enable “emulate terminal” in output console option in run/debug configuration to see styled output. Reference: [https://rich.readthedocs.io/en/latest/introduction.html#requirements](https://rich.readthedocs.io/en/latest/introduction.html#requirements)

#### `disable()` {#lightning.pytorch.callbacks.RichProgressBar.disable}

You should provide a way to disable the progress bar.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `enable()` {#lightning.pytorch.callbacks.RichProgressBar.enable}

You should provide a way to enable the progress bar.

The [`Trainer`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.trainer.trainer.Trainer.md#lightning.pytorch.trainer.trainer.Trainer "lightning.pytorch.trainer.trainer.Trainer") will call this in e.g. pre-training routines like the [learning rate finder](/docs/pytorch/2.6.6/reference/advanced/training_tricks.md#learning-rate-finder). to temporarily enable and disable the training progress bar.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `get_metrics(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.get_metrics}

Combines progress bar metrics collected from the trainer with standard metrics from get\_standard\_metrics. Implement this to override the items displayed in the progress bar.

Here is an example of how to override the defaults:

```python
def get_metrics(self, trainer, model):
    # don't show the version number
    items = super().get_metrics(trainer, model)
    items.pop("v_num", None)
    return items
```

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), `Union`\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)"), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]\]\]

Returns:

Dictionary with the items to be displayed in the progress bar.

#### `on_exception(trainer, pl_module, exception)` {#lightning.pytorch.callbacks.RichProgressBar.on_exception}

Called when any trainer execution is interrupted by an exception.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_predict_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_predict_batch_end}

Called when the predict batch ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_predict_batch_start(trainer, pl_module, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_predict_batch_start}

Called when the predict batch begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_predict_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_predict_end}

Called when predict ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_predict_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_predict_start}

Called when the predict begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_sanity_check_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_sanity_check_end}

Called when the validation sanity check ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_sanity_check_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_sanity_check_start}

Called when the validation sanity check starts.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_test_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_test_batch_end}

Called when the test batch ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_test_batch_start(trainer, pl_module, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_test_batch_start}

Called when the test batch begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_test_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_test_end}

Called when the test ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_test_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_test_start}

Called when the test begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)` {#lightning.pytorch.callbacks.RichProgressBar.on_train_batch_end}

Called when the train batch ends. :rtype: [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

Note

The value `outputs["loss"]` here will be the normalized value w.r.t `accumulate_grad_batches` of the loss returned from `training_step`.

#### `on_train_epoch_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_train_epoch_end}

Called when the train epoch ends.

To access all batch outputs at the end of the epoch, you can cache step outputs as an attribute of the [`lightning.pytorch.core.LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.LightningModule") and access them in this hook:

```python
class MyLightningModule(L.LightningModule):
    def __init__(self):
        super().__init__()
        self.training_step_outputs = []

    def training_step(self):
        loss = ...
        self.training_step_outputs.append(loss)
        return loss


class MyCallback(L.Callback):
    def on_train_epoch_end(self, trainer, pl_module):
        # do something with all training_step outputs, for example:
        epoch_mean = torch.stack(pl_module.training_step_outputs).mean()
        pl_module.log("training_epoch_mean", epoch_mean)
        # free up the memory
        pl_module.training_step_outputs.clear()
```

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_train_epoch_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_train_epoch_start}

Called when the train epoch begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_train_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_train_start}

Called when the train begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_validation_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_validation_batch_end}

Called when the validation batch ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_validation_batch_start(trainer, pl_module, batch, batch_idx, dataloader_idx=0)` {#lightning.pytorch.callbacks.RichProgressBar.on_validation_batch_start}

Called when the validation batch begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_validation_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_validation_end}

Called when the validation loop ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_validation_epoch_end(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_validation_epoch_end}

Called when the val epoch ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `on_validation_start(trainer, pl_module)` {#lightning.pytorch.callbacks.RichProgressBar.on_validation_start}

Called when the validation loop begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

#### `teardown(trainer, pl_module, stage)` {#lightning.pytorch.callbacks.RichProgressBar.teardown}

Called when fit, validate, test, predict, or tune ends.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
