Skip to main content

Auto generate docs for typer commands.

Project description

sphinxcontrib-typer

License: MIT PyPI version PyPI pyversions PyPI status Documentation Status Code Cov Test Status Lint Status Ruff OpenSSF Scorecard

A Sphinx directive for auto generating docs for Typer applications using the rich console formatting available in Typer. This package generates concise command documentation in text, html or svg formats out of the box. If you need to document a standalone Click command, or want to greatly customize the generated documentation, sphinx-click may be more appropriate and will also work for Typer commands.

Installation

Install with pip::

pip install sphinxcontrib-typer

Add sphinxcontrib.typer to your conf.py file:

# 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:

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:

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

This would generate html that looks like this:

Example PNG

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib_typer-0.9.0.tar.gz (168.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinxcontrib_typer-0.9.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file sphinxcontrib_typer-0.9.0.tar.gz.

File metadata

  • Download URL: sphinxcontrib_typer-0.9.0.tar.gz
  • Upload date:
  • Size: 168.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for sphinxcontrib_typer-0.9.0.tar.gz
Algorithm Hash digest
SHA256 480175de4f0ee280cde438f830996cbc7f1f5d8838157bbe9f5dc7894615a002
MD5 a05f4248c073c56e1bcdc9b382e99a1e
BLAKE2b-256 98e5a3463123d69ae431ce8708cab92de0434012bd3d1f4d8e3ea82fc1a5ed82

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinxcontrib_typer-0.9.0.tar.gz:

Publisher: release.yml on sphinx-contrib/typer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinxcontrib_typer-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinxcontrib_typer-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f171000b4000f392517735855e5915ffc08afaf6b6d127116f239c4715a75f5c
MD5 c9e7ab0c06e27221cf1f867e9cacd3f6
BLAKE2b-256 d31eeca6d5b3bc072a8c02cd1ccdd558e75aec7f19f70e91d87fdd93a46ab904

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinxcontrib_typer-0.9.0-py3-none-any.whl:

Publisher: release.yml on sphinx-contrib/typer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page