Skip to content

MkDocstrings Plugin

Auto-generate API documentation from Python docstrings.

Core Attributes

Plugin Name

mkdocstrings

Installation

Bash
pip install mkdocstrings[python]

Configuration

YAML
plugins:
  - mkdocstrings:
      enabled: true
      default_handler: python
      handlers:
        python:
          options:
            show_source: true
            show_root_heading: true
            docstring_style: google
            members_order: source
            show_signature: true

Usage

Basic Usage

Markdown
::: mymodule.MyClass

With Options

Markdown
::: mymodule.MyClass
    options:
      show_source: false
      members:
        - method1
        - method2

Selective Rendering

Markdown
::: mymodule
    options:
      members:
        - important_function
        - CriticalClass
      filters:
        - "!^_"  # Exclude private

Docstring Styles

Google Style

Python
def function(arg1: str, arg2: int) -> bool:
    """
    Short description.

    Longer description of the function.

    Args:
        arg1: Description of arg1
        arg2: Description of arg2

    Returns:
        Description of return value

    Raises:
        ValueError: When something is wrong

    Examples:
        >>> function("test", 42)
        True
    """
    pass

NumPy Style

Python
def function(arg1, arg2):
    """
    Short description.

    Parameters
    ----------
    arg1 : str
        Description of arg1
    arg2 : int
        Description of arg2

    Returns
    -------
    bool
        Description of return value
    """
    pass

Options Reference

show_source

Display source code: true or false

show_signature

Show function signatures: true or false

docstring_style

Style: google, numpy, or sphinx

members_order

Order: source or alphabetical

show_if_no_docstring

Show undocumented members: true or false

merge_init_into_class

Merge __init__ into class docs: true or false

Best Practices

  1. Write comprehensive docstrings
  2. Use type hints consistently
  3. Include examples in docstrings
  4. Document all parameters and returns
  5. Use consistent docstring style
  6. Group related functionality