tyro


Nametyro JSON
Version 0.9.11 PyPI version JSON
download
home_pageNone
SummaryCLI interfaces & config objects, from types
upload_time2025-01-18 01:44:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
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 star count"
          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 star count"
          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 star count"
          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 star count"
          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 star count"
          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 star count"
          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 star count"
          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 star count"
          src="https://img.shields.io/github/stars/vwxyzjn/cleanrl?style=social"
        />
      </a>
    </td>
    <td>Single-file implementation of deep RL algorithms.</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:

- [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.
- [defopt](https://defopt.readthedocs.io/), which has similarly comprehensive type annotation support.
- [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.7",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "brentyi <brentyi@berkeley.edu>",
    "download_url": "https://files.pythonhosted.org/packages/57/b6/de48f7076518c4b698688371d3ea95636ccf69735fd13d20f8dc052d03d5/tyro-0.9.11.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(\n    foo: int,\n    bar: str = \"default\",\n) -> 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 star count\"\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 star count\"\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 star count\"\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 star count\"\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 star count\"\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 star count\"\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 star count\"\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 star count\"\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</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- [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- [defopt](https://defopt.readthedocs.io/), which has similarly comprehensive type annotation support.\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.11",
    "project_urls": {
        "GitHub": "https://github.com/brentyi/tyro"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30fb8e89431d455777804cefe9dc5bcf8d23564eb71862a51927f2c6d7d72fa6",
                "md5": "fed987fe136b110fa8173ccc79711073",
                "sha256": "57ffc2eae76e5466c9b84211a528c69812a809529e0202645960a466750e42c6"
            },
            "downloads": -1,
            "filename": "tyro-0.9.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fed987fe136b110fa8173ccc79711073",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 115500,
            "upload_time": "2025-01-18T01:44:10",
            "upload_time_iso_8601": "2025-01-18T01:44:10.703138Z",
            "url": "https://files.pythonhosted.org/packages/30/fb/8e89431d455777804cefe9dc5bcf8d23564eb71862a51927f2c6d7d72fa6/tyro-0.9.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57b6de48f7076518c4b698688371d3ea95636ccf69735fd13d20f8dc052d03d5",
                "md5": "22a2d32c5abad297f1089b6d56c2a06e",
                "sha256": "923cd08f903d969d01bca5304727b500b8ce21ed0c0e2eeb8acffde5f267daaa"
            },
            "downloads": -1,
            "filename": "tyro-0.9.11.tar.gz",
            "has_sig": false,
            "md5_digest": "22a2d32c5abad297f1089b6d56c2a06e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 244151,
            "upload_time": "2025-01-18T01:44:13",
            "upload_time_iso_8601": "2025-01-18T01:44:13.880105Z",
            "url": "https://files.pythonhosted.org/packages/57/b6/de48f7076518c4b698688371d3ea95636ccf69735fd13d20f8dc052d03d5/tyro-0.9.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-18 01:44:13",
    "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: 0.44234s