doccmd is a command-line tool (CLI) designed to run external commands, such as linters and formatters, against code blocks embedded within reStructuredText and Markdown documentation files. It helps ensure the code examples in documentation remain correct and up-to-date. The library follows a rapid release cadence, with frequent updates, often on a daily basis.
pip install doccmdNo compatibility data collected yet for this library.
This quickstart demonstrates how to use `doccmd` from the command line to execute code blocks in a Markdown file. `doccmd` will find the code blocks, create temporary files, run them, and report any errors. By default, it runs all supported languages. You can specify a language with `--language`.
Configure your linter (e.g., Ruff) to ignore files matching `doccmd_*.py` or the prefix specified by `--temporary-file-name-prefix` in its configuration (e.g., `[tool.ruff] lint.per-file-ignores."doccmd_*.py" = ["S105"]`).
To prevent `doccmd` from erroring in this scenario, use the `--no-fail-on-group-write` option. Be aware that the documentation will not be updated with the changes from tools for grouped blocks.
Pin your `doccmd` version in production environments to avoid unexpected behavior from frequent updates, e.g., `pip install doccmd==2026.3.26.2`.
Group related code blocks using `<!-- group doccmd[all]: start -->` and `<!-- group doccmd[all]: end -->` comments around them in Markdown, or `.. group-doccmd[all]: start` and `.. group-doccmd[all]: end` directives in reStructuredText.
If you accept that changes to grouped blocks will not be written back to the documentation, rerun `doccmd` with the `--no-fail-on-group-write` option. Otherwise, refactor your documentation or tools to avoid modifying grouped blocks, or do not group blocks that need to be modified by tools.