Strongly typed, zero-effort CLI interfaces
Reason this release was yanked:
https://github.com/nerfstudio-project/nerfstudio/issues/882#issuecomment-1301148363
Project description
Documentation
•
pip install tyro
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
?
-
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.
If you're familiar with type annotations and docstrings in Python, you already know how to use
tyro
! If you're not, learning to usetyro
reduces to learning to write modern Python.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. -
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.
In the wild
tyro
is still a new library, but being stress tested in several projects!
- nerfstudio-project/nerfstudio provides a set of tools for end-to-end training, testing, and rendering of neural radiance fields.
- Sea-Snell/JAXSeq is a library for distributed training of large language models in JAX.
- kevinzakka/obj2mjcf is an interface for processing composite Wavefront OBJ files for Mujoco.
- brentyi/tensorf-jax is an unofficial implementation of Tensorial Radiance Fields in JAX.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tyro-0.3.28.tar.gz
.
File metadata
- Download URL: tyro-0.3.28.tar.gz
- Upload date:
- Size: 46.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d47c714348209957111fb07f02beabb7a4b89614fe5ea7a5d6ed1d3cfb48b79 |
|
MD5 | 1e04d4c7bac390d0c7cbeab30b0dbca9 |
|
BLAKE2b-256 | 235930ff53db19167c648c48c732e2c8fa6e162eccab98a38db6fad9c18c2c97 |
File details
Details for the file tyro-0.3.28-py3-none-any.whl
.
File metadata
- Download URL: tyro-0.3.28-py3-none-any.whl
- Upload date:
- Size: 52.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb6265e5a0e38863e1507b5fa50a3f2e9aaabd111bd5b50baf16c9680823833f |
|
MD5 | 00a66d4fd6b433754226fa8a77fc4c59 |
|
BLAKE2b-256 | f2926170a3a3427ec14194c803263a4ccafea9a25cc8034f66e932336fe6a824 |