Strongly typed, zero-effort CLI interfaces
Project description
Documentation
•
pip install tyro
tyro is a library for building CLI interfaces,
configuration objects, and configuration systems with modern, type-annotated
Python.
Our core interface consists of just one function, tyro.cli(), that translates
Python callables and types into fully-featured argument parsers and
configuration objects.
To get started, we recommend visiting the examples in our documentation.
Why tyro?
-
Strong typing.
Unlike tools dependent on dictionaries, YAML, or dynamic namespaces, arguments populated by
tyrobenefit from IDE and language server-supported operations — think tab completion, rename, jump-to-def, docstrings on hover — as well as static checking tools likepyrightandmypy. -
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 usetyroreduces 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.
tyrosupports 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,
tyroautomatically generates tab completion scripts for bash, zsh, and tcsh.
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tyro-0.3.26.tar.gz.
File metadata
- Download URL: tyro-0.3.26.tar.gz
- Upload date:
- Size: 56.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a221e6389775969efc468baf5222a7a8cab99dd11b7205cf3684877678d91389
|
|
| MD5 |
da101a6cc888fa699788fbd94b991050
|
|
| BLAKE2b-256 |
94897d39a7c12b04b855d65bd93ad458ac9a1751d43e8c6cec4e81e63eeb39fc
|
File details
Details for the file tyro-0.3.26-py3-none-any.whl.
File metadata
- Download URL: tyro-0.3.26-py3-none-any.whl
- Upload date:
- Size: 63.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.14 Linux/5.15.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e81273e1a6777b495aef379cdf509d77a5fb3b574145e31b15b3a4608019421f
|
|
| MD5 |
7e2e82d5026585453b25debd313f6f48
|
|
| BLAKE2b-256 |
40194bf056de3fb60a4c2c757f2133556ba96385afcada1ccc1e54df3bcfc84d
|