# tyro |coverage| |nbsp| |downloads| |nbsp| |versions| :func:`tyro.cli()` is a tool for generating CLI interfaces from type-annotated Python. We can define configurable scripts using functions:
script.py
# Write standard Python
from typing import Literal

def main(
    name: str,
    greet: Literal["Hello", "Hi"] = "Hi",
) -> None:
    """Print a greeting."""
    print(f"{greet}, {name}!")

# Call tyro.cli()
if __name__ == "__main__":
    import tyro
    tyro.cli(main)
Terminal
# tyro CLI
$ python script.py --help
usage: script.py [-h] [OPTIONS]

Print a greeting.

╭─ options ──────────────────────────────╮
│ -h, --help         show help message   │
│ --name STR         (required)          │
│ --greet {Hello,Hi} (default: Hi)       │
╰────────────────────────────────────────╯

$ python script.py --name World
Hi, World!
Or using structures like dataclasses:
script.py
# Write standard Python
from dataclasses import dataclass
from typing import Literal

@dataclass
class Args:
    """Configure a greeting."""
    name: str
    greet: Literal["Hello", "Hi"] = "Hi"

# Call tyro.cli()
if __name__ == "__main__":
    import tyro
    args = tyro.cli(Args)
    print(f"{args.greet}, {args.name}!")
Terminal
# tyro CLI
$ python script.py --help
usage: script.py [-h] [OPTIONS]

Configure a greeting.

╭─ options ──────────────────────────────╮
│ -h, --help         show help message   │
│ --name STR         (required)          │
│ --greet {Hello,Hi} (default: Hi)       │
╰────────────────────────────────────────╯

$ python script.py --name World
Hi, World!
Other features include helptext generation, nested structures, subcommands, and shell completion. #### Why `tyro`? 1. **Define things once.** Standard Python type annotations, docstrings, and default values are parsed to automatically generate command-line interfaces with nice helptext. 2. **Static types.** Unlike tools dependent on dictionaries, YAML, or dynamic namespaces, arguments populated by `tyro` are better undestood by IDEs and language servers, as well as static checking tools like `pyright` and `mypy`. 3. **Modularity.** `tyro` supports hierarchical configurations, which make it easy to decentralize definitions, defaults, and documentation. .. toctree:: :caption: Getting started :hidden: :maxdepth: 1 :titlesonly: installation your_first_cli whats_supported .. toctree:: :caption: Examples :hidden: :titlesonly: ./examples/basics.rst ./examples/hierarchical_structures.rst ./examples/subcommands.rst ./examples/overriding_configs.rst ./examples/generics.rst ./examples/custom_constructors.rst ./examples/pytorch_jax.rst .. toctree:: :caption: Notes :hidden: :maxdepth: 5 :glob: goals_and_alternatives helptext_generation tab_completion wandb_sweeps .. toctree:: :caption: API Reference :hidden: :maxdepth: 5 :titlesonly: api/tyro/index .. |downloads| image:: https://static.pepy.tech/personalized-badge/tyro?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=GREEN&left_text=downloads :alt: Download count icon :target: https://pypi.org/project/tyro/ .. |coverage| image:: https://codecov.io/gh/brentyi/tyro/branch/main/graph/badge.svg :alt: Test coverage status icon :target: https://codecov.io/gh/brentyi/tyro .. |versions| image:: https://img.shields.io/pypi/pyversions/tyro :alt: Version icon :target: https://pypi.org/project/tyro/ .. |nbsp| unicode:: 0xA0 :trim: