tyro#

Build status icon Lint status icon Mypy status icon Mypy status icon Test coverage status icon Version icon

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, and attrs 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, and tcsh.

  • Fine-grained configuration via PEP 529 runtime annotations (tyro.conf.*).

To get started, we recommend browsing the examples to the left.

Why tyro?#

  1. 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 like pyright and mypy.

  2. 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.

    Hate tyro? Just remove one line of code, and you’re left with beautiful, type-annotated, and documented vanilla Python that can be used with a range of other configuration libraries.

  3. Modularity.

    tyro supports hierarchical configuration structures, which make it easy to distribute definitions, defaults, and documentation of configurable fields across modules or source files.

  4. Tab completion.

    By extending shtab, tyro automatically generates tab completion scripts for bash, zsh, and tcsh.