tyro#
tyro
is a tool for generating command-line interfaces and configuration
objects in Python.
Our core API, tyro.cli()
,
Generates CLI interfaces from a comprehensive set of Python type constructs.
Populates helptext automatically from defaults, annotations, and docstrings.
Understands nesting of
dataclasses
,pydantic
, andattrs
structures.Prioritizes static analysis for type checking and autocompletion with tools like Pylance, Pyright, and mypy.
For advanced users, it also supports:
Subcommands, as well as choosing between and overriding values in configuration objects.
Completion script generation for
bash
,zsh
, andtcsh
.Fine-grained configuration via PEP 529 runtime annotations (
tyro.conf.*
).
To get started, we recommend browsing the examples to the left.
Why tyro
?#
Strong typing.
Unlike tools dependent on dictionaries, YAML, or dynamic namespaces, arguments populated by
tyro
benefit from IDE and language server-supported operations — think tab completion, rename, jump-to-def, docstrings on hover — as well as static checking tools likepyright
andmypy
.Minimal overhead.
Standard Python type annotations, docstrings, and default values are parsed to automatically generate command-line interfaces with informative helptext.
tyro
works seamlessly with tools you already use: examples are included for dataclasses, attrs, pydantic, flax.linen, and more.Modularity.
tyro
supports hierarchical configuration structures, which make it easy to distribute definitions, defaults, and documentation of configurable fields across modules or source files.Tab completion.
By extending shtab,
tyro
automatically generates tab completion scripts for bash, zsh, and tcsh.