Skip to content

General options¤

allow_inspection¤

Whether to allow inspecting modules (importing them) when it is not possible to visit them (parse their source code).

When loading data for a given package, Griffe discovers every Python module, compiled or not, and inspects or visits them accordingly.

If you have compiled modules but also provide stubs for them, you might want to disable the inspection of these modules, because inspection picks up many more members, and sometimes the collected data is inaccurate (depending on the tool that was used to compile the module) or too low-level/technical for API documentation.

in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          allow_inspection: true
or in docs/some_page.md (local configuration)
::: path.to.object
    options:
      allow_inspection: false

Preview

SomeClass

Docstring of the class.

__eq__

Method docstring.

__weakref__

Method docstring.

documented_method

Method docstring.

SomeClass

Docstring of the class.

documented_method

Method docstring.

show_bases¤

Show the base classes of a class.

in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          show_bases: true
or in docs/some_page.md (local configuration)
::: path.to.object
    options:
      show_bases: false

Preview

SomeClass()

Bases: SomeBaseClass

Docstring of the class.

SomeClass()

Docstring of the class.

show_inheritance_diagram¤

Sponsors only Insiders 1.7.0

Show the inheritance diagram of a class using Mermaid.

With this option enabled, an inheritance diagram (as a flowchart) will be displayed after a class signature. Each node will act as a cross-reference and will bring you to the relevant class' documentation when clicking on it.

It should work out of the box with Material for MkDocs. For other themes, you must include Mermaid's Javascript code manually:

mkdocs.yml
extra_javascript:
- https://unpkg.com/mermaid@10.9.0/dist/mermaid.min.js
in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          show_inheritance_diagram: true
or in docs/some_page.md (local configuration)
::: path.to.object
    options:
      show_inheritance_diagram: false

Preview

With the following classes:

class SuperAbstract:
    """Super abstract class."""
class Mixin1:
    """Mixin 1."""
class Abstract(SuperAbstract, Mixin1):
    """Abstract class."""
class Mixin2A:
    """Mixin 2A."""
class Mixin2B(Mixin2A):
    """Mixin 2B."""
class Concrete(Abstract, Mixin2B):
    """Concrete class."""
class SuperConcrete(Concrete):
    """Super concrete class."""

The diagram for SuperConcrete will look like this:

flowchart TD
SuperConcrete[SuperConcrete]
Concrete[Concrete]
Abstract[Abstract]
SuperAbstract[SuperAbstract]
Mixin1[Mixin1]
Mixin2B[Mixin2B]
Mixin2A[Mixin2A]

Concrete --> SuperConcrete
Abstract --> Concrete
SuperAbstract --> Abstract
Mixin1 --> Abstract
Mixin2B --> Concrete
Mixin2A --> Mixin2B

Nodes are not clickable in this example because these classes do not exist in our documentation.

show_source¤

Show the source code of this object.

in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          show_source: true
or in docs/some_page.md (local configuration)
::: path.to.object
    options:
      show_source: false

Preview

some_function()

Docstring of the function.

Source code in package/module.py
1
2
def some_function():
    ...

some_function()

Docstring of the function.

preload_modules¤

Pre-load modules that are not specified directly in autodoc instructions (::: identifier). It is useful when you want to render documentation for a particular member of an object, and this member is imported from another package than its parent.

For an imported member to be rendered, you need to add it to the __all__ attribute of the importing module. The package from which the imported object originates must be accessible to the handler (see Finding modules).

in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          preload_modules:
          - their_package
or in docs/some_page.md (local configuration)
::: your_package.your_module
    options:
      preload_modules:
      - their_package   
your_package/your_module.py
from their_package.their_module import their_object

__all__ = ["their_object"]

# rest of your code

Preview

your_module

Docstring of your module.

their_object

Docstring of their object.

your_module

Docstring of your module.

find_stubs_package¤

When looking for documentation specified in autodoc instructions (::: identifier), also look for the stubs package as defined in PEP 561 if it exists. This is useful when most of your documentation is separately provided by such a package and not inline in your main package.

in mkdocs.yml (global configuration)
plugins:
- mkdocstrings:
    handlers:
      python:
        options:
          find_stubs_package: true
or in docs/some_page.md (local configuration)
::: your_package.your_module.your_func
    options:
      find_stubs_package: true
your_package/your_module.py
def your_func(a, b):
    # Function code
    ...

# rest of your code
your_package-stubs/your_module.pyi
def your_func(a: int, b: str):
    """
    <Function docstring>
    """
    ...

# rest of your code

Preview

your_func

Function docstring

your_func