---
title: LightningArgumentParser
description: Extension of jsonargparse’s ArgumentParser for pytorch-lightning.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.cli.LightningArgumentParser
---
# LightningArgumentParser {#lightningargumentparser}

### `class lightning.pytorch.cli.LightningArgumentParser(*args, description='Lightning Trainer command line tool', env_prefix='PL', default_env=False, **kwargs)` {#lightning.pytorch.cli.LightningArgumentParser}

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

Extension of jsonargparse’s ArgumentParser for pytorch-lightning.

Initialize argument parser that supports configuration file input.

For full details of accepted arguments see [ArgumentParser.\_\_init\_\_](https://jsonargparse.readthedocs.io/en/stable/#jsonargparse.ArgumentParser.__init__).

Parameters:

*   **description** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Description of the tool shown when running `--help`.
    
*   **env\_prefix** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Prefix for environment variables. Set `default_env=True` to enable env parsing.
    
*   **default\_env** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to parse environment variables.
    

#### `add_lightning_class_args(lightning_class, nested_key, subclass_mode=False, required=True)` {#lightning.pytorch.cli.LightningArgumentParser.add_lightning_class_args}

Adds arguments from a lightning class to a nested key of the parser.

Parameters:

*   **lightning\_class** (`Union`\[[`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.15)")\[[`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)"), `Union`\[[`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"), [`LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.module.LightningModule"), [`LightningDataModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningDataModule.md#lightning.pytorch.core.LightningDataModule "lightning.pytorch.core.datamodule.LightningDataModule"), [`Callback`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.Callback.md#lightning.pytorch.callbacks.Callback "lightning.pytorch.callbacks.callback.Callback")\]\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`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")\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`LightningModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningModule.md#lightning.pytorch.core.LightningModule "lightning.pytorch.core.module.LightningModule")\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`LightningDataModule`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.core.LightningDataModule.md#lightning.pytorch.core.LightningDataModule "lightning.pytorch.core.datamodule.LightningDataModule")\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`Callback`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.Callback.md#lightning.pytorch.callbacks.Callback "lightning.pytorch.callbacks.callback.Callback")\]\]) – A callable or any subclass of {Trainer, LightningModule, LightningDataModule, Callback}.
    
*   **nested\_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Name of the nested namespace to store arguments.
    
*   **subclass\_mode** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether allow any subclass of the given class.
    
*   **required** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether the argument group is required.
    

Return type:

[`list`](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")\]

Returns:

A list with the names of the class arguments added.

#### `add_lr_scheduler_args(lr_scheduler_class=(<class 'torch.optim.lr_scheduler.LRScheduler'>, <class 'lightning.pytorch.cli.ReduceLROnPlateau'>), nested_key='lr_scheduler', link_to='AUTOMATIC')` {#lightning.pytorch.cli.LightningArgumentParser.add_lr_scheduler_args}

Adds arguments from a learning rate scheduler class to a nested key of the parser.

Parameters:

*   **lr\_scheduler\_class** (`Union`\[[`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`LRScheduler`](https://docs.pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.LRScheduler.html#torch.optim.lr_scheduler.LRScheduler "(in PyTorch v2.15)")\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[`ReduceLROnPlateau`\], [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[`Union`\[[`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`LRScheduler`](https://docs.pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.LRScheduler.html#torch.optim.lr_scheduler.LRScheduler "(in PyTorch v2.15)")\], [`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[`ReduceLROnPlateau`\]\], [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)")\]\]) – Any subclass of `torch.optim.lr_scheduler.{_LRScheduler, ReduceLROnPlateau}`. Use tuple to allow subclasses.
    
*   **nested\_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Name of the nested namespace to store arguments.
    
*   **link\_to** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Dot notation of a parser key to set arguments or AUTOMATIC.
    

Return type:

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

#### `add_optimizer_args(optimizer_class=(<class 'torch.optim.optimizer.Optimizer'>, ), nested_key='optimizer', link_to='AUTOMATIC')` {#lightning.pytorch.cli.LightningArgumentParser.add_optimizer_args}

Adds arguments from an optimizer class to a nested key of the parser.

Parameters:

*   **optimizer\_class** (`Union`\[[`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)")\], [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`type`](https://docs.python.org/3/builtins/functions.html#type "(in Python v3.15)")\[[`Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)")\], [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis "(in Python v3.15)")\]\]) – Any subclass of [`torch.optim.Optimizer`](https://docs.pytorch.org/docs/stable/optim.html#torch.optim.Optimizer "(in PyTorch v2.15)"). Use tuple to allow subclasses.
    
*   **nested\_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Name of the nested namespace to store arguments.
    
*   **link\_to** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Dot notation of a parser key to set arguments or AUTOMATIC.
    

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)
