tyro

Generate command-line interfaces and config objects directly from Python type annotations.

Library
PyPI
v1.0.15
1,099stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
77/100Good
Development Activity80
Maintenance84
Community48
Maturity56
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture85
Code Quality88
Innovation86
Learning Curve80

Tyro turns type-annotated Python into fully-featured command-line interfaces with a single call to tyro.cli(). Standard type hints, docstrings, and default values are parsed to build argument parsers with rich helptext, nested structures, subcommands, and shell completion.

Because everything is driven by real types, arguments populated by tyro are understood by IDEs and static checkers like pyright and mypy. It works with plain functions, dataclasses, pydantic models, and attrs classes, making it equally suited to throwaway scripts and large, hierarchical configuration systems.

What You Get

  • A single tyro.cli() entry point that builds a full argument parser from any type-annotated function or class
  • Support for dataclasses, pydantic, attrs, TypedDicts, NamedTuples, and standard typing constructs
  • Automatic helptext generated from docstrings and field comments
  • Hierarchical/nested configs, unions as subcommands, and shell completion out of the box
  • Static-type-friendly output that works with pyright and mypy

Common Use Cases

  • Adding a typed CLI to a research or training script without boilerplate
  • Managing large, hierarchical experiment configurations across a project
  • Exposing dataclass or pydantic config objects as command-line arguments
  • Building subcommand-driven tools from union types

Under The Hood

Architecture - Tyro is organized around a single public entry point, tyro.cli(), in src/tyro/_cli.py, which delegates to a resolver (_resolver.py), a field-extraction layer (_fields.py), and parser construction (_parsers.py, _arguments.py). Type introspection walks annotations to build a tree of fields that is compiled into an argparse-based parser via pluggable backends under _backends/, then instantiated back into the original typed object during _calling.py. Tech Stack - Pure Python (>=3.8) with a small dependency footprint: typeguard, docstring-parser, and typing-extensions, plus eval_type_backport on older interpreters. It is built with hatchling and supports dataclasses, pydantic, attrs, and msgspec through dedicated constructor modules. Code Quality - The codebase is extensively tested, with over 200 test files under tests/ covering attrs, pydantic, subcommands, helptext snapshots, and version-specific behavior, alongside pyright, mypy, and ty type-checking in the dev toolchain and codecov coverage tracking. Internal modules are consistently underscore-prefixed to keep the public surface small. API Design - The developer experience is deliberately minimal: most use cases are a single tyro.cli(SomeType) call, with configuration exposed through a tyro.conf module and typed annotations rather than a large option surface, and thorough documentation plus an examples directory lower the barrier to adoption.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search