sphinxcontrib-typer


Namesphinxcontrib-typer JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://sphinxcontrib-typer.readthedocs.io
SummaryAuto generate docs for typer commands.
upload_time2024-10-14 04:20:38
maintainerNone
docs_urlNone
authorBrian Kohan
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PyPI version](https://badge.fury.io/py/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer/)
[![PyPI status](https://img.shields.io/pypi/status/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer)
[![Documentation Status](https://readthedocs.org/projects/sphinxcontrib-typer/badge/?version=latest)](http://sphinxcontrib-typer.readthedocs.io/?badge=latest/)
[![Code Cov](https://codecov.io/gh/sphinx-contrib/typer/branch/main/graph/badge.svg?token=0IZOKN2DYL)](https://app.codecov.io/gh/sphinx-contrib/typer)
[![Test Status](https://github.com/sphinx-contrib/typer/workflows/test/badge.svg)](https://github.com/sphinx-contrib/typer/actions/workflows/test.yml)
[![Lint Status](https://github.com/sphinx-contrib/typer/workflows/lint/badge.svg)](https://github.com/sphinx-contrib/typer/actions/workflows/lint.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

# sphinxcontrib-typer

A Sphinx directive for auto generating docs for [Typer](https://typer.tiangolo.com/) 
(and [Click](https://click.palletsprojects.com/) commands!) using the rich console
formatting available in [Typer](https://typer.tiangolo.com/). This package generates
concise command documentation in text, html or svg formats out of the box, but if your
goal is to greatly customize the generated documentation
[sphinx-click](https://sphinx-click.readthedocs.io/en/latest/) may be more appropriate
and will also work for [Typer](https://typer.tiangolo.com/) commands.

## Installation

Install with pip::

    pip install sphinxcontrib-typer

Add ``sphinxcontrib.typer`` to your ``conf.py`` file:

```python
# be sure that the commands you want to document are importable
# from the python path when building the docs
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / '../path/to/your/commands'))

extensions = [
    ...
    'sphinxcontrib.typer',
    ...
]
```

## Usage

Say you have a command in the file ``examples/example.py`` that looks like
this:

```python
import typer
import typing as t

app = typer.Typer(add_completion=False)

@app.callback()
def callback(
    flag1: bool = typer.Option(False, help="Flag 1."),
    flag2: bool = typer.Option(False, help="Flag 2.")
):
    """This is the callback function."""
    pass


@app.command()
def foo(
    name: str = typer.Option(..., help="The name of the item to foo.")
):
    """This is the foo command."""
    pass


@app.command()
def bar(
    names: t.List[str] = typer.Option(..., help="The names of the items to bar."),
):
    """This is the bar command."""
    pass


if __name__ == "__main__":
    app()
```

You can generate documentation for this command using the ``typer`` directive
like so:

```rst
.. typer:: examples.example.app
    :prog: example1
    :width: 70
    :preferred: html
```

This would generate html that looks like this:

![Example PNG](https://raw.githubusercontent.com/sphinx-contrib/typer/main/example.html.png)

You could change ``:preferred:`` to svg, to generate svg instead:

![Example SVG](https://raw.githubusercontent.com/sphinx-contrib/typer/main/example.svg)

|

Or to text
                                                                                            
    Usage: example [OPTIONS] COMMAND [ARGS]...                                                  
                                                                                                
    This is the callback function.                                                              
                                                                                                
    ╭─ Options ──────────────────────────────────────────────────────────╮
    │ --flag1    --no-flag1      Flag 1. [default: no-flag1]             │
    │ --flag2    --no-flag2      Flag 2. [default: no-flag2]             │
    │ --help                     Show this message and exit.             │
    ╰────────────────────────────────────────────────────────────────────╯
    ╭─ Commands ─────────────────────────────────────────────────────────╮
    │ bar           This is the bar command.                             │
    │ foo           This is the foo command.                             │
    ╰────────────────────────────────────────────────────────────────────╯


The ``typer`` directive has options for generating docs for all subcommands as well
and optionally generating independent sections for each. There are also mechanisms
for passing options to the underlying console and svg generation functions. See the
official documentation for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://sphinxcontrib-typer.readthedocs.io",
    "name": "sphinxcontrib-typer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Brian Kohan",
    "author_email": "bckohan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/eb/695758b1a85c35c8b7222039d939eeaef68dcb575941c6f1fbe18c14c7c0/sphinxcontrib_typer-0.5.1.tar.gz",
    "platform": null,
    "description": "\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![PyPI version](https://badge.fury.io/py/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer/)\n[![PyPI status](https://img.shields.io/pypi/status/sphinxcontrib-typer.svg)](https://pypi.python.org/pypi/sphinxcontrib-typer)\n[![Documentation Status](https://readthedocs.org/projects/sphinxcontrib-typer/badge/?version=latest)](http://sphinxcontrib-typer.readthedocs.io/?badge=latest/)\n[![Code Cov](https://codecov.io/gh/sphinx-contrib/typer/branch/main/graph/badge.svg?token=0IZOKN2DYL)](https://app.codecov.io/gh/sphinx-contrib/typer)\n[![Test Status](https://github.com/sphinx-contrib/typer/workflows/test/badge.svg)](https://github.com/sphinx-contrib/typer/actions/workflows/test.yml)\n[![Lint Status](https://github.com/sphinx-contrib/typer/workflows/lint/badge.svg)](https://github.com/sphinx-contrib/typer/actions/workflows/lint.yml)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n# sphinxcontrib-typer\n\nA Sphinx directive for auto generating docs for [Typer](https://typer.tiangolo.com/) \n(and [Click](https://click.palletsprojects.com/) commands!) using the rich console\nformatting available in [Typer](https://typer.tiangolo.com/). This package generates\nconcise command documentation in text, html or svg formats out of the box, but if your\ngoal is to greatly customize the generated documentation\n[sphinx-click](https://sphinx-click.readthedocs.io/en/latest/) may be more appropriate\nand will also work for [Typer](https://typer.tiangolo.com/) commands.\n\n## Installation\n\nInstall with pip::\n\n    pip install sphinxcontrib-typer\n\nAdd ``sphinxcontrib.typer`` to your ``conf.py`` file:\n\n```python\n# be sure that the commands you want to document are importable\n# from the python path when building the docs\nimport sys\nfrom pathlib import Path\nsys.path.insert(0, str(Path(__file__).parent / '../path/to/your/commands'))\n\nextensions = [\n    ...\n    'sphinxcontrib.typer',\n    ...\n]\n```\n\n## Usage\n\nSay you have a command in the file ``examples/example.py`` that looks like\nthis:\n\n```python\nimport typer\nimport typing as t\n\napp = typer.Typer(add_completion=False)\n\n@app.callback()\ndef callback(\n    flag1: bool = typer.Option(False, help=\"Flag 1.\"),\n    flag2: bool = typer.Option(False, help=\"Flag 2.\")\n):\n    \"\"\"This is the callback function.\"\"\"\n    pass\n\n\n@app.command()\ndef foo(\n    name: str = typer.Option(..., help=\"The name of the item to foo.\")\n):\n    \"\"\"This is the foo command.\"\"\"\n    pass\n\n\n@app.command()\ndef bar(\n    names: t.List[str] = typer.Option(..., help=\"The names of the items to bar.\"),\n):\n    \"\"\"This is the bar command.\"\"\"\n    pass\n\n\nif __name__ == \"__main__\":\n    app()\n```\n\nYou can generate documentation for this command using the ``typer`` directive\nlike so:\n\n```rst\n.. typer:: examples.example.app\n    :prog: example1\n    :width: 70\n    :preferred: html\n```\n\nThis would generate html that looks like this:\n\n![Example PNG](https://raw.githubusercontent.com/sphinx-contrib/typer/main/example.html.png)\n\nYou could change ``:preferred:`` to svg, to generate svg instead:\n\n![Example SVG](https://raw.githubusercontent.com/sphinx-contrib/typer/main/example.svg)\n\n|\n\nOr to text\n                                                                                            \n    Usage: example [OPTIONS] COMMAND [ARGS]...                                                  \n                                                                                                \n    This is the callback function.                                                              \n                                                                                                \n    \u256d\u2500 Options \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n    \u2502 --flag1    --no-flag1      Flag 1. [default: no-flag1]             \u2502\n    \u2502 --flag2    --no-flag2      Flag 2. [default: no-flag2]             \u2502\n    \u2502 --help                     Show this message and exit.             \u2502\n    \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n    \u256d\u2500 Commands \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n    \u2502 bar           This is the bar command.                             \u2502\n    \u2502 foo           This is the foo command.                             \u2502\n    \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\n\nThe ``typer`` directive has options for generating docs for all subcommands as well\nand optionally generating independent sections for each. There are also mechanisms\nfor passing options to the underlying console and svg generation functions. See the\nofficial documentation for more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Auto generate docs for typer commands.",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://sphinxcontrib-typer.readthedocs.io",
        "Repository": "https://github.com/sphinx-contrib/typer"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5683452c4b576996125402da7209012bd753501e764d6e2e177c7d497e34df48",
                "md5": "02799ab1c40a41f61851ca8b58505950",
                "sha256": "74f1416392bfef39ea12c940f074383ff2fb27b3dc0388806012b87b8dae971c"
            },
            "downloads": -1,
            "filename": "sphinxcontrib_typer-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "02799ab1c40a41f61851ca8b58505950",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 14427,
            "upload_time": "2024-10-14T04:20:37",
            "upload_time_iso_8601": "2024-10-14T04:20:37.076205Z",
            "url": "https://files.pythonhosted.org/packages/56/83/452c4b576996125402da7209012bd753501e764d6e2e177c7d497e34df48/sphinxcontrib_typer-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9eb695758b1a85c35c8b7222039d939eeaef68dcb575941c6f1fbe18c14c7c0",
                "md5": "c9412b286cd8df87723c22254abd912c",
                "sha256": "b455664c5820e5e6748466707fbac63aa864abf2b7006857dff4006772d3bbbf"
            },
            "downloads": -1,
            "filename": "sphinxcontrib_typer-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c9412b286cd8df87723c22254abd912c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 15982,
            "upload_time": "2024-10-14T04:20:38",
            "upload_time_iso_8601": "2024-10-14T04:20:38.649888Z",
            "url": "https://files.pythonhosted.org/packages/c9/eb/695758b1a85c35c8b7222039d939eeaef68dcb575941c6f1fbe18c14c7c0/sphinxcontrib_typer-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-14 04:20:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sphinx-contrib",
    "github_project": "typer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sphinxcontrib-typer"
}
        
Elapsed time: 1.44259s