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.
pip install tyroVerified import paths — ran on the pinned version, not inferred.
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`.
Refer to the official documentation on 'What's supported' and 'Argument Prefixing' for `tyro`'s specific interpretation of type hints and argument parsing. Upgrade to the latest version (>=1.0.12) for bug fixes related to `nargs` and positional arguments.
Consider using `tyro.conf.OmitSubcommandPrefixes` on your dataclass or `prefix_name=False` in `tyro.conf.arg()` to shorten argument names where appropriate. For `Union` types defining subcommands, `tyro.conf.subcommand(name='...')` can customize the subcommand name directly.
Refactor code to pass configuration markers as a tuple to `tyro.cli(YourConfig, config=(tyro.conf.Marker,))` instead of using the `@tyro.conf.configure` decorator.