Convert Python docstrings to Markdown documentation.
Project description
PyDoc2Markdown
Convert Python docstrings into clean, structured Markdown documentation.
PyDoc2Markdown is a lightweight documentation tool for Python projects that want plain Markdown output without adopting a full documentation framework. It works as both a CLI and a library: point it at your source code, and it generates module docs, a navigation-ready docs directory, or an API section inside your README.
It is built for projects that want documentation to stay close to the code while remaining easy to publish on GitHub, GitLab, MkDocs, or any Markdown renderer.
Table of Contents
- Why PyDoc2Markdown?
- Features
- Requirements
- Installation
- Try It In 30 Seconds
- Sample Project
- Before And After
- Quick Start
- CLI Reference
- Configuration
- README API Sections
- Navigation Docs Layout
- Library API
- Supported Docstring Formats
- Example Output
- Documentation
- License
Why PyDoc2Markdown?
Documentation generators like Sphinx are powerful but require significant configuration — themes, conf.py, extensions, and often custom builders to get clean output. pdoc and mkdocstrings are easier but still depend on a full documentation framework.
PyDoc2Markdown takes a different approach: zero configuration, zero framework dependencies, pure Markdown output. Point it at your Python project and get structured Markdown files that work anywhere — GitHub, GitLab, MkDocs, or any Markdown renderer.
- No
conf.py— works out of the box - No framework lock-in — generates plain
.mdfiles - Minimal dependencies — Jinja2 + docstring-parser
- Practical defaults — useful CLI output before you write any config
Features
- Docstring parsing — Extract Google and NumPy style docstrings, with basic reStructuredText field support via
docstring-parser. - Markdown generation — Produce beautiful Markdown files with customizable Jinja2 templates.
- README API sections — Create or update a generated API reference block in README files.
- Auto-generated index & TOC — Each module gets a Table of Contents; an
index.mdwith package grouping is created automatically. - Navigation layout — Generate a docs entrypoint with package pages and API files under
api/. - Package grouping — Output files are organized into subdirectories matching the package structure.
- Built-in themes — Choose between
default(detailed) andminimalthemes, or supply your own template. - CLI & API — Use via command line or import as a Python library.
- Recursive processing — Scan entire packages in one command.
- Type-aware — Respects type hints and annotations.
- Advanced constructs — Supports
property,classmethod,staticmethod,dataclass,Enum,TypedDict,Protocol,ABC,Pydantic, and__all__.
Requirements
- Python >= 3.10
- Dependencies: Jinja2, docstring-parser
- Optional: watchdog (for
--watchmode)
Installation
# Base installation
pip install pydoc2markdown
# With file watcher support
pip install pydoc2markdown[watch]
Try It In 30 Seconds
Clone the repository and run PyDoc2Markdown against the included sample project:
pydoc2markdown examples/sample_project/src --recursive --nav --readme \
--readme-path examples/sample_project/README.md \
-o examples/sample_project/docs
That command updates the sample project's README API block and creates a navigation-first docs layout:
examples/sample_project/
├── README.md
├── src/shop_demo/
└── docs/
├── index.md
├── shop_demo.md
└── api/shop_demo/
├── inventory.md
└── orders.md
Sample Project
The sample project is a tiny shop package with dataclasses, an enum, typed functions, properties, and Google-style docstrings. It exists so you can inspect both sides of the workflow:
Before And After
Start with normal Python code and docstrings:
def calculate_total(items: list[Product], discount: float = 0.0) -> float:
"""Calculate the discounted order total.
Args:
items: Products to include in the total.
discount: Discount ratio between 0 and 1.
Returns:
Total price after discount.
Raises:
ValueError: If discount is outside the accepted range.
"""
PyDoc2Markdown turns it into Markdown with headings, parameter tables, return types, and raised exceptions:
### `calculate_total`
Calculate the discounted order total.
**Parameters:**
| Name | Type | Description |
|------|------|-------------|
| `items` | `list[Product]` | Products to include in the total. |
| `discount` | `float` | Discount ratio between 0 and 1. |
**Returns:** `float`
Total price after discount.
**Raises:**
- `ValueError`: If discount is outside the accepted range.
Quick Start
CLI Usage
# Initialize default configuration in pyproject.toml
pydoc2markdown --init
# Generate docs for a single file
pydoc2markdown my_module.py -o docs
# Recursively process a package
pydoc2markdown src/my_package --recursive -o docs
# Use a built-in theme
pydoc2markdown src/my_package --recursive --theme minimal -o docs
# Use a custom template
pydoc2markdown src/my_package --recursive --template custom.md.j2 -o docs
# Single combined file
pydoc2markdown src/my_package --recursive --single-file -o docs/README.md
# Update the API section in README.md
pydoc2markdown src/my_package --recursive --readme
# Generate a navigation-first docs layout
pydoc2markdown src/my_package --recursive --nav -o docs
# Watch mode — auto-regenerate on changes
pydoc2markdown src/my_package --recursive --watch -o docs
# Enable verbose logging
pydoc2markdown src/my_package --recursive -vv -o docs
Library Usage
from pathlib import Path
from pydoc2markdown import DocstringParser, MarkdownGenerator
parser = DocstringParser()
modules = parser.parse(Path("src/my_package"), recursive=True)
generator = MarkdownGenerator(theme="default")
generator.generate(modules, output_dir=Path("docs"))
CLI Reference
| Flag | Default | Description |
|---|---|---|
source |
(required unless --init is used) |
Path to a Python file or directory to process |
--init |
False |
Create or update [tool.pydoc2markdown] in pyproject.toml |
-o, --output |
docs / value from pyproject.toml |
Output directory (or file path when --single-file is used) |
--recursive |
False / value from pyproject.toml |
Recursively process subdirectories |
--theme |
default / value from pyproject.toml |
Built-in theme: default (detailed) or minimal |
--template |
None |
Path to a custom Jinja2 template for Markdown generation |
--single-file |
False |
Generate a single combined Markdown file instead of separate files |
--readme |
False |
Create or update an API reference section in README.md |
--readme-path |
README.md |
Path to the README file updated by --readme |
--nav |
False |
Generate a navigation-first docs layout with API pages under api/ |
--api-dir |
api |
Directory for API pages when --nav is used |
--watch |
False |
Watch source files and regenerate docs on change |
-v, --verbose |
0 |
Increase verbosity (-v = INFO, -vv = DEBUG) |
--version |
— | Show version and exit |
Configuration priority: CLI flags > [tool.pydoc2markdown] in pyproject.toml > built-in defaults.
Configuration
You can initialize default configuration with:
pydoc2markdown --init
This creates or appends a [tool.pydoc2markdown] section in pyproject.toml.
If the section already exists, it is left unchanged.
You can also set default values manually in your pyproject.toml:
[tool.pydoc2markdown]
output = "docs"
theme = "default"
recursive = true
Any values set here serve as defaults and can be overridden by CLI flags.
README API Sections
Use --readme to create or update a compact API reference in your README:
pydoc2markdown src/my_package --recursive --readme
By default, PyDoc2Markdown updates README.md. Use --readme-path to target a
different file:
pydoc2markdown src/my_package --recursive --readme --readme-path docs/index.md
When the file already contains PyDoc2Markdown markers, only the generated block between the markers is replaced:
## API Reference
<!-- pydoc2markdown:start -->
<!-- pydoc2markdown:end -->
If the markers are missing, a new ## API Reference section is appended. If the
README does not exist, it is created.
Navigation Docs Layout
Use --nav when you want a docs directory that is ready to browse from a single
entrypoint:
pydoc2markdown src/my_package --recursive --nav -o docs
This creates a layout like:
docs/
├── index.md
├── modules.md
└── api/
├── package.md
└── utils.md
The root index.md links to package landing pages and every generated API page.
Use --api-dir to change where module pages are written:
pydoc2markdown src/my_package --recursive --nav --api-dir reference -o docs
Library API
DocstringParser
from pathlib import Path
from pydoc2markdown import DocstringParser
parser = DocstringParser()
modules = parser.parse(Path("src/my_package"), recursive=True)
MarkdownGenerator
from pathlib import Path
from pydoc2markdown import DocstringParser, MarkdownGenerator
# Parse modules
parser = DocstringParser()
modules = parser.parse(Path("src/my_package"), recursive=True)
# Default theme, separate files
gen = MarkdownGenerator(theme="default")
gen.generate(modules, output_dir=Path("docs"))
# Minimal theme
gen_min = MarkdownGenerator(theme="minimal")
gen_min.generate(modules, output_dir=Path("docs_minimal"))
# Custom template
gen_tmpl = MarkdownGenerator(template_path=Path("my_template.md.j2"))
gen_tmpl.generate(modules, output_dir=Path("docs_custom"))
# Single combined file
gen.generate_single_file(modules, output_path=Path("docs/README.md"))
# README API section
gen.update_readme(modules, readme_path=Path("README.md"))
# Navigation docs layout
gen.generate_navigation(modules, output_dir=Path("docs"))
# Markdown string for a single module
md_string = gen.generate_string(modules[0])
Supported Docstring Formats
PyDoc2Markdown uses docstring-parser and supports common structured docstring sections:
| Style | Support | Notes |
|---|---|---|
| ✅ Full | Args, Returns, Raises, Attributes, Examples | |
| NumPy | ✅ Full | Parameters, Returns, Raises, Attributes, Examples |
| reStructuredText (reST) | ⚠️ Basic | Field-style metadata via docstring-parser, including :param:, :returns:, and :raises: |
Example Output
Given this source file:
from pydantic import BaseModel, Field
class User(BaseModel):
"""A user in the system."""
id: int = Field(description="Unique identifier")
email: str = Field(default="", description="Email address")
is_active: bool = True
class UserService:
"""Service for managing users."""
def get_user(self, user_id: int) -> User:
"""Fetch a user by ID.
Args:
user_id: The user's unique identifier.
Returns:
The requested User instance.
Raises:
ValueError: If the user does not exist.
"""
...
Running pydoc2markdown src/users.py -o docs produces:
# users
## Table of Contents
- [Classes](#classes)
- [`User`](#user)
- [`UserService`](#userservice)
## Classes
### `User` *(Pydantic)*
A user in the system.
#### Pydantic Fields
| Name | Type | Default | Description |
|------|------|---------|-------------|
| `id` | `int` | *required* | Unique identifier |
| `email` | `str` | `""` | Email address |
| `is_active` | `bool` | `True` | - |
### `UserService`
Service for managing users.
#### Methods
##### `get_user`
Fetch a user by ID.
**Parameters:**
| Name | Type | Default | Description |
|------|------|---------|-------------|
| `user_id` | `int` | *required* | The user's unique identifier. |
**Returns:** `User`
**Raises:**
- `ValueError` — If the user does not exist.
For a complete small project, see examples/sample_project/. It includes source code, a generated README API section, and a navigation-first docs layout generated by PyDoc2Markdown. You can also see pre-built documentation for this repository in examples/docs/.
Documentation
License
MIT License — see LICENSE for details.
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 pydoc2markdown-0.5.2.tar.gz.
File metadata
- Download URL: pydoc2markdown-0.5.2.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70ebdd0b022449464549a9342c6043b7c4632cef7381083fc25c0c69b642c787
|
|
| MD5 |
735542625e81081cd3bff5cf3a5f6eca
|
|
| BLAKE2b-256 |
feb6251a086b9ae382b31e849fc1239b7ef9d7584b95aad7f89a175eb0e9a7c6
|
Provenance
The following attestation bundles were made for pydoc2markdown-0.5.2.tar.gz:
Publisher:
release.yml on f1sherFM/PyDoc2Markdown
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydoc2markdown-0.5.2.tar.gz -
Subject digest:
70ebdd0b022449464549a9342c6043b7c4632cef7381083fc25c0c69b642c787 - Sigstore transparency entry: 1694779671
- Sigstore integration time:
-
Permalink:
f1sherFM/PyDoc2Markdown@2163878b47939728fecd0c2c4b5ab69e8faa95c8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/f1sherFM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2163878b47939728fecd0c2c4b5ab69e8faa95c8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydoc2markdown-0.5.2-py3-none-any.whl.
File metadata
- Download URL: pydoc2markdown-0.5.2-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49345c0d4efd622619c773b319b8453eb5a7d9244728f16ce48886635726795b
|
|
| MD5 |
4f8ab0c7fd055de292f898f9b11fffd9
|
|
| BLAKE2b-256 |
d88e110714f4810408136edbe0cf67bcd6b82c0185a692ce79ba2448bfeab58e
|
Provenance
The following attestation bundles were made for pydoc2markdown-0.5.2-py3-none-any.whl:
Publisher:
release.yml on f1sherFM/PyDoc2Markdown
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydoc2markdown-0.5.2-py3-none-any.whl -
Subject digest:
49345c0d4efd622619c773b319b8453eb5a7d9244728f16ce48886635726795b - Sigstore transparency entry: 1694780092
- Sigstore integration time:
-
Permalink:
f1sherFM/PyDoc2Markdown@2163878b47939728fecd0c2c4b5ab69e8faa95c8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/f1sherFM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2163878b47939728fecd0c2c4b5ab69e8faa95c8 -
Trigger Event:
push
-
Statement type: