Pydoctor
Pydoctor is a standalone API documentation generator that works by static analysis. It was primarily written to replace epydoc for the Twisted project, especially due to epydoc's difficulties with `zope.interface`. It aims to provide comprehensive API documentation for Python projects, supporting various docstring formats like epytext, reStructuredText, Google, and Numpy styles. The current version is 25.10.1 and it is actively maintained.
Common errors
-
Pydoctor crashed with traceback
cause A runtime error occurred during static analysis or HTML generation. This corresponds to pydoctor's exit code 1.fixEnable verbose logging with `-v` (or multiple `-vvv`) to get more details. Check for issues in the source code or docstring parsing. Consult the full traceback for the specific error location. -
Error: Source directory lacks __init__.py
cause Prior to pydoctor 25.4.0, pydoctor expected source directories to be traditional packages with an `__init__.py` file. It did not fully support implicit native namespace packages (PEP 420).fixUpgrade pydoctor to version 25.4.0 or newer to support implicit native namespace packages (PEP 420). Alternatively, ensure that the source directories being documented are valid Python packages with an `__init__.py` file, or explicitly configure them. -
Error 'Template folder do not exist or is not a directory'
cause Pydoctor could not find the specified custom template directory, or the path provided was not a directory.fixVerify the path provided to the `--template-dir` option (or its equivalent in a config file) is correct and points to an existing directory containing valid template files. -
Pydoctor fails to find Python objects or resolve links correctly.
cause Pydoctor's static analysis might struggle with complex import structures, aliasing, or the project's base directory not matching the current working directory.fixSpecify the project's base directory using `--project-base-dir` for accurate source link computation. Use `--add-package` or `--add-module` explicitly, and ensure all relevant source code is discoverable. For module/package name collisions, better messages are triggered in newer versions.
Warnings
- breaking Pydoctor regularly drops support for older Python versions. For example, pydoctor 24.11 dropped Python 3.7, and pydoctor 25.4 dropped Python 3.8. Always check the `requires_python` metadata for compatibility.
- gotcha The `--html-viewsource-base` argument, used for linking to source code, should point to a stable Git tag or commit SHA, not a mutable branch (e.g., `master`/`main`). Using a branch can lead to broken source links due to line number mismatches as the code evolves.
- breaking The `--html-write-function-pages` option, which generated individual HTML files for functions and methods, was removed in pydoctor 21.2.0.
- gotcha Pydoctor's exit codes can be non-zero even if HTML output is successfully generated. Exit code `1` indicates a crash, `2` for malformatted docstrings, and `3` if warnings are treated as errors via `--warnings-as-errors`.
Install
-
pip install pydoctor
Quickstart
# 1. Create a dummy Python package/module
mkdir -p my_project/src/my_lib
echo """"""A simple library.""""" > my_project/src/my_lib/__init__.py
echo """"""A simple module.
def greet(name: str) -> str:
"""Greets the given name.
:param name: The name to greet.
:type name: str
:return: A greeting message.
:rtype: str
"""
return f'Hello, {name}!'
""" > my_project/src/my_lib/greeting.py
# 2. Run pydoctor to generate documentation
cd my_project
pydoctor --project-name="My Project API" \
--project-version="1.0.0" \
--html-output=docs/api \
src/my_lib
# 3. View the generated documentation (e.g., open docs/api/index.html)