tyro


Nametyro JSON
Version 0.9.27 PyPI version JSON
download
home_pageNone
SummaryCLI interfaces & config objects, from types
upload_time2025-07-29 22:29:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br />
<p align="center">
    <!--
    This README will be used for both GitHub and PyPI. We therefore:
    - Keep all image URLs absolute.
    - In the GitHub action we use for publishing, strip some HTML tags that aren't supported by PyPI.
    -->
        <img alt="tyro logo" src="https://brentyi.github.io/tyro/_static/logo-light.svg" width="200px" />

</p>

<p align="center">
    <em><a href="https://brentyi.github.io/tyro">Documentation</a></em>
    &nbsp;&nbsp;&bull;&nbsp;&nbsp;
    <em><code>pip install tyro</code></em>
</p>

<p align="center">
    <!-- <img alt="build" src="https://github.com/brentyi/tyro/actions/workflows/build.yml/badge.svg" /> -->
    <img alt="mypy" src="https://github.com/brentyi/tyro/actions/workflows/mypy.yml/badge.svg" />
    <img alt="pyright" src="https://github.com/brentyi/tyro/actions/workflows/pyright.yml/badge.svg" />
    <!-- <img alt="ruff" src="https://github.com/brentyi/tyro/actions/workflows/ruff.yml/badge.svg" /> -->
    <a href="https://codecov.io/gh/brentyi/tyro">
        <img alt="codecov" src="https://codecov.io/gh/brentyi/tyro/branch/main/graph/badge.svg" />
    </a>
    <a href="https://pypi.org/project/tyro/">
        <img alt="codecov" src="https://img.shields.io/pypi/pyversions/tyro" />
    </a>
</p>

<br />

<strong><code>tyro.cli()</code></strong> is a tool for generating CLI
interfaces from type-annotated Python.

We can define configurable scripts using functions:

```python
"""A command-line interface defined using a function signature.

Usage: python script_name.py --foo INT [--bar STR]
"""

import tyro

def main(foo: int, bar: str = "default") -> None:
    ...  # Main body of a script.

if __name__ == "__main__":
    # Generate a CLI and call `main` with its two arguments: `foo` and `bar`.
    tyro.cli(main)
```

Or instantiate config objects defined using tools like `dataclasses`, `pydantic`, and `attrs`:

```python
"""A command-line interface defined using a class signature.

Usage: python script_name.py --foo INT [--bar STR]
"""

from dataclasses import dataclass
import tyro

@dataclass
class Config:
    foo: int
    bar: str = "default"

if __name__ == "__main__":
    # Generate a CLI and instantiate `Config` with its two arguments: `foo` and `bar`.
    config = tyro.cli(Config)

    # Rest of script.
    assert isinstance(config, Config)  # Should pass.
```

Other features include helptext generation, nested structures, subcommands, and
shell completion. For examples and the API reference, see our
[documentation](https://brentyi.github.io/tyro).

### Why `tyro`?

1. **Define things once.** Standard Python type annotations, docstrings, and default values are parsed to automatically generate command-line interfaces with informative helptext.

2. **Static types.** Unlike tools dependent on dictionaries, YAML, or dynamic
   namespaces, arguments populated by `tyro` benefit from IDE and language
   server-supported operations — tab completion, rename, jump-to-def,
   docstrings on hover — as well as static checking tools like `pyright` and
   `mypy`.

3. **Modularity.** `tyro` supports hierarchical configuration structures, which
   make it easy to decentralize definitions, defaults, and documentation.

### In the wild

`tyro` is designed to be lightweight enough for throwaway scripts, while
facilitating type safety and modularity for larger projects. Examples:

<table>
  <tr>
    <td>
      <a href="https://github.com/nerfstudio-project/nerfstudio/">
        nerfstudio-project/nerfstudio
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/nerfstudio-project/nerfstudio?style=social"
        />
      </a>
    </td>
    <td>
      Open-source tools for neural radiance fields.
    </td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/Sea-Snell/JAXSeq/">
        Sea-Snell/JAXSeq
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/Sea-Snell/JAXSeq?style=social"
        />
      </a>
    </td>
    <td>Train very large language models in Jax.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/kevinzakka/obj2mjcf">
        kevinzakka/obj2mjcf
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/kevinzakka/obj2mjcf?style=social"
        />
      </a>
    </td>
    <td>Interface for processing OBJ files for Mujoco.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/blurgyy/jaxngp">
        blurgyy/jaxngp
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/blurgyy/jaxngp?style=social"
        />
      </a>
    </td>
    <td>
      CUDA-accelerated implementation of
      <a href="https://nvlabs.github.io/instant-ngp/">instant-ngp</a>, in JAX.
    </td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/NVIDIAGameWorks/kaolin-wisp">
        NVIDIAGameWorks/kaolin-wisp
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/NVIDIAGameWorks/kaolin-wisp?style=social"
        />
      </a>
    </td>
    <td>PyTorch library for neural fields.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/autonomousvision/sdfstudio">
        autonomousvision/sdfstudio
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/autonomousvision/sdfstudio?style=social"
        />
      </a>
    </td>
    <td>Unified framework for surface reconstruction.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/openrlbenchmark/openrlbenchmark">
        openrlbenchmark/openrlbenchmark
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/openrlbenchmark/openrlbenchmark?style=social"
        />
      </a>
    </td>
    <td>Collection of tracked experiments for reinforcement learning.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/vwxyzjn/cleanrl">
        vwxyzjn/cleanrl
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/vwxyzjn/cleanrl?style=social"
        />
      </a>
    </td>
    <td>Single-file implementation of deep RL algorithms.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/pytorch-labs/LeanRL/">
        pytorch-labs/LeanRL
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/pytorch-labs/LeanRL?style=social"
        />
      </a>
    </td>
    <td>Fork of CleanRL, optimized using PyTorch 2 features.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/pytorch/torchtitan">
        pytorch/torchtitan
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/pytorch/torchtitan?style=social"
        />
      </a>
    </td>
    <td>PyTorch-native platform for training generative AI models.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/KwaiVGI/LivePortrait">
        KwaiVGI/LivePortrait
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/KwaiVGI/LivePortrait?style=social"
        />
      </a>
    </td>
    <td>Stitching and retargeting for portraits.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/Physical-Intelligence/openpi/">
        Physical-Intelligence/openpi
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/Physical-Intelligence/openpi?style=social"
        />
      </a>
    </td>
    <td>Open-source models for robotics.</td>
  </tr>
  <tr>
    <td>
      <a href="https://github.com/MalcolmMielle/bark_monitor">
        MalcolmMielle/bark_monitor
        <br /><img
          alt="GitHub stars"
          src="https://img.shields.io/github/stars/MalcolmMielle/bark_monitor?style=social"
        />
      </a>
    </td>
    <td>Show your neighbor that your dog doesn't bark!</td>
  </tr>
</table>

### Alternatives

`tyro` is an opinionated library. If any design decisions don't make sense,
feel free to file an issue!

You might also consider one of many alternative libraries. Some that we
particularly like:

- [cyclopts](https://github.com/BrianPugh/cyclopts) and
  [defopt](https://defopt.readthedocs.io/), which have very comprehensive type
  annotation support and a heavier emphasis on subcommand generation.
- [simple-parsing](https://github.com/lebrice/SimpleParsing) and
  [jsonargparse](https://github.com/omni-us/jsonargparse), which provide deeper
  integration with configuration file formats like YAML and JSON.
- [clipstick](https://github.com/sander76/clipstick), which focuses on
  simplicity + generating CLIs from Pydantic models.
- [datargs](https://github.com/roee30/datargs), which provides a minimal API for
  dataclasses.
- [fire](https://github.com/google/python-fire) and
  [clize](https://github.com/epsy/clize), which support arguments without type
  annotations.

We also have some notes on `tyro`'s design goals and other alternatives in the
docs [here](https://brentyi.github.io/tyro/goals_and_alternatives/).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tyro",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "brentyi <brentyi@berkeley.edu>",
    "download_url": "https://files.pythonhosted.org/packages/48/4b/c2b5e9b497bdd03fbf78f1fb83da621e6609d6a764ea0c34f9486dcc3e95/tyro-0.9.27.tar.gz",
    "platform": null,
    "description": "<br />\n<p align=\"center\">\n    <!--\n    This README will be used for both GitHub and PyPI. We therefore:\n    - Keep all image URLs absolute.\n    - In the GitHub action we use for publishing, strip some HTML tags that aren't supported by PyPI.\n    -->\n        <img alt=\"tyro logo\" src=\"https://brentyi.github.io/tyro/_static/logo-light.svg\" width=\"200px\" />\n\n</p>\n\n<p align=\"center\">\n    <em><a href=\"https://brentyi.github.io/tyro\">Documentation</a></em>\n    &nbsp;&nbsp;&bull;&nbsp;&nbsp;\n    <em><code>pip install tyro</code></em>\n</p>\n\n<p align=\"center\">\n    <!-- <img alt=\"build\" src=\"https://github.com/brentyi/tyro/actions/workflows/build.yml/badge.svg\" /> -->\n    <img alt=\"mypy\" src=\"https://github.com/brentyi/tyro/actions/workflows/mypy.yml/badge.svg\" />\n    <img alt=\"pyright\" src=\"https://github.com/brentyi/tyro/actions/workflows/pyright.yml/badge.svg\" />\n    <!-- <img alt=\"ruff\" src=\"https://github.com/brentyi/tyro/actions/workflows/ruff.yml/badge.svg\" /> -->\n    <a href=\"https://codecov.io/gh/brentyi/tyro\">\n        <img alt=\"codecov\" src=\"https://codecov.io/gh/brentyi/tyro/branch/main/graph/badge.svg\" />\n    </a>\n    <a href=\"https://pypi.org/project/tyro/\">\n        <img alt=\"codecov\" src=\"https://img.shields.io/pypi/pyversions/tyro\" />\n    </a>\n</p>\n\n<br />\n\n<strong><code>tyro.cli()</code></strong> is a tool for generating CLI\ninterfaces from type-annotated Python.\n\nWe can define configurable scripts using functions:\n\n```python\n\"\"\"A command-line interface defined using a function signature.\n\nUsage: python script_name.py --foo INT [--bar STR]\n\"\"\"\n\nimport tyro\n\ndef main(foo: int, bar: str = \"default\") -> None:\n    ...  # Main body of a script.\n\nif __name__ == \"__main__\":\n    # Generate a CLI and call `main` with its two arguments: `foo` and `bar`.\n    tyro.cli(main)\n```\n\nOr instantiate config objects defined using tools like `dataclasses`, `pydantic`, and `attrs`:\n\n```python\n\"\"\"A command-line interface defined using a class signature.\n\nUsage: python script_name.py --foo INT [--bar STR]\n\"\"\"\n\nfrom dataclasses import dataclass\nimport tyro\n\n@dataclass\nclass Config:\n    foo: int\n    bar: str = \"default\"\n\nif __name__ == \"__main__\":\n    # Generate a CLI and instantiate `Config` with its two arguments: `foo` and `bar`.\n    config = tyro.cli(Config)\n\n    # Rest of script.\n    assert isinstance(config, Config)  # Should pass.\n```\n\nOther features include helptext generation, nested structures, subcommands, and\nshell completion. For examples and the API reference, see our\n[documentation](https://brentyi.github.io/tyro).\n\n### Why `tyro`?\n\n1. **Define things once.** Standard Python type annotations, docstrings, and default values are parsed to automatically generate command-line interfaces with informative helptext.\n\n2. **Static types.** Unlike tools dependent on dictionaries, YAML, or dynamic\n   namespaces, arguments populated by `tyro` benefit from IDE and language\n   server-supported operations \u2014 tab completion, rename, jump-to-def,\n   docstrings on hover \u2014 as well as static checking tools like `pyright` and\n   `mypy`.\n\n3. **Modularity.** `tyro` supports hierarchical configuration structures, which\n   make it easy to decentralize definitions, defaults, and documentation.\n\n### In the wild\n\n`tyro` is designed to be lightweight enough for throwaway scripts, while\nfacilitating type safety and modularity for larger projects. Examples:\n\n<table>\n  <tr>\n    <td>\n      <a href=\"https://github.com/nerfstudio-project/nerfstudio/\">\n        nerfstudio-project/nerfstudio\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/nerfstudio-project/nerfstudio?style=social\"\n        />\n      </a>\n    </td>\n    <td>\n      Open-source tools for neural radiance fields.\n    </td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/Sea-Snell/JAXSeq/\">\n        Sea-Snell/JAXSeq\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/Sea-Snell/JAXSeq?style=social\"\n        />\n      </a>\n    </td>\n    <td>Train very large language models in Jax.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/kevinzakka/obj2mjcf\">\n        kevinzakka/obj2mjcf\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/kevinzakka/obj2mjcf?style=social\"\n        />\n      </a>\n    </td>\n    <td>Interface for processing OBJ files for Mujoco.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/blurgyy/jaxngp\">\n        blurgyy/jaxngp\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/blurgyy/jaxngp?style=social\"\n        />\n      </a>\n    </td>\n    <td>\n      CUDA-accelerated implementation of\n      <a href=\"https://nvlabs.github.io/instant-ngp/\">instant-ngp</a>, in JAX.\n    </td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/NVIDIAGameWorks/kaolin-wisp\">\n        NVIDIAGameWorks/kaolin-wisp\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/NVIDIAGameWorks/kaolin-wisp?style=social\"\n        />\n      </a>\n    </td>\n    <td>PyTorch library for neural fields.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/autonomousvision/sdfstudio\">\n        autonomousvision/sdfstudio\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/autonomousvision/sdfstudio?style=social\"\n        />\n      </a>\n    </td>\n    <td>Unified framework for surface reconstruction.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/openrlbenchmark/openrlbenchmark\">\n        openrlbenchmark/openrlbenchmark\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/openrlbenchmark/openrlbenchmark?style=social\"\n        />\n      </a>\n    </td>\n    <td>Collection of tracked experiments for reinforcement learning.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/vwxyzjn/cleanrl\">\n        vwxyzjn/cleanrl\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/vwxyzjn/cleanrl?style=social\"\n        />\n      </a>\n    </td>\n    <td>Single-file implementation of deep RL algorithms.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/pytorch-labs/LeanRL/\">\n        pytorch-labs/LeanRL\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/pytorch-labs/LeanRL?style=social\"\n        />\n      </a>\n    </td>\n    <td>Fork of CleanRL, optimized using PyTorch 2 features.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/pytorch/torchtitan\">\n        pytorch/torchtitan\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/pytorch/torchtitan?style=social\"\n        />\n      </a>\n    </td>\n    <td>PyTorch-native platform for training generative AI models.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/KwaiVGI/LivePortrait\">\n        KwaiVGI/LivePortrait\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/KwaiVGI/LivePortrait?style=social\"\n        />\n      </a>\n    </td>\n    <td>Stitching and retargeting for portraits.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/Physical-Intelligence/openpi/\">\n        Physical-Intelligence/openpi\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/Physical-Intelligence/openpi?style=social\"\n        />\n      </a>\n    </td>\n    <td>Open-source models for robotics.</td>\n  </tr>\n  <tr>\n    <td>\n      <a href=\"https://github.com/MalcolmMielle/bark_monitor\">\n        MalcolmMielle/bark_monitor\n        <br /><img\n          alt=\"GitHub stars\"\n          src=\"https://img.shields.io/github/stars/MalcolmMielle/bark_monitor?style=social\"\n        />\n      </a>\n    </td>\n    <td>Show your neighbor that your dog doesn't bark!</td>\n  </tr>\n</table>\n\n### Alternatives\n\n`tyro` is an opinionated library. If any design decisions don't make sense,\nfeel free to file an issue!\n\nYou might also consider one of many alternative libraries. Some that we\nparticularly like:\n\n- [cyclopts](https://github.com/BrianPugh/cyclopts) and\n  [defopt](https://defopt.readthedocs.io/), which have very comprehensive type\n  annotation support and a heavier emphasis on subcommand generation.\n- [simple-parsing](https://github.com/lebrice/SimpleParsing) and\n  [jsonargparse](https://github.com/omni-us/jsonargparse), which provide deeper\n  integration with configuration file formats like YAML and JSON.\n- [clipstick](https://github.com/sander76/clipstick), which focuses on\n  simplicity + generating CLIs from Pydantic models.\n- [datargs](https://github.com/roee30/datargs), which provides a minimal API for\n  dataclasses.\n- [fire](https://github.com/google/python-fire) and\n  [clize](https://github.com/epsy/clize), which support arguments without type\n  annotations.\n\nWe also have some notes on `tyro`'s design goals and other alternatives in the\ndocs [here](https://brentyi.github.io/tyro/goals_and_alternatives/).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "CLI interfaces & config objects, from types",
    "version": "0.9.27",
    "project_urls": {
        "GitHub": "https://github.com/brentyi/tyro"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "36ef98b2700c6a262a9d78eaec5b16916a75a63f7c1e642cfce0717c440d2f9b",
                "md5": "96bfe641626f01491c702813a7bb572c",
                "sha256": "f51655c45be6ba297af47cfc04622287422177448a060ffbec0f5fa905046f41"
            },
            "downloads": -1,
            "filename": "tyro-0.9.27-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "96bfe641626f01491c702813a7bb572c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 129003,
            "upload_time": "2025-07-29T22:29:48",
            "upload_time_iso_8601": "2025-07-29T22:29:48.629461Z",
            "url": "https://files.pythonhosted.org/packages/36/ef/98b2700c6a262a9d78eaec5b16916a75a63f7c1e642cfce0717c440d2f9b/tyro-0.9.27-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "484bc2b5e9b497bdd03fbf78f1fb83da621e6609d6a764ea0c34f9486dcc3e95",
                "md5": "8ebb66da16507ac6a8b6f8538986a0fb",
                "sha256": "f7b16340bc07b1eeb0a06880c9fcdddf0cfd084fbad40baf3072361c5a63b268"
            },
            "downloads": -1,
            "filename": "tyro-0.9.27.tar.gz",
            "has_sig": false,
            "md5_digest": "8ebb66da16507ac6a8b6f8538986a0fb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 307477,
            "upload_time": "2025-07-29T22:29:50",
            "upload_time_iso_8601": "2025-07-29T22:29:50.018449Z",
            "url": "https://files.pythonhosted.org/packages/48/4b/c2b5e9b497bdd03fbf78f1fb83da621e6609d6a764ea0c34f9486dcc3e95/tyro-0.9.27.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-29 22:29:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "brentyi",
    "github_project": "tyro",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tyro"
}
        
Elapsed time: 1.51625s