mkdocstrings-python-legacy
mkdocstrings-python-legacy is a Python handler for the mkdocstrings documentation generator. It facilitates the automatic collection of documentation from Python source code, relying on `pytkdocs` for data extraction. The handler supports popular docstring styles like Google, Numpydoc, and reStructuredText. While actively maintained, receiving updates as recently as May 2025, it is considered a legacy component, and users are strongly advised to migrate to the newer `mkdocstrings-python` handler, which offers improved functionality based on Griffe.
Common errors
-
Some objects are not rendered (they do not appear in the generated docs)
cause Incorrect configuration of handler options, incorrectly formatted docstrings, or Python modules not being discoverable (e.g., missing `__init__.py` files or incorrect `paths` setting).fixVerify `mkdocs.yml` handler options. Ensure docstrings follow a supported style. Add `__init__.py` to directories containing modules. Configure the `paths` option in `mkdocs.yml` to point to your source code directory (e.g., `paths: [src]`). Run `mkdocs build -v` for verbose output. -
WARNING - Documentation file 'reference/parsers/docstrings.md' contains a link to 'reference/parsers/pytkdocs.parsers.docstrings.Section' which is not found in the documentation files.
cause A cross-reference link in your Markdown uses parentheses `()` instead of brackets `[]`.fixChange cross-references from `[Title](path.to.object)` to `[Title][path.to.object]` or `[path.to.object][]` for automatic linking. -
mkdocstrings not finding module
cause The Python handler cannot locate your Python packages or modules. This is often due to an incorrect `paths` configuration in `mkdocs.yml` or an improperly set `PYTHONPATH` environment variable.fixExplicitly configure the `paths` option under the `python` handler in your `mkdocs.yml` (e.g., `paths: [src]`). Ensure this path is relative to your `mkdocs.yml` file. Alternatively, ensure your `PYTHONPATH` environment variable correctly points to your project's source root or install your package in the environment.
Warnings
- deprecated This handler is considered legacy. Users are strongly recommended to migrate to the newer `mkdocstrings-python` handler for improved features and future compatibility, which is based on Griffe.
- breaking Support for Python 3.8 has been dropped. Ensure you are running Python 3.9 or newer.
- gotcha When using Numpy-style docstrings, having a 'Methods' section within a class docstring can lead to parsing issues.
- gotcha For code blocks within docstrings or admonitions to render correctly, the `pymdownx.superfences` Markdown extension must be enabled. Newlines within docstring code blocks may also require escaping.
Install
-
pip install mkdocstrings-python-legacy -
pip install 'mkdocstrings[python-legacy]'
Quickstart
# mkdocs.yml
plugins:
- mkdocstrings:
handlers:
python:
paths: [src] # Adjust to your source code directory
options:
docstring_style: google # or numpy, restructured-text
members: !docstrings_replace # Example: show only documented members
# docs/index.md
# ::: my_package.my_module