Skip to main content

Convert Python docstrings to Markdown documentation.

Project description

PyDoc2Markdown

CI codecov PyPI Python versions License

Convert Python docstrings into clean, structured Markdown documentation.

Table of Contents

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 .md files
  • Minimal dependencies — Jinja2 + docstring-parser

Features

  • Docstring parsing — Extract Google, NumPy, and reStructuredText style docstrings with structured params, returns, and raises.
  • Markdown generation — Produce beautiful Markdown files with customizable Jinja2 templates.
  • Auto-generated index & TOC — Each module gets a Table of Contents; an index.md with package grouping is created automatically.
  • Package grouping — Output files are organized into subdirectories matching the package structure.
  • Built-in themes — Choose between default (detailed) and minimal themes, 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

Installation

# Base installation
pip install pydoc2markdown

# With file watcher support
pip install pydoc2markdown[watch]

Quick Start

CLI Usage

# 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

# 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) Path to a Python file or directory to process
-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
--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 set default values in your pyproject.toml under the [tool.pydoc2markdown] section:

[tool.pydoc2markdown]
output = "docs"
theme = "default"
recursive = true

Any values set here serve as defaults and can be overridden by CLI flags.

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"))

# Markdown string for a single module
md_string = gen.generate_string(modules[0])

Supported Docstring Formats

PyDoc2Markdown uses docstring-parser and supports:

Style Support Notes
Google ✅ Full Args, Returns, Raises, Attributes, Examples
NumPy ✅ Full Parameters, Returns, Raises, Attributes, Examples
reStructuredText (reST) ⚠️ Partial Basic structure via docstring-parser; :param:, :returns:, :raises: fields

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 more complete example, see the examples/ directory or the pre-built documentation in examples/docs/.

Documentation

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydoc2markdown-0.4.1.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydoc2markdown-0.4.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file pydoc2markdown-0.4.1.tar.gz.

File metadata

  • Download URL: pydoc2markdown-0.4.1.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydoc2markdown-0.4.1.tar.gz
Algorithm Hash digest
SHA256 47af1cf3b6fbd1cc41a61c33b329dc2bf9944292a9199136cb5b51d4c91db6a7
MD5 bc38f9436403a825fda22a4499a6d6c8
BLAKE2b-256 4c0e5075b8f875f3c1c6e052b96e165b5d6665cf65f9b9cba7499de11cd958cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydoc2markdown-0.4.1.tar.gz:

Publisher: release.yml on f1sherFM/PyDoc2Markdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydoc2markdown-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pydoc2markdown-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydoc2markdown-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55e930d3f78201114cbb529f6be436888c384c0842770bd7dd8409d512e42004
MD5 c1597a6f9a16a225d276baf743dab3fd
BLAKE2b-256 b24c6a6be28f1d27aff6875ad01c6d71f12772c87cab211fdd982f69e0f7374d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydoc2markdown-0.4.1-py3-none-any.whl:

Publisher: release.yml on f1sherFM/PyDoc2Markdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page