Tyro

1.0.12 · active · verified Fri Apr 10

Tyro is a Python library that generates command-line interfaces (CLIs) and configuration objects directly from standard Python type annotations, docstrings, and default values. It simplifies CLI creation by reducing boilerplate, improving IDE support, and enabling static type checking, acting as a lightweight wrapper around `argparse`. The current version is 1.0.12, and it follows a frequent, point-release cadence.

Warnings

Install

Imports

Quickstart

This example defines a command-line interface using a dataclass. Tyro automatically generates arguments, help text, and parses values from the command line based on the type annotations and docstrings, then populates an instance of `Args`.

from dataclasses import dataclass
import tyro

@dataclass
class Args:
    """Configure a greeting."""
    name: str
    greet: str = "Hi" # Default value

if __name__ == "__main__":
    # From command line:
    # python your_script.py --name World
    # Or: python your_script.py --name World --greet Hello
    args = tyro.cli(Args)
    print(f"{args.greet}, {args.name}!")

view raw JSON →