Generate usage documentation from Python scripts using the `argparse` module
Project description
Parse 2 Docs
parse2docs
is a Python library that allows you to automatically generate usage documentation in Markdown format from Python scripts using the argparse
module.
Features
- Scans the Python script for instances of
argparse.ArgumentParser
. - Generates a Markdown file with usage documentation based on the
ArgumentParser
object. - The generated documentation includes a table of contents, descriptions of each command line argument, and examples if provided.
- Works with
ArgumentParser
instances declared at the module level or returned by functions.
Installation
Via pip
parse2docs
can be installed via pip
:
pip install parse2docs
Via poetry
parse2docs
can be installed via Poetry. To install the library, clone this repository to your local machine and use Poetry to install:
git clone https://github.com/yourusername/parse2docs.git
cd parse2docs
poetry install
Usage
There are two ways to use parse2docs, either as a Python module in your script or directly from the command line using the provided command.
As a Python module
import parse2docs
# Path to the Python script
script_path = 'path_to_your_python_script.py'
# Generate markdown documentation
markdown = parse2docs.generate_md_from_py_script(script_path)
# Save the markdown to a .md file
with open('output.md', 'w') as f:
f.write(markdown)
This will generate a output.md
file with the usage documentation in Markdown format.
From the command line
Description
The following usage section was generated using parse2docs
😉:
## Overall Usage Example
`example.py <file_path>`
## Table of Contents
* [file_path](#file_path)
## Options
### file_path
Path to the Python script file containing the ArgumentParser.
**Type**: `Path`
**Required**: Yes
This will print the usage documentation in Markdown format to the console.
Testing
We use pytest
for testing. Run the tests with the following command:
python -m pytest tests/
Contributing
Contributions to parse2docs
are welcome and awesome! Please submit a pull request or open an issue to discuss potential changes or improvements.
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
Hashes for parse2docs-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc09dbcf7381c27509001169233fc1dd20eee578b2d361ed2816635e83a37473 |
|
MD5 | 1cff33cdcb255b5aba0c8f02c567b133 |
|
BLAKE2b-256 | b6959602f3c8925d754fd4c66eec464e6c4ea249a018521c998749f1edf1ecdd |