Sphinx Click

6.2.0 · active · verified Sun Apr 12

sphinx-click is a Sphinx extension that automatically extracts documentation from Click-based command-line applications and integrates it into Sphinx documentation. It is currently at version 6.2.0 and receives regular updates, often with several releases per year.

Warnings

Install

Imports

Quickstart

To quickly document a Click application, first set up a Sphinx project (e.g., using `sphinx-quickstart`). Create your Click application (e.g., `hello_world.py`). In your `conf.py`, add `'sphinx_click'` to the `extensions` list and ensure your application's path is included in `sys.path`. Then, in an RST file (e.g., `cli.rst`), use the `.. click::` directive, pointing to your Click command or group. The `:prog:` option specifies the command name to display, and `:nested: full` will document subcommands. Ensure the Click application and its dependencies are available in the build environment.

# docs/conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('.'))

project = 'My Click App Docs'
copyright = '2026, My Team'
extensions = ['sphinx_click']
html_theme = 'alabaster'

# hello_world.py
import click

@click.group()
def cli():
    """A sample command group."""
    pass

@cli.command()
@click.argument('name', envvar='USER', default='World')
def hello(name):
    """Greet a user or the world.

    :param name: The name to greet. Defaults to the USER environment variable if set.
    """
    click.echo(f'Hello {name}!')

@cli.command()
def goodbye():
    """Say goodbye.

    """
    click.echo('Goodbye!')

# docs/index.rst
.. toctree::
   :maxdepth: 2
   :caption: Contents:

   cli

.. click:: hello_world:cli
   :prog: myapp
   :nested: full

view raw JSON →