Usage

1
2
# Run help
!python src.py -h
usage: pytest [-h] [-k KW1] [-w] param1 param2

Example function with types documented in the docstring.

positional arguments:
  param1             The first parameter.
  param2             The second parameter.

optional arguments:
  -h, --help         show this help message and exit
  -k KW1, --kw1 KW1  this is optional parameter. (default: None)
  -w, --kw2          this is boolean. setting flag sets True. (default: False)

1
2
# ran with both positional arguments
!python src.py 10 p2
_namespace_ (<class 'argparse.Namespace'>): [('__func_0', '_dispatch'), ('__level__', 0), ('kw1', None), ('kw2', False), ('param1', 10), ('param2', 'p2')]
kw1 (<class 'NoneType'>): None
kw2 (<class 'bool'>): False
param1 (<class 'int'>): 10
param2 (<class 'str'>): p2

1
2
#  ran empty
!python src.py
usage: pytest [-h] [-k KW1] [-w] param1 param2
pytest: error: the following arguments are required: param1, param2

1
2
# ran with invalid option
!python src.py --invalid
usage: pytest [-h] [-k KW1] [-w] param1 param2
pytest: error: the following arguments are required: param1, param2

1
2
# ran with invalid type
!python src.py p1 p2
usage: pytest [-h] [-k KW1] [-w] param1 param2
pytest: error: argument param1: invalid int value: 'p1'