Skip to main content

Strongly typed, zero-effort CLI interfaces

Project description


tyro logo

Documentation   •   pip install tyro

build mypy lint codecov codecov


tyro is a library for building CLI interfaces and configuration objects with type-annotated Python.

Our core interface consists of one function, tyro.cli(), that generates argument parsers from Python callables and types.

A minimal example

As a replacement for argparse:

with argparse with tyro
"""Sum two numbers from argparse."""

import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
    "--a",
    type=int,
    required=True,
)
parser.add_argument(
    "--b",
    type=int,
    default=3,
)
args = parser.parse_args()

print(args.a + args.b)
"""Sum two numbers by calling a
function with tyro."""

import tyro

def main(a: int, b: int = 3) -> None:
    print(a + b)

tyro.cli(main)

"""Sum two numbers by instantiating
a dataclass with tyro."""

from dataclasses import dataclass

import tyro

@dataclass
class Args:
    a: int
    b: int = 3

args = tyro.cli(Args)
print(args.a + args.b)

For more examples, see our documentation.

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.

In the wild

tyro is still a new library, but being stress tested in several projects!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tyro-0.3.33.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

tyro-0.3.33-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file tyro-0.3.33.tar.gz.

File metadata

  • Download URL: tyro-0.3.33.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1022-azure

File hashes

Hashes for tyro-0.3.33.tar.gz
Algorithm Hash digest
SHA256 0a8144ff08ccfcd883b69c8cbb58cb1aa42a6304b5329137312f5ff809f11fa8
MD5 ee608d50cf6471edfa6f6c41b3702044
BLAKE2b-256 0a74744592bef6d2b517bd287e8982919c972ff8fc4fd1848a227041afb8d339

See more details on using hashes here.

File details

Details for the file tyro-0.3.33-py3-none-any.whl.

File metadata

  • Download URL: tyro-0.3.33-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1022-azure

File hashes

Hashes for tyro-0.3.33-py3-none-any.whl
Algorithm Hash digest
SHA256 e85047ee68a8ceb0baaf59732100862742f9c9d9130b57a0153772ae85da1e37
MD5 a32fae7f8f680f5ba0e78cd634a9a994
BLAKE2b-256 593d573ce674f0d6c0de73b9245dfc50a95576b8de19ac47bed3b37686f2bc70

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page