Auto generate docs for typer commands.
Project description
sphinxcontrib-typer
A Sphinx directive for auto generating docs for Typer (and Click commands!) using the rich console formatting available in Typer. 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 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:
You could change :preferred: to svg, to generate svg instead:
|
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinxcontrib_typer-0.8.0.tar.gz.
File metadata
- Download URL: sphinxcontrib_typer-0.8.0.tar.gz
- Upload date:
- Size: 382.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7637045f1446ed991b80dcaeea4b9f85258e08ddbc3ef91ac80baac5603ff282
|
|
| MD5 |
76d9c85ad1157d5f327221044fd9c2fb
|
|
| BLAKE2b-256 |
5e45844b8bb4ceb98b90adb352d695f82632176041e93c169d2ad19d434fb9b8
|
Provenance
The following attestation bundles were made for sphinxcontrib_typer-0.8.0.tar.gz:
Publisher:
release.yml on sphinx-contrib/typer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_typer-0.8.0.tar.gz -
Subject digest:
7637045f1446ed991b80dcaeea4b9f85258e08ddbc3ef91ac80baac5603ff282 - Sigstore transparency entry: 946080320
- Sigstore integration time:
-
Permalink:
sphinx-contrib/typer@6aadcd5eb6c484931784b810876b151a03e12c1d -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/sphinx-contrib
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6aadcd5eb6c484931784b810876b151a03e12c1d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinxcontrib_typer-0.8.0-py3-none-any.whl.
File metadata
- Download URL: sphinxcontrib_typer-0.8.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
876547f7f0ded9eca17fdc8191373f4ac096642f00bf19c5e99c950228a0436a
|
|
| MD5 |
d8e6e0f6fb5814866d777f051e9ea43e
|
|
| BLAKE2b-256 |
aa91e50144ab98635102e9c33d599177381aa2d9996efcb5179ed59a1bb421d6
|
Provenance
The following attestation bundles were made for sphinxcontrib_typer-0.8.0-py3-none-any.whl:
Publisher:
release.yml on sphinx-contrib/typer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinxcontrib_typer-0.8.0-py3-none-any.whl -
Subject digest:
876547f7f0ded9eca17fdc8191373f4ac096642f00bf19c5e99c950228a0436a - Sigstore transparency entry: 946080331
- Sigstore integration time:
-
Permalink:
sphinx-contrib/typer@6aadcd5eb6c484931784b810876b151a03e12c1d -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/sphinx-contrib
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6aadcd5eb6c484931784b810876b151a03e12c1d -
Trigger Event:
push
-
Statement type: