pdoc3

0.11.6 · active · verified Mon Apr 13

pdoc3 is a Python library and command-line tool that automatically generates API documentation from your Python project's docstrings and type annotations. It supports various docstring formats like Markdown, numpydoc, and Google-style, and can output documentation in HTML or PDF formats. As an actively maintained fork of the original `pdoc` project, it focuses on Python 3+ compatibility and ease of use, aiming to provide sensible documentation with minimal configuration.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate HTML documentation for a simple Python module using pdoc3 programmatically. It creates a temporary Python file, generates docs into a 'docs/' directory, and then cleans up the temporary file. For command-line usage, simply run `pdoc your_module_or_package`.

import pdoc
import os

# Create a dummy module file for documentation
dummy_module_content = """
\"\"\"
A simple example module.
\"\"\"

class MyClass:
    \"\"\"
    A sample class.

    Attributes:
        name (str): The name of the instance.
    \"\"\"
    def __init__(self, name: str):
        self.name = name

    def greet(self) -> str:
        \"\"\"
        Greets the user.
        \"\"\"
        return f"Hello, {self.name}!"

def my_function(value: int) -> int:
    \"\"\"
    A sample function.

    Args:
        value (int): An integer input.

    Returns:
        int: The input value multiplied by 2.
    \"\"\"
    return value * 2
"""
with open("my_example_module.py", "w") as f:
    f.write(dummy_module_content)

# Generate documentation for the module
# Output to a 'docs' directory
pdoc.pdoc("my_example_module", output_directory="docs")

print("Documentation generated in 'docs/' directory.")
print("You can view it by opening docs/my_example_module.html")

# Clean up the dummy module file
os.remove("my_example_module.py")
# To clean up the generated documentation directory:
# import shutil
# shutil.rmtree("docs")

view raw JSON →