Functions#

In the simplest case, tyro.cli() can be used to run a function with arguments populated from the CLI.

 1import tyro
 2
 3
 4def main(
 5    field1: str,
 6    field2: int = 3,
 7) -> None:
 8    """Function, whose arguments will be populated from a CLI interface.
 9
10    Args:
11        field1: A string field.
12        field2: A numeric field, with a default value.
13    """
14    print(field1, field2)
15
16
17if __name__ == "__main__":
18    tyro.cli(main)

python 01_basics/01_functions.py --help
usage: 01_functions.py [-h] --field1 STR [--field2 INT]

Function, whose arguments will be populated from a CLI interface.

╭─ options ───────────────────────────────────────────────────────────────╮
│ -h, --help          show this help message and exit                     │
│ --field1 STR        A string field. (required)                          │
│ --field2 INT        A numeric field, with a default value. (default: 3) │
╰─────────────────────────────────────────────────────────────────────────╯

python 01_basics/01_functions.py --field1 hello
hello 3

python 01_basics/01_functions.py --field1 hello --field2 10
hello 10