argparse_to_md: Argparse to README.md
argparse_to_md tool helps developers of command-line tools written in Python keep the usage instructions in their README.md files up to date. It can automatically update usage instructions in README.md file based on argparse parsers defined in the code. It can be invoked as a pre-commit hook or as a standalone script.
How to use argparse_to_md:
- In your CLI tool, move creation of
argparse.ArgumentParserinto a separate function:import argparse def create_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(prog='mytool') parser.add_argument(...) return parser def main(): parser = create_parser() parser.parse_args()
- In your README.md file, add a section where the usage would be described. Replace
mytoolwith the fully qualified name of the module andcreate_parserwith the name of the function which returns anargparse.ArgumentParser.### Usage <!-- argparse_to_md:mytool:create_parser --> <!-- argparse_to_md_end --> - Run
argparse_to_md, either manually or as a pre-commit hook. The README.md file will be updated, the usage instructions will appear inside this section:### Usage <!-- argparse_to_md:mytool:create_parser --> Usage: ``` mytool [-h] ... ``` Optional arguments: - `-h`, `--help`: show this help message and exit - ... <!-- argparse_to_md_end -->
- Whenever you modify the parser in your code, re-run
argparse_to_md, or let the pre-commit hook run. README.md will be updated with the new usage instructions.
Usage as a pre-commit hook
Add to your .pre-commit-config.yaml. This pre-commit hook will be triggered by changes to all Python or Markdown files, and it will edit README.md:
repos:
- repo: https://github.com/igrr/argparse_to_md.git
rev: v0.5.1
hooks:
- id: argparse_to_md
If you need to adjust the list of files to be updated, specify them in args: as follows:
repos:
- repo: https://github.com/igrr/argparse_to_md.git
rev: v0.5.1
hooks:
- id: argparse_to_md
args: [--input=README.md, --input=README_CN.md]
Command-line usage
You can also use argparse_to_md from the command line:
Usage:
argparse_to_md [-h] [-i INPUT [-i INPUT ...]] [--extra-sys-path EXTRA_SYS_PATH [EXTRA_SYS_PATH ...]]
[--check] [--version]
Optional arguments:
-i INPUT [-i INPUT ...],--input INPUT [--input INPUT ...]: Markdown file to update (can be specified multiple times).--extra-sys-path EXTRA_SYS_PATH [EXTRA_SYS_PATH ...]: Extra paths to add to PYTHONPATH before loading the module--check: Check if the files need to be updated, but don't modify them. Non-zero exit code is returned if any file needs to be updated.--version: show program's version number and exit
Customizing output
Output can be customized by passing additional options in the comment:
<!-- argparse_to_md:module_name:function_name:opt1=value1:opt2=value2 -->
<!-- argparse_to_md_end -->
The following options are supported:
subheading_level(default0): if set to a non-zero value, theUsageline and all theUsagelines related to subparsers are prefixed with a markdown heading of respective level. For example, when specifyingsubheading_level=2, the final output will contain## Usage:instead ofUsage:.pad_lists(default0): if set to1, an empty line is added before each markdown list. Some markdown renderers require this blank line for proper list rendering.
Related projects
- https://github.com/9999years/argdown/ — Generates Markdown and RestructuredText from argparse-based parsers.
- https://github.com/alex-rudakov/sphinx-argparse — Sphinx extension for documenting argparse-based parsers.
- https://github.com/docopt/docopt — Inverse of the above, constructs a parser based on documentation.
License
This tool is Copyright (c) 2024 Ivan Grokhotkov and distributed under the MIT License.
Metadata
Release files for argparse-to-md 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| argparse_to_md-0.5.1.tar.gz | 18.4 kB | With provenance | Details for argparse_to_md-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| argparse_to_md-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for argparse_to_md-0.5.1-py3-none-any.whl |
Total release size: 29.9 kB
Release files / argparse_to_md-0.5.1.tar.gz
| Download URL | argparse_to_md-0.5.1.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
358596ebd6e4fc02dfed548037f467815a7b77f07938232733615c1871681178
|
|
BLAKE2b-256 checksum How to use checksums |
384e2db7cda6bbba0d403b534505db68d83b8765d01952241bfbf629f818d6e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logRelease files / argparse_to_md-0.5.1-py3-none-any.whl
| Download URL | argparse_to_md-0.5.1-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2be1b92da06c9a47b18147f690ef47f68d4987a9ef993058189a8723a206be4
|
|
BLAKE2b-256 checksum How to use checksums |
d1882e28fbbd067b9c1ab1a3ea2a1ad0b0c51bd9b741c89c9c7cb74c838c10db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logSecurity for argparse-to-md 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for argparse_to_md-0.5.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.