Skip to content

Typer class

Here's the reference information for the Typer class, with all its parameters, attributes and methods.

You can import the Typer class directly from typer:

from typer import Typer

typer.Typer

Typer(
    *,
    name=Default(None),
    cls=Default(None),
    invoke_without_command=Default(False),
    no_args_is_help=Default(False),
    subcommand_metavar=Default(None),
    chain=Default(False),
    result_callback=Default(None),
    context_settings=Default(None),
    callback=Default(None),
    help=Default(None),
    epilog=Default(None),
    short_help=Default(None),
    options_metavar=Default("[OPTIONS]"),
    add_help_option=Default(True),
    hidden=Default(False),
    deprecated=Default(False),
    add_completion=True,
    rich_markup_mode=DEFAULT_MARKUP_MODE,
    rich_help_panel=Default(None),
    suggest_commands=True,
    pretty_exceptions_enable=True,
    pretty_exceptions_show_locals=True,
    pretty_exceptions_short=True,
)

Typer main class, the main entrypoint to use Typer.

Read more in the Typer docs for First Steps.

Example

import typer

app = typer.Typer()
PARAMETER DESCRIPTION
name

The name of this application. Mostly used to set the name for subcommands, in which case it can be overridden by add_typer(name=...).

Example

import typer

app = typer.Typer(name="users")

TYPE: Optional[str] DEFAULT: Default(None)

cls

The class of this app. Mainly used when using the Click library underneath. Can usually be left at the default value None. Otherwise, should be a subtype of TyperGroup.

Example

import typer

app = typer.Typer(cls=TyperGroup)

TYPE: Optional[type[TyperGroup]] DEFAULT: Default(None)

invoke_without_command

By setting this to True, you can make sure a callback is executed even when no subcommand is provided.

Example

import typer

app = typer.Typer(invoke_without_command=True)

TYPE: bool DEFAULT: Default(False)

no_args_is_help

If this is set to True, running a command without any arguments will automatically show the help page.

Example

import typer

app = typer.Typer(no_args_is_help=True)

TYPE: bool DEFAULT: Default(False)

subcommand_metavar

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


How to represent the subcommand argument in help.

TYPE: Optional[str] DEFAULT: Default(None)

chain

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


Allow passing more than one subcommand argument.

TYPE: bool DEFAULT: Default(False)

result_callback

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


A function to call after the group's and subcommand's callbacks.

TYPE: Optional[Callable[..., Any]] DEFAULT: Default(None)

context_settings

Pass configurations for the context. Available configurations can be found in the docs for Click's Context here.

Example

import typer

app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})

TYPE: Optional[dict[Any, Any]] DEFAULT: Default(None)

callback

Add a callback to the main Typer app. Can be overridden with @app.callback(). See the tutorial about callbacks for more details.

Example

import typer

def callback():
    print("Running a command")

app = typer.Typer(callback=callback)

TYPE: Optional[Callable[..., Any]] DEFAULT: Default(None)

help

Help text for the main Typer app. See the tutorial about name and help for different ways of setting a command's help, and which one takes priority.

Example

import typer

app = typer.Typer(help="Some help.")

TYPE: Optional[str] DEFAULT: Default(None)

epilog

Text that will be printed right after the help text.

Example

import typer

app = typer.Typer(epilog="May the force be with you")

TYPE: Optional[str] DEFAULT: Default(None)

short_help

A shortened version of the help text that can be used e.g. in the help table listing subcommands. When not defined, the normal help text will be used instead.

Example

import typer

app = typer.Typer(help="A lot of explanation about user management", short_help="user management")

TYPE: Optional[str] DEFAULT: Default(None)

options_metavar

In the example usage string of the help text for a command, the default placeholder for various arguments is [OPTIONS]. Set options_metavar to change this into a different string.

Example

import typer

app = typer.Typer(options_metavar="[OPTS]")

TYPE: str DEFAULT: Default('[OPTIONS]')

add_help_option

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


By default each command registers a --help option. This can be disabled by this parameter.

TYPE: bool DEFAULT: Default(True)

hidden

Hide this command from help outputs. False by default.

Example

import typer

app = typer.Typer(hidden=True)

TYPE: bool DEFAULT: Default(False)

deprecated

Mark this command as being deprecated in the help text. False by default.

Example

import typer

app = typer.Typer(deprecated=True)

TYPE: bool DEFAULT: Default(False)

add_completion

Toggle whether or not to add the --install-completion and --show-completion options to the app. Set to True by default.

Example

import typer

app = typer.Typer(add_completion=False)

TYPE: bool DEFAULT: True

rich_markup_mode

Enable markup text if you have Rich installed. This can be set to "markdown", "rich", or None. By default, rich_markup_mode is None if Rich is not installed, and "rich" if it is installed. See the tutorial on help formatting for more information.

Example

import typer

app = typer.Typer(rich_markup_mode="rich")

TYPE: MarkupMode DEFAULT: DEFAULT_MARKUP_MODE

rich_help_panel

Set the panel name of the command when the help is printed with Rich.

Example

import typer

app = typer.Typer(rich_help_panel="Utils and Configs")

TYPE: Union[str, None] DEFAULT: Default(None)

suggest_commands

As of version 0.20.0, Typer provides support for mistyped command names by printing helpful suggestions. You can turn this setting off with suggest_commands:

Example

import typer

app = typer.Typer(suggest_commands=False)

TYPE: bool DEFAULT: True

pretty_exceptions_enable

If you want to disable pretty exceptions with Rich, you can set pretty_exceptions_enable to False. When doing so, you will see the usual standard exception trace.

Example

import typer

app = typer.Typer(pretty_exceptions_enable=False)

TYPE: bool DEFAULT: True

pretty_exceptions_show_locals

If Rich is installed, error messages will be nicely printed and include the values of local variables for easy debugging. However, if such a variable contains delicate information, you should consider setting pretty_exceptions_show_locals to False to enhance security.

Example

import typer

app = typer.Typer(pretty_exceptions_show_locals=False)

TYPE: bool DEFAULT: True

pretty_exceptions_short

By default, pretty exceptions formatted with Rich hide the long stack trace. If you want to show the full trace instead, you can set the parameter pretty_exceptions_short to False:

Example

import typer

app = typer.Typer(pretty_exceptions_short=False)

TYPE: bool DEFAULT: True

Source code in typer/main.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
def __init__(
    self,
    *,
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name of this application.
            Mostly used to set the name for [subcommands](https://typer.tiangolo.com/tutorial/subcommands/), in which case it can be overridden by `add_typer(name=...)`.

            **Example**

            ```python
            import typer

            app = typer.Typer(name="users")
            ```
            """
        ),
    ] = Default(None),
    cls: Annotated[
        Optional[type[TyperGroup]],
        Doc(
            """
            The class of this app. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
            Otherwise, should be a subtype of `TyperGroup`.

            **Example**

            ```python
            import typer

            app = typer.Typer(cls=TyperGroup)
            ```
            """
        ),
    ] = Default(None),
    invoke_without_command: Annotated[
        bool,
        Doc(
            """
            By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.

            **Example**

            ```python
            import typer

            app = typer.Typer(invoke_without_command=True)
            ```
            """
        ),
    ] = Default(False),
    no_args_is_help: Annotated[
        bool,
        Doc(
            """
            If this is set to `True`, running a command without any arguments will automatically show the help page.

            **Example**

            ```python
            import typer

            app = typer.Typer(no_args_is_help=True)
            ```
            """
        ),
    ] = Default(False),
    subcommand_metavar: Annotated[
        Optional[str],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            How to represent the subcommand argument in help.
            """
        ),
    ] = Default(None),
    chain: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            Allow passing more than one subcommand argument.
            """
        ),
    ] = Default(False),
    result_callback: Annotated[
        Optional[Callable[..., Any]],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            A function to call after the group's and subcommand's callbacks.
            """
        ),
    ] = Default(None),
    # Command
    context_settings: Annotated[
        Optional[dict[Any, Any]],
        Doc(
            """
            Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
            Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).

            **Example**

            ```python
            import typer

            app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
            ```
            """
        ),
    ] = Default(None),
    callback: Annotated[
        Optional[Callable[..., Any]],
        Doc(
            """
            Add a callback to the main Typer app. Can be overridden with `@app.callback()`.
            See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/commands/callback/) for more details.

            **Example**

            ```python
            import typer

            def callback():
                print("Running a command")

            app = typer.Typer(callback=callback)
            ```
            """
        ),
    ] = Default(None),
    help: Annotated[
        Optional[str],
        Doc(
            """
            Help text for the main Typer app.
            See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
            and which one takes priority.

            **Example**

            ```python
            import typer

            app = typer.Typer(help="Some help.")
            ```
            """
        ),
    ] = Default(None),
    epilog: Annotated[
        Optional[str],
        Doc(
            """
            Text that will be printed right after the help text.

            **Example**

            ```python
            import typer

            app = typer.Typer(epilog="May the force be with you")
            ```
            """
        ),
    ] = Default(None),
    short_help: Annotated[
        Optional[str],
        Doc(
            """
            A shortened version of the help text that can be used e.g. in the help table listing subcommands.
            When not defined, the normal `help` text will be used instead.

            **Example**

            ```python
            import typer

            app = typer.Typer(help="A lot of explanation about user management", short_help="user management")
            ```
            """
        ),
    ] = Default(None),
    options_metavar: Annotated[
        str,
        Doc(
            """
            In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
            Set `options_metavar` to change this into a different string.

            **Example**

            ```python
            import typer

            app = typer.Typer(options_metavar="[OPTS]")
            ```
            """
        ),
    ] = Default("[OPTIONS]"),
    add_help_option: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            By default each command registers a `--help` option. This can be disabled by this parameter.
            """
        ),
    ] = Default(True),
    hidden: Annotated[
        bool,
        Doc(
            """
            Hide this command from help outputs. `False` by default.

            **Example**

            ```python
            import typer

            app = typer.Typer(hidden=True)
            ```
            """
        ),
    ] = Default(False),
    deprecated: Annotated[
        bool,
        Doc(
            """
            Mark this command as being deprecated in the help text. `False` by default.

            **Example**

            ```python
            import typer

            app = typer.Typer(deprecated=True)
            ```
            """
        ),
    ] = Default(False),
    add_completion: Annotated[
        bool,
        Doc(
            """
            Toggle whether or not to add the `--install-completion` and `--show-completion` options to the app.
            Set to `True` by default.

            **Example**

            ```python
            import typer

            app = typer.Typer(add_completion=False)
            ```
            """
        ),
    ] = True,
    # Rich settings
    rich_markup_mode: Annotated[
        MarkupMode,
        Doc(
            """
            Enable markup text if you have Rich installed. This can be set to `"markdown"`, `"rich"`, or `None`.
            By default, `rich_markup_mode` is `None` if Rich is not installed, and `"rich"` if it is installed.
            See [the tutorial on help formatting](https://typer.tiangolo.com/tutorial/commands/help/#rich-markdown-and-markup) for more information.

            **Example**

            ```python
            import typer

            app = typer.Typer(rich_markup_mode="rich")
            ```
            """
        ),
    ] = DEFAULT_MARKUP_MODE,
    rich_help_panel: Annotated[
        Union[str, None],
        Doc(
            """
            Set the panel name of the command when the help is printed with Rich.

            **Example**

            ```python
            import typer

            app = typer.Typer(rich_help_panel="Utils and Configs")
            ```
            """
        ),
    ] = Default(None),
    suggest_commands: Annotated[
        bool,
        Doc(
            """
            As of version 0.20.0, Typer provides [support for mistyped command names](https://typer.tiangolo.com/tutorial/commands/help/#suggest-commands) by printing helpful suggestions.
            You can turn this setting off with `suggest_commands`:

            **Example**

            ```python
            import typer

            app = typer.Typer(suggest_commands=False)
            ```
            """
        ),
    ] = True,
    pretty_exceptions_enable: Annotated[
        bool,
        Doc(
            """
            If you want to disable [pretty exceptions with Rich](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-with-rich),
            you can set `pretty_exceptions_enable` to `False`. When doing so, you will see the usual standard exception trace.

            **Example**

            ```python
            import typer

            app = typer.Typer(pretty_exceptions_enable=False)
            ```
            """
        ),
    ] = True,
    pretty_exceptions_show_locals: Annotated[
        bool,
        Doc(
            """
            If Rich is installed, [error messages](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-and-errors)
            will be nicely printed and include the values of local variables for easy debugging.
            However, if such a variable contains delicate information, you should consider setting `pretty_exceptions_show_locals` to `False`
            to enhance security.

            **Example**

            ```python
            import typer

            app = typer.Typer(pretty_exceptions_show_locals=False)
            ```
            """
        ),
    ] = True,
    pretty_exceptions_short: Annotated[
        bool,
        Doc(
            """
            By default, [pretty exceptions formatted with Rich](https://typer.tiangolo.com/tutorial/exceptions/#exceptions-with-rich) hide the long stack trace.
            If you want to show the full trace instead, you can set the parameter `pretty_exceptions_short` to `False`:

            **Example**

            ```python
            import typer

            app = typer.Typer(pretty_exceptions_short=False)
            ```
            """
        ),
    ] = True,
):
    self._add_completion = add_completion
    self.rich_markup_mode: MarkupMode = rich_markup_mode
    self.rich_help_panel = rich_help_panel
    self.suggest_commands = suggest_commands
    self.pretty_exceptions_enable = pretty_exceptions_enable
    self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
    self.pretty_exceptions_short = pretty_exceptions_short
    self.info = TyperInfo(
        name=name,
        cls=cls,
        invoke_without_command=invoke_without_command,
        no_args_is_help=no_args_is_help,
        subcommand_metavar=subcommand_metavar,
        chain=chain,
        result_callback=result_callback,
        context_settings=context_settings,
        callback=callback,
        help=help,
        epilog=epilog,
        short_help=short_help,
        options_metavar=options_metavar,
        add_help_option=add_help_option,
        hidden=hidden,
        deprecated=deprecated,
    )
    self.registered_groups: list[TyperInfo] = []
    self.registered_commands: list[CommandInfo] = []
    self.registered_callback: Optional[TyperInfo] = None

callback

callback(
    *,
    cls=Default(None),
    invoke_without_command=Default(False),
    no_args_is_help=Default(False),
    subcommand_metavar=Default(None),
    chain=Default(False),
    result_callback=Default(None),
    context_settings=Default(None),
    help=Default(None),
    epilog=Default(None),
    short_help=Default(None),
    options_metavar=Default(None),
    add_help_option=Default(True),
    hidden=Default(False),
    deprecated=Default(False),
    rich_help_panel=Default(None),
)

Using the decorator @app.callback, you can declare the CLI parameters for the main CLI application.

Read more in the Typer docs for Callbacks.

Example
import typer

app = typer.Typer()
state = {"verbose": False}

@app.callback()
def main(verbose: bool = False):
    if verbose:
        print("Will write verbose output")
        state["verbose"] = True

@app.command()
def delete(username: str):
    # define subcommand
    ...
PARAMETER DESCRIPTION
cls

The class of this app. Mainly used when using the Click library underneath. Can usually be left at the default value None. Otherwise, should be a subtype of TyperGroup.

TYPE: Optional[type[TyperGroup]] DEFAULT: Default(None)

invoke_without_command

By setting this to True, you can make sure a callback is executed even when no subcommand is provided.

TYPE: bool DEFAULT: Default(False)

no_args_is_help

If this is set to True, running a command without any arguments will automatically show the help page.

TYPE: bool DEFAULT: Default(False)

subcommand_metavar

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


How to represent the subcommand argument in help.

TYPE: Optional[str] DEFAULT: Default(None)

chain

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


Allow passing more than one subcommand argument.

TYPE: bool DEFAULT: Default(False)

result_callback

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


A function to call after the group's and subcommand's callbacks.

TYPE: Optional[Callable[..., Any]] DEFAULT: Default(None)

context_settings

Pass configurations for the context. Available configurations can be found in the docs for Click's Context here.

TYPE: Optional[dict[Any, Any]] DEFAULT: Default(None)

help

Help text for the command. See the tutorial about name and help for different ways of setting a command's help, and which one takes priority.

TYPE: Optional[str] DEFAULT: Default(None)

epilog

Text that will be printed right after the help text.

TYPE: Optional[str] DEFAULT: Default(None)

short_help

A shortened version of the help text that can be used e.g. in the help table listing subcommands. When not defined, the normal help text will be used instead.

TYPE: Optional[str] DEFAULT: Default(None)

options_metavar

In the example usage string of the help text for a command, the default placeholder for various arguments is [OPTIONS]. Set options_metavar to change this into a different string. When None, the default value will be used.

TYPE: Optional[str] DEFAULT: Default(None)

add_help_option

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


By default each command registers a --help option. This can be disabled by this parameter.

TYPE: bool DEFAULT: Default(True)

hidden

Hide this command from help outputs. False by default.

TYPE: bool DEFAULT: Default(False)

deprecated

Mark this command as deprecated in the help text. False by default.

TYPE: bool DEFAULT: Default(False)

rich_help_panel

Set the panel name of the command when the help is printed with Rich.

TYPE: Union[str, None] DEFAULT: Default(None)

Source code in typer/main.py
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
def callback(
    self,
    *,
    cls: Annotated[
        Optional[type[TyperGroup]],
        Doc(
            """
            The class of this app. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
            Otherwise, should be a subtype of `TyperGroup`.
            """
        ),
    ] = Default(None),
    invoke_without_command: Annotated[
        bool,
        Doc(
            """
            By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
            """
        ),
    ] = Default(False),
    no_args_is_help: Annotated[
        bool,
        Doc(
            """
            If this is set to `True`, running a command without any arguments will automatically show the help page.
            """
        ),
    ] = Default(False),
    subcommand_metavar: Annotated[
        Optional[str],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            How to represent the subcommand argument in help.
            """
        ),
    ] = Default(None),
    chain: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            Allow passing more than one subcommand argument.
            """
        ),
    ] = Default(False),
    result_callback: Annotated[
        Optional[Callable[..., Any]],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            A function to call after the group's and subcommand's callbacks.
            """
        ),
    ] = Default(None),
    # Command
    context_settings: Annotated[
        Optional[dict[Any, Any]],
        Doc(
            """
            Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
            Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
            """
        ),
    ] = Default(None),
    help: Annotated[
        Optional[str],
        Doc(
            """
            Help text for the command.
            See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
            and which one takes priority.
            """
        ),
    ] = Default(None),
    epilog: Annotated[
        Optional[str],
        Doc(
            """
            Text that will be printed right after the help text.
            """
        ),
    ] = Default(None),
    short_help: Annotated[
        Optional[str],
        Doc(
            """
            A shortened version of the help text that can be used e.g. in the help table listing subcommands.
            When not defined, the normal `help` text will be used instead.
            """
        ),
    ] = Default(None),
    options_metavar: Annotated[
        Optional[str],
        Doc(
            """
            In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
            Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
            """
        ),
    ] = Default(None),
    add_help_option: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            By default each command registers a `--help` option. This can be disabled by this parameter.
            """
        ),
    ] = Default(True),
    hidden: Annotated[
        bool,
        Doc(
            """
            Hide this command from help outputs. `False` by default.
            """
        ),
    ] = Default(False),
    deprecated: Annotated[
        bool,
        Doc(
            """
            Mark this command as deprecated in the help text. `False` by default.
            """
        ),
    ] = Default(False),
    # Rich settings
    rich_help_panel: Annotated[
        Union[str, None],
        Doc(
            """
            Set the panel name of the command when the help is printed with Rich.
            """
        ),
    ] = Default(None),
) -> Callable[[CommandFunctionType], CommandFunctionType]:
    """
    Using the decorator `@app.callback`, you can declare the CLI parameters for the main CLI application.

    Read more in the
    [Typer docs for Callbacks](https://typer.tiangolo.com/tutorial/commands/callback/).

    ## Example

    ```python
    import typer

    app = typer.Typer()
    state = {"verbose": False}

    @app.callback()
    def main(verbose: bool = False):
        if verbose:
            print("Will write verbose output")
            state["verbose"] = True

    @app.command()
    def delete(username: str):
        # define subcommand
        ...
    ```
    """

    def decorator(f: CommandFunctionType) -> CommandFunctionType:
        self.registered_callback = TyperInfo(
            cls=cls,
            invoke_without_command=invoke_without_command,
            no_args_is_help=no_args_is_help,
            subcommand_metavar=subcommand_metavar,
            chain=chain,
            result_callback=result_callback,
            context_settings=context_settings,
            callback=f,
            help=help,
            epilog=epilog,
            short_help=short_help,
            options_metavar=(
                options_metavar or self._info_val_str("options_metavar")
            ),
            add_help_option=add_help_option,
            hidden=hidden,
            deprecated=deprecated,
            rich_help_panel=rich_help_panel,
        )
        return f

    return decorator

command

command(
    name=None,
    *,
    cls=None,
    context_settings=None,
    help=None,
    epilog=None,
    short_help=None,
    options_metavar=Default(None),
    add_help_option=True,
    no_args_is_help=False,
    hidden=False,
    deprecated=False,
    rich_help_panel=Default(None),
)

Using the decorator @app.command, you can define a subcommand of the previously defined Typer app.

Read more in the Typer docs for Commands.

Example
import typer

app = typer.Typer()

@app.command()
def create():
    print("Creating user: Hiro Hamada")

@app.command()
def delete():
    print("Deleting user: Hiro Hamada")
PARAMETER DESCRIPTION
name

The name of this command.

TYPE: Optional[str] DEFAULT: None

cls

The class of this command. Mainly used when using the Click library underneath. Can usually be left at the default value None. Otherwise, should be a subtype of TyperCommand.

TYPE: Optional[type[TyperCommand]] DEFAULT: None

context_settings

Pass configurations for the context. Available configurations can be found in the docs for Click's Context here.

TYPE: Optional[dict[Any, Any]] DEFAULT: None

help

Help text for the command. See the tutorial about name and help for different ways of setting a command's help, and which one takes priority.

TYPE: Optional[str] DEFAULT: None

epilog

Text that will be printed right after the help text.

TYPE: Optional[str] DEFAULT: None

short_help

A shortened version of the help text that can be used e.g. in the help table listing subcommands. When not defined, the normal help text will be used instead.

TYPE: Optional[str] DEFAULT: None

options_metavar

In the example usage string of the help text for a command, the default placeholder for various arguments is [OPTIONS]. Set options_metavar to change this into a different string. When None, the default value will be used.

TYPE: Optional[str] DEFAULT: Default(None)

add_help_option

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


By default each command registers a --help option. This can be disabled by this parameter.

TYPE: bool DEFAULT: True

no_args_is_help

If this is set to True, running a command without any arguments will automatically show the help page.

TYPE: bool DEFAULT: False

hidden

Hide this command from help outputs. False by default.

TYPE: bool DEFAULT: False

deprecated

Mark this command as deprecated in the help outputs. False by default.

TYPE: bool DEFAULT: False

rich_help_panel

Set the panel name of the command when the help is printed with Rich.

TYPE: Union[str, None] DEFAULT: Default(None)

Source code in typer/main.py
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
def command(
    self,
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name of this command.
            """
        ),
    ] = None,
    *,
    cls: Annotated[
        Optional[type[TyperCommand]],
        Doc(
            """
            The class of this command. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
            Otherwise, should be a subtype of `TyperCommand`.
            """
        ),
    ] = None,
    context_settings: Annotated[
        Optional[dict[Any, Any]],
        Doc(
            """
            Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
            Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
            """
        ),
    ] = None,
    help: Annotated[
        Optional[str],
        Doc(
            """
            Help text for the command.
            See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
            and which one takes priority.
            """
        ),
    ] = None,
    epilog: Annotated[
        Optional[str],
        Doc(
            """
            Text that will be printed right after the help text.
            """
        ),
    ] = None,
    short_help: Annotated[
        Optional[str],
        Doc(
            """
            A shortened version of the help text that can be used e.g. in the help table listing subcommands.
            When not defined, the normal `help` text will be used instead.
            """
        ),
    ] = None,
    options_metavar: Annotated[
        Optional[str],
        Doc(
            """
            In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
            Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
            """
        ),
    ] = Default(None),
    add_help_option: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            By default each command registers a `--help` option. This can be disabled by this parameter.
            """
        ),
    ] = True,
    no_args_is_help: Annotated[
        bool,
        Doc(
            """
            If this is set to `True`, running a command without any arguments will automatically show the help page.
            """
        ),
    ] = False,
    hidden: Annotated[
        bool,
        Doc(
            """
            Hide this command from help outputs. `False` by default.
            """
        ),
    ] = False,
    deprecated: Annotated[
        bool,
        Doc(
            """
            Mark this command as deprecated in the help outputs. `False` by default.
            """
        ),
    ] = False,
    # Rich settings
    rich_help_panel: Annotated[
        Union[str, None],
        Doc(
            """
            Set the panel name of the command when the help is printed with Rich.
            """
        ),
    ] = Default(None),
) -> Callable[[CommandFunctionType], CommandFunctionType]:
    """
    Using the decorator `@app.command`, you can define a subcommand of the previously defined Typer app.

    Read more in the
    [Typer docs for Commands](https://typer.tiangolo.com/tutorial/commands/).

    ## Example

    ```python
    import typer

    app = typer.Typer()

    @app.command()
    def create():
        print("Creating user: Hiro Hamada")

    @app.command()
    def delete():
        print("Deleting user: Hiro Hamada")
    ```
    """
    if cls is None:
        cls = TyperCommand

    def decorator(f: CommandFunctionType) -> CommandFunctionType:
        self.registered_commands.append(
            CommandInfo(
                name=name,
                cls=cls,
                context_settings=context_settings,
                callback=f,
                help=help,
                epilog=epilog,
                short_help=short_help,
                options_metavar=(
                    options_metavar or self._info_val_str("options_metavar")
                ),
                add_help_option=add_help_option,
                no_args_is_help=no_args_is_help,
                hidden=hidden,
                deprecated=deprecated,
                # Rich settings
                rich_help_panel=rich_help_panel,
            )
        )
        return f

    return decorator

add_typer

add_typer(
    typer_instance,
    *,
    name=Default(None),
    cls=Default(None),
    invoke_without_command=Default(False),
    no_args_is_help=Default(False),
    subcommand_metavar=Default(None),
    chain=Default(False),
    result_callback=Default(None),
    context_settings=Default(None),
    callback=Default(None),
    help=Default(None),
    epilog=Default(None),
    short_help=Default(None),
    options_metavar=Default(None),
    add_help_option=Default(True),
    hidden=Default(False),
    deprecated=False,
    rich_help_panel=Default(None),
)

Add subcommands to the main app using app.add_typer(). Subcommands may be defined in separate modules, ensuring clean separation of code by functionality.

Read more in the Typer docs for SubCommands.

Example
import typer

from .add import app as add_app
from .delete import app as delete_app

app = typer.Typer()

app.add_typer(add_app)
app.add_typer(delete_app)
PARAMETER DESCRIPTION
name

The name of this subcommand. See the tutorial about name and help for different ways of setting a command's name, and which one takes priority.

TYPE: Optional[str] DEFAULT: Default(None)

cls

The class of this subcommand. Mainly used when using the Click library underneath. Can usually be left at the default value None. Otherwise, should be a subtype of TyperGroup.

TYPE: Optional[type[TyperGroup]] DEFAULT: Default(None)

invoke_without_command

By setting this to True, you can make sure a callback is executed even when no subcommand is provided.

TYPE: bool DEFAULT: Default(False)

no_args_is_help

If this is set to True, running a command without any arguments will automatically show the help page.

TYPE: bool DEFAULT: Default(False)

subcommand_metavar

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


How to represent the subcommand argument in help.

TYPE: Optional[str] DEFAULT: Default(None)

chain

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


Allow passing more than one subcommand argument.

TYPE: bool DEFAULT: Default(False)

result_callback

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


A function to call after the group's and subcommand's callbacks.

TYPE: Optional[Callable[..., Any]] DEFAULT: Default(None)

context_settings

Pass configurations for the context. Available configurations can be found in the docs for Click's Context here.

TYPE: Optional[dict[Any, Any]] DEFAULT: Default(None)

callback

Add a callback to this app. See the tutorial about callbacks for more details.

TYPE: Optional[Callable[..., Any]] DEFAULT: Default(None)

help

Help text for the subcommand. See the tutorial about name and help for different ways of setting a command's help, and which one takes priority.

TYPE: Optional[str] DEFAULT: Default(None)

epilog

Text that will be printed right after the help text.

TYPE: Optional[str] DEFAULT: Default(None)

short_help

A shortened version of the help text that can be used e.g. in the help table listing subcommands. When not defined, the normal help text will be used instead.

TYPE: Optional[str] DEFAULT: Default(None)

options_metavar

In the example usage string of the help text for a command, the default placeholder for various arguments is [OPTIONS]. Set options_metavar to change this into a different string. When None, the default value will be used.

TYPE: Optional[str] DEFAULT: Default(None)

add_help_option

Note: you probably shouldn't use this parameter, it is inherited from Click and supported for compatibility.


By default each command registers a --help option. This can be disabled by this parameter.

TYPE: bool DEFAULT: Default(True)

hidden

Hide this command from help outputs. False by default.

TYPE: bool DEFAULT: Default(False)

deprecated

Mark this command as deprecated in the help outputs. False by default.

TYPE: bool DEFAULT: False

rich_help_panel

Set the panel name of the command when the help is printed with Rich.

TYPE: Union[str, None] DEFAULT: Default(None)

Source code in typer/main.py
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
def add_typer(
    self,
    typer_instance: "Typer",
    *,
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name of this subcommand.
            See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's name,
            and which one takes priority.
            """
        ),
    ] = Default(None),
    cls: Annotated[
        Optional[type[TyperGroup]],
        Doc(
            """
            The class of this subcommand. Mainly used when [using the Click library underneath](https://typer.tiangolo.com/tutorial/using-click/). Can usually be left at the default value `None`.
            Otherwise, should be a subtype of `TyperGroup`.
            """
        ),
    ] = Default(None),
    invoke_without_command: Annotated[
        bool,
        Doc(
            """
            By setting this to `True`, you can make sure a callback is executed even when no subcommand is provided.
            """
        ),
    ] = Default(False),
    no_args_is_help: Annotated[
        bool,
        Doc(
            """
            If this is set to `True`, running a command without any arguments will automatically show the help page.
            """
        ),
    ] = Default(False),
    subcommand_metavar: Annotated[
        Optional[str],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            How to represent the subcommand argument in help.
            """
        ),
    ] = Default(None),
    chain: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            Allow passing more than one subcommand argument.
            """
        ),
    ] = Default(False),
    result_callback: Annotated[
        Optional[Callable[..., Any]],
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            A function to call after the group's and subcommand's callbacks.
            """
        ),
    ] = Default(None),
    # Command
    context_settings: Annotated[
        Optional[dict[Any, Any]],
        Doc(
            """
            Pass configurations for the [context](https://typer.tiangolo.com/tutorial/commands/context/).
            Available configurations can be found in the docs for Click's `Context` [here](https://click.palletsprojects.com/en/stable/api/#context).
            """
        ),
    ] = Default(None),
    callback: Annotated[
        Optional[Callable[..., Any]],
        Doc(
            """
            Add a callback to this app.
            See [the tutorial about callbacks](https://typer.tiangolo.com/tutorial/commands/callback/) for more details.
            """
        ),
    ] = Default(None),
    help: Annotated[
        Optional[str],
        Doc(
            """
            Help text for the subcommand.
            See [the tutorial about name and help](https://typer.tiangolo.com/tutorial/subcommands/name-and-help) for different ways of setting a command's help,
            and which one takes priority.
            """
        ),
    ] = Default(None),
    epilog: Annotated[
        Optional[str],
        Doc(
            """
            Text that will be printed right after the help text.
            """
        ),
    ] = Default(None),
    short_help: Annotated[
        Optional[str],
        Doc(
            """
            A shortened version of the help text that can be used e.g. in the help table listing subcommands.
            When not defined, the normal `help` text will be used instead.
            """
        ),
    ] = Default(None),
    options_metavar: Annotated[
        Optional[str],
        Doc(
            """
            In the example usage string of the help text for a command, the default placeholder for various arguments is `[OPTIONS]`.
            Set `options_metavar` to change this into a different string. When `None`, the default value will be used.
            """
        ),
    ] = Default(None),
    add_help_option: Annotated[
        bool,
        Doc(
            """
            **Note**: you probably shouldn't use this parameter, it is inherited
            from Click and supported for compatibility.

            ---

            By default each command registers a `--help` option. This can be disabled by this parameter.
            """
        ),
    ] = Default(True),
    hidden: Annotated[
        bool,
        Doc(
            """
            Hide this command from help outputs. `False` by default.
            """
        ),
    ] = Default(False),
    deprecated: Annotated[
        bool,
        Doc(
            """
            Mark this command as deprecated in the help outputs. `False` by default.
            """
        ),
    ] = False,
    # Rich settings
    rich_help_panel: Annotated[
        Union[str, None],
        Doc(
            """
            Set the panel name of the command when the help is printed with Rich.
            """
        ),
    ] = Default(None),
) -> None:
    """
    Add subcommands to the main app using `app.add_typer()`.
    Subcommands may be defined in separate modules, ensuring clean separation of code by functionality.

    Read more in the
    [Typer docs for SubCommands](https://typer.tiangolo.com/tutorial/subcommands/add-typer/).

    ## Example

    ```python
    import typer

    from .add import app as add_app
    from .delete import app as delete_app

    app = typer.Typer()

    app.add_typer(add_app)
    app.add_typer(delete_app)
    ```
    """
    self.registered_groups.append(
        TyperInfo(
            typer_instance,
            name=name,
            cls=cls,
            invoke_without_command=invoke_without_command,
            no_args_is_help=no_args_is_help,
            subcommand_metavar=subcommand_metavar,
            chain=chain,
            result_callback=result_callback,
            context_settings=context_settings,
            callback=callback,
            help=help,
            epilog=epilog,
            short_help=short_help,
            options_metavar=(
                options_metavar or self._info_val_str("options_metavar")
            ),
            add_help_option=add_help_option,
            hidden=hidden,
            deprecated=deprecated,
            rich_help_panel=rich_help_panel,
        )
    )