Sphinx Click
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
- breaking sphinx-click 6.0.0 dropped support for Click 7.x. Your Click application must use Click 8.0.0 or higher.
- breaking sphinx-click 6.0.0 dropped support for Sphinx versions older than 4.0.0. Ensure your Sphinx installation meets this minimum requirement.
- breaking As of sphinx-click 6.1.0, Python 3.8 and 3.9 are no longer supported.
- deprecated The `:show-nested:` option for the `.. click::` directive is deprecated.
- gotcha Cross-referencing environment variables using the standard `:envvar:` role in Sphinx can cause conflicts if the same environment variable is used across multiple commands, due to Sphinx's non-namespaced default labels.
- gotcha Click docstrings often use the `\b` character for formatting. Sphinx-click might not render these characters correctly in HTML output, leading to broken formatting for lists or paragraphs intended for specific Click help screens.
Install
-
pip install sphinx-click
Imports
- sphinx_click
extensions = ['sphinx_click']
Quickstart
# 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