Skip to content

python ¤

Python handler for mkdocstrings.

Modules:

  • config

    Deprecated. Import from mkdocstrings_handlers.python directly.

  • handler

    Deprecated. Import from mkdocstrings_handlers.python directly.

  • rendering

    Deprecated. Import from mkdocstrings_handlers.python directly.

Classes:

Functions:

Attributes:

  • Order

    Ordering methods.

  • Tree

    A tree type. Each node holds a tuple of items.

  • do_stash_crossref

    Filter to stash cross-references (and restore them after formatting and highlighting).

Order module-attribute ¤

Order = Literal['alphabetical', 'source']

Ordering methods.

Tree module-attribute ¤

Tree = dict[tuple[_T, ...], 'Tree']

A tree type. Each node holds a tuple of items.

do_stash_crossref module-attribute ¤

do_stash_crossref = _StashCrossRefFilter()

Filter to stash cross-references (and restore them after formatting and highlighting).

AutoStyleOptions dataclass ¤

AutoStyleOptions(
    method: Literal["heuristics", "max_sections"] = "heuristics",
    style_order: list[str] = lambda: ["sphinx", "google", "numpy"](),
    default: str | None = None,
    per_style_options: PerStyleOptions = PerStyleOptions(),
)

Auto style docstring options.

Methods:

  • from_data

    Create an instance from a dictionary.

Attributes:

default class-attribute instance-attribute ¤

default: str | None = None

The default docstring style to use if no other style is detected.

method class-attribute instance-attribute ¤

method: Literal['heuristics', 'max_sections'] = 'heuristics'

The method to use to determine the docstring style.

per_style_options class-attribute instance-attribute ¤

per_style_options: PerStyleOptions = field(default_factory=PerStyleOptions)

Per-style options.

style_order class-attribute instance-attribute ¤

style_order: list[str] = field(default_factory=lambda: ['sphinx', 'google', 'numpy'])

The order of the docstring styles to try.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

AutorefsHook ¤

AutorefsHook(current_object: Object | Alias, config: dict[str, Any])

Autorefs hook.

With this hook, we're able to add context to autorefs (cross-references), such as originating file path and line number, to improve error reporting.

Parameters:

  • current_object ¤

    (Object | Alias) –

    The object being rendered.

  • config ¤

    (dict[str, Any]) –

    The configuration dictionary.

Methods:

Attributes:

config instance-attribute ¤

config = config

The configuration options.

current_object instance-attribute ¤

current_object = current_object

The current object being rendered.

expand_identifier ¤

expand_identifier(identifier: str) -> str

Expand an identifier.

Parameters:

  • identifier ¤

    (str) –

    The identifier to expand.

Returns:

  • str

    The expanded identifier.

get_context ¤

get_context() -> Context

Get the context for the current object.

Returns:

GoogleStyleOptions dataclass ¤

GoogleStyleOptions(
    ignore_init_summary: bool = False,
    returns_multiple_items: bool = True,
    returns_named_value: bool = True,
    returns_type_in_property_summary: bool = False,
    receives_multiple_items: bool = True,
    receives_named_value: bool = True,
    trim_doctest_flags: bool = True,
    warn_unknown_params: bool = True,
)

Google style docstring options.

Attributes:

ignore_init_summary class-attribute instance-attribute ¤

ignore_init_summary: bool = False

Whether to ignore the summary in __init__ methods' docstrings.

receives_multiple_items class-attribute instance-attribute ¤

receives_multiple_items: bool = True

Whether to parse multiple items in Receives sections.

When true, each item's continuation lines must be indented. When false (single item), no further indentation is required.

receives_named_value class-attribute instance-attribute ¤

receives_named_value: bool = True

Whether to parse Receives section items as name and description, rather than type and description.

When true, type must be wrapped in parentheses: (int): Description.. Names are optional: name (int): Description.. When false, parentheses are optional but the items cannot be named: int: Description.

returns_multiple_items class-attribute instance-attribute ¤

returns_multiple_items: bool = True

Whether to parse multiple items in Yields and Returns sections.

When true, each item's continuation lines must be indented. When false (single item), no further indentation is required.

returns_named_value class-attribute instance-attribute ¤

returns_named_value: bool = True

Whether to parse Yields and Returns section items as name and description, rather than type and description.

When true, type must be wrapped in parentheses: (int): Description.. Names are optional: name (int): Description.. When false, parentheses are optional but the items cannot be named: int: Description.

returns_type_in_property_summary class-attribute instance-attribute ¤

returns_type_in_property_summary: bool = False

Whether to parse the return type of properties at the beginning of their summary: str: Summary of the property.

trim_doctest_flags class-attribute instance-attribute ¤

trim_doctest_flags: bool = True

Whether to remove doctest flags from Python example blocks.

warn_unknown_params class-attribute instance-attribute ¤

warn_unknown_params: bool = True

Warn about documented parameters not appearing in the signature.

Inventory dataclass ¤

Inventory(url: str, base: str | None = None, domains: list[str] = lambda: ['py']())

An inventory.

Attributes:

  • base (str | None) –

    The base URL of the inventory.

  • domains (list[str]) –

    The domains to load from the inventory.

  • url (str) –

    The URL of the inventory.

base class-attribute instance-attribute ¤

base: str | None = None

The base URL of the inventory.

domains class-attribute instance-attribute ¤

domains: list[str] = field(default_factory=lambda: ['py'])

The domains to load from the inventory.

url instance-attribute ¤

url: str

The URL of the inventory.

NumpyStyleOptions dataclass ¤

NumpyStyleOptions(
    ignore_init_summary: bool = False,
    trim_doctest_flags: bool = True,
    warn_unknown_params: bool = True,
)

Numpy style docstring options.

Attributes:

ignore_init_summary class-attribute instance-attribute ¤

ignore_init_summary: bool = False

Whether to ignore the summary in __init__ methods' docstrings.

trim_doctest_flags class-attribute instance-attribute ¤

trim_doctest_flags: bool = True

Whether to remove doctest flags from Python example blocks.

warn_unknown_params class-attribute instance-attribute ¤

warn_unknown_params: bool = True

Warn about documented parameters not appearing in the signature.

PerStyleOptions dataclass ¤

Per style options.

Methods:

  • from_data

    Create an instance from a dictionary.

Attributes:

google class-attribute instance-attribute ¤

google: GoogleStyleOptions = field(default_factory=GoogleStyleOptions)

Google-style options.

numpy class-attribute instance-attribute ¤

numpy: NumpyStyleOptions = field(default_factory=NumpyStyleOptions)

Numpydoc-style options.

sphinx class-attribute instance-attribute ¤

sphinx: SphinxStyleOptions = field(default_factory=SphinxStyleOptions)

Sphinx-style options.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

PythonConfig dataclass ¤

PythonConfig(
    inventories: list[Inventory] = list(),
    paths: list[str] = lambda: ["."](),
    load_external_modules: bool | None = None,
    options: dict[str, Any] = dict(),
    locale: str | None = None,
)

Python handler configuration.

Methods:

  • coerce

    Coerce data.

  • from_data

    Create an instance from a dictionary.

Attributes:

inventories class-attribute instance-attribute ¤

inventories: list[Inventory] = field(default_factory=list)

The object inventories to load.

load_external_modules class-attribute instance-attribute ¤

load_external_modules: bool | None = None

Whether to always load external modules/packages.

locale class-attribute instance-attribute ¤

locale: str | None = None

The locale to use when translating template strings.

options class-attribute instance-attribute ¤

options: dict[str, Any] = field(default_factory=dict)

Configuration options for collecting and rendering objects.

paths class-attribute instance-attribute ¤

paths: list[str] = field(default_factory=lambda: ['.'])

The paths in which to search for Python packages.

coerce classmethod ¤

coerce(**data: Any) -> MutableMapping[str, Any]

Coerce data.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

PythonHandler ¤

PythonHandler(config: PythonConfig, base_dir: Path, **kwargs: Any)

The Python handler class.

Parameters:

  • config ¤

    (PythonConfig) –

    The handler configuration.

  • base_dir ¤

    (Path) –

    The base directory of the project.

  • **kwargs ¤

    (Any, default: {} ) –

    Arguments passed to the parent constructor.

Methods:

  • collect

    Collect the documentation for the given identifier.

  • do_convert_markdown

    Render Markdown text; for use inside templates.

  • do_heading

    Render an HTML heading and register it for the table of contents. For use inside templates.

  • get_aliases

    Get the aliases for the given identifier.

  • get_extended_templates_dirs

    Load template extensions for the given handler, return their templates directories.

  • get_headings

    Return and clear the headings gathered so far.

  • get_inventory_urls

    Return the URLs of the inventory files to download.

  • get_options

    Get combined default, global and local options.

  • get_templates_dir

    Return the path to the handler's templates directory.

  • load_inventory

    Yield items and their URLs from an inventory file streamed from in_file.

  • normalize_extension_paths

    Resolve extension paths relative to config file.

  • render

    Render the collected data.

  • render_backlinks

    Render the backlinks.

  • teardown

    Teardown the handler.

  • update_env

    Update the Jinja environment with custom filters and tests.

Attributes:

  • base_dir

    The base directory of the project.

  • config

    The handler configuration.

  • custom_templates

    The path to custom templates.

  • domain (str) –

    The cross-documentation domain/language for this handler.

  • enable_inventory (bool) –

    Whether this handler is interested in enabling the creation of the objects.inv Sphinx inventory file.

  • env

    The Jinja environment.

  • extra_css (str) –

    Extra CSS.

  • fallback_config (dict) –

    Fallback configuration when searching anchors for identifiers.

  • fallback_theme (str) –

    The fallback theme.

  • global_options

    The global configuration options (in mkdocs.yml).

  • md (Markdown) –

    The Markdown instance.

  • mdx

    The Markdown extensions to use.

  • mdx_config

    The configuration for the Markdown extensions.

  • name (str) –

    The handler's name.

  • outer_layer (bool) –

    Whether we're in the outer Markdown conversion layer.

  • theme

    The selected theme.

base_dir instance-attribute ¤

base_dir = base_dir

The base directory of the project.

config instance-attribute ¤

config = config

The handler configuration.

custom_templates instance-attribute ¤

custom_templates = custom_templates

The path to custom templates.

domain class-attribute ¤

domain: str = 'py'

The cross-documentation domain/language for this handler.

enable_inventory class-attribute ¤

enable_inventory: bool = True

Whether this handler is interested in enabling the creation of the objects.inv Sphinx inventory file.

env instance-attribute ¤

env = Environment(autoescape=True, loader=FileSystemLoader(paths), auto_reload=False)

The Jinja environment.

extra_css class-attribute instance-attribute ¤

extra_css: str = ''

Extra CSS.

fallback_config class-attribute ¤

fallback_config: dict = {}

Fallback configuration when searching anchors for identifiers.

fallback_theme class-attribute ¤

fallback_theme: str = 'material'

The fallback theme.

global_options instance-attribute ¤

global_options = global_options

The global configuration options (in mkdocs.yml).

md property ¤

The Markdown instance.

Raises:

  • RuntimeError

    When the Markdown instance is not set yet.

mdx instance-attribute ¤

mdx = mdx

The Markdown extensions to use.

mdx_config instance-attribute ¤

mdx_config = mdx_config

The configuration for the Markdown extensions.

name class-attribute ¤

name: str = 'python'

The handler's name.

outer_layer property ¤

outer_layer: bool

Whether we're in the outer Markdown conversion layer.

theme instance-attribute ¤

theme = theme

The selected theme.

collect ¤

Collect the documentation for the given identifier.

Parameters:

  • identifier ¤

    (str) –

    The identifier of the object to collect.

  • options ¤

    (PythonOptions) –

    The options to use for the collection.

Returns:

do_convert_markdown ¤

do_convert_markdown(
    text: str,
    heading_level: int,
    html_id: str = "",
    *,
    strip_paragraph: bool = False,
    autoref_hook: AutorefsHookInterface | None = None
) -> Markup

Render Markdown text; for use inside templates.

Parameters:

  • text ¤

    (str) –

    The text to convert.

  • heading_level ¤

    (int) –

    The base heading level to start all Markdown headings from.

  • html_id ¤

    (str, default: '' ) –

    The HTML id of the element that's considered the parent of this element.

  • strip_paragraph ¤

    (bool, default: False ) –

    Whether to exclude the <p> tag from around the whole output.

Returns:

  • Markup

    An HTML string.

do_heading ¤

do_heading(
    content: Markup,
    heading_level: int,
    *,
    role: str | None = None,
    hidden: bool = False,
    toc_label: str | None = None,
    **attributes: str
) -> Markup

Render an HTML heading and register it for the table of contents. For use inside templates.

Parameters:

  • content ¤

    (Markup) –

    The HTML within the heading.

  • heading_level ¤

    (int) –

    The level of heading (e.g. 3 -> h3).

  • role ¤

    (str | None, default: None ) –

    An optional role for the object bound to this heading.

  • hidden ¤

    (bool, default: False ) –

    If True, only register it for the table of contents, don't render anything.

  • toc_label ¤

    (str | None, default: None ) –

    The title to use in the table of contents ('data-toc-label' attribute).

  • **attributes ¤

    (str, default: {} ) –

    Any extra HTML attributes of the heading.

Returns:

  • Markup

    An HTML string.

get_aliases ¤

get_aliases(identifier: str) -> tuple[str, ...]

Get the aliases for the given identifier.

Parameters:

  • identifier ¤

    (str) –

    The identifier to get the aliases for.

Returns:

get_extended_templates_dirs ¤

get_extended_templates_dirs(handler: str) -> list[Path]

Load template extensions for the given handler, return their templates directories.

Parameters:

  • handler ¤

    (str) –

    The name of the handler to get the extended templates directory of.

Returns:

  • list[Path]

    The extensions templates directories.

get_headings ¤

get_headings() -> Sequence[Element]

Return and clear the headings gathered so far.

Returns:

get_inventory_urls ¤

get_inventory_urls() -> list[tuple[str, dict[str, Any]]]

Return the URLs of the inventory files to download.

get_options ¤

Get combined default, global and local options.

Parameters:

Returns:

get_templates_dir ¤

get_templates_dir(handler: str | None = None) -> Path

Return the path to the handler's templates directory.

Override to customize how the templates directory is found.

Parameters:

  • handler ¤

    (str | None, default: None ) –

    The name of the handler to get the templates directory of.

Raises:

Returns:

  • Path

    The templates directory path.

load_inventory staticmethod ¤

load_inventory(
    in_file: BinaryIO,
    url: str,
    base_url: str | None = None,
    domains: list[str] | None = None,
    **kwargs: Any
) -> Iterator[tuple[str, str]]

Yield items and their URLs from an inventory file streamed from in_file.

This implements mkdocstrings' load_inventory "protocol" (see mkdocstrings.plugin).

Parameters:

  • in_file ¤

    (BinaryIO) –

    The binary file-like object to read the inventory from.

  • url ¤

    (str) –

    The URL that this file is being streamed from (used to guess base_url).

  • base_url ¤

    (str | None, default: None ) –

    The URL that this inventory's sub-paths are relative to.

  • domains ¤

    (list[str] | None, default: None ) –

    A list of domain strings to filter the inventory by, when not passed, "py" will be used.

  • **kwargs ¤

    (Any, default: {} ) –

    Ignore additional arguments passed from the config.

Yields:

  • tuple[str, str]

    Tuples of (item identifier, item URL).

normalize_extension_paths ¤

normalize_extension_paths(extensions: Sequence) -> Sequence

Resolve extension paths relative to config file.

Parameters:

  • extensions ¤

    (Sequence) –

    The extensions (configuration) to normalize.

Returns:

  • Sequence

    The normalized extensions.

render ¤

Render the collected data.

Parameters:

Returns:

  • str

    The rendered data (HTML).

render_backlinks(backlinks: Mapping[str, Iterable[Backlink]]) -> str

Render the backlinks.

Parameters:

Returns:

  • str

    The rendered backlinks (HTML).

teardown ¤

teardown() -> None

Teardown the handler.

This method should be implemented to, for example, terminate a subprocess that was started when creating the handler instance.

update_env ¤

update_env(config: Any) -> None

Update the Jinja environment with custom filters and tests.

Parameters:

  • config ¤

    (Any) –

    The SSG configuration.

PythonInputConfig dataclass ¤

PythonInputConfig(
    inventories: list[str | Inventory] = list(),
    paths: list[str] = lambda: ["."](),
    load_external_modules: bool | None = None,
    options: PythonInputOptions = PythonInputOptions(),
    locale: str | None = None,
)

Python handler configuration.

Methods:

  • coerce

    Coerce data.

  • from_data

    Create an instance from a dictionary.

Attributes:

inventories class-attribute instance-attribute ¤

inventories: list[str | Inventory] = field(default_factory=list)

The inventories to load.

load_external_modules class-attribute instance-attribute ¤

load_external_modules: bool | None = None

Whether to always load external modules/packages.

locale class-attribute instance-attribute ¤

locale: str | None = None

The locale to use when translating template strings.

options class-attribute instance-attribute ¤

options: PythonInputOptions = field(default_factory=PythonInputOptions)

Configuration options for collecting and rendering objects.

paths class-attribute instance-attribute ¤

paths: list[str] = field(default_factory=lambda: ['.'])

The paths in which to search for Python packages.

coerce classmethod ¤

coerce(**data: Any) -> MutableMapping[str, Any]

Coerce data.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

PythonInputOptions dataclass ¤

PythonInputOptions(
    allow_inspection: bool = True,
    force_inspection: bool = False,
    annotations_path: Literal["brief", "source", "full"] = "brief",
    backlinks: Literal["flat", "tree", False] = False,
    docstring_options: (
        GoogleStyleOptions
        | NumpyStyleOptions
        | SphinxStyleOptions
        | AutoStyleOptions
        | None
    ) = None,
    docstring_section_style: Literal["table", "list", "spacy"] = "table",
    docstring_style: Literal["auto", "google", "numpy", "sphinx"] | None = "google",
    extensions: list[str | dict[str, Any]] = list(),
    filters: list[str] | Literal["public"] = lambda: copy()(),
    find_stubs_package: bool = False,
    group_by_category: bool = True,
    heading: str = "",
    heading_level: int = 2,
    inherited_members: bool | list[str] = False,
    line_length: int = 60,
    members: list[str] | bool | None = None,
    members_order: Literal["alphabetical", "source"] = "alphabetical",
    merge_init_into_class: bool = False,
    modernize_annotations: bool = False,
    parameter_headings: bool = False,
    preload_modules: list[str] = list(),
    relative_crossrefs: bool = False,
    scoped_crossrefs: bool = False,
    show_overloads: bool = True,
    separate_signature: bool = False,
    show_bases: bool = True,
    show_category_heading: bool = False,
    show_docstring_attributes: bool = True,
    show_docstring_classes: bool = True,
    show_docstring_description: bool = True,
    show_docstring_examples: bool = True,
    show_docstring_functions: bool = True,
    show_docstring_modules: bool = True,
    show_docstring_other_parameters: bool = True,
    show_docstring_parameters: bool = True,
    show_docstring_raises: bool = True,
    show_docstring_receives: bool = True,
    show_docstring_returns: bool = True,
    show_docstring_warns: bool = True,
    show_docstring_yields: bool = True,
    show_if_no_docstring: bool = False,
    show_inheritance_diagram: bool = False,
    show_labels: bool = True,
    show_object_full_path: bool = False,
    show_root_full_path: bool = True,
    show_root_heading: bool = False,
    show_root_members_full_path: bool = False,
    show_root_toc_entry: bool = True,
    show_signature_annotations: bool = False,
    show_signature: bool = True,
    show_source: bool = True,
    show_submodules: bool = False,
    show_symbol_type_heading: bool = False,
    show_symbol_type_toc: bool = False,
    signature_crossrefs: bool = False,
    summary: bool | SummaryOption = SummaryOption(),
    toc_label: str = "",
    unwrap_annotated: bool = False,
    extra: dict[str, Any] = dict(),
)

Accepted input options.

Methods:

  • coerce

    Coerce data.

  • from_data

    Create an instance from a dictionary.

Attributes:

allow_inspection class-attribute instance-attribute ¤

allow_inspection: bool = True

Whether to allow inspecting modules when visiting them is not possible.

annotations_path class-attribute instance-attribute ¤

annotations_path: Literal['brief', 'source', 'full'] = 'brief'

The verbosity for annotations path: brief (recommended), source (as written in the source), or full.

backlinks: Literal['flat', 'tree', False] = False

Whether to render backlinks, and how.

docstring_options class-attribute instance-attribute ¤

docstring_options: (
    GoogleStyleOptions
    | NumpyStyleOptions
    | SphinxStyleOptions
    | AutoStyleOptions
    | None
) = None

The options for the docstring parser.

See docstring parsers and their options in Griffe docs.

docstring_section_style class-attribute instance-attribute ¤

docstring_section_style: Literal['table', 'list', 'spacy'] = 'table'

The style used to render docstring sections.

docstring_style class-attribute instance-attribute ¤

docstring_style: Literal['auto', 'google', 'numpy', 'sphinx'] | None = 'google'

The docstring style to use: auto, google, numpy, sphinx, or None.

extensions class-attribute instance-attribute ¤

extensions: list[str | dict[str, Any]] = field(default_factory=list)

A list of Griffe extensions to load.

extra class-attribute instance-attribute ¤

extra: dict[str, Any] = field(default_factory=dict)

Extra options.

filters class-attribute instance-attribute ¤

filters: list[str] | Literal['public'] = field(default_factory=lambda: copy())

A list of filters, or "public".

List of filters

A filter starting with ! will exclude matching objects instead of including them. The members option takes precedence over filters (filters will still be applied recursively to lower members in the hierarchy).

Filtering methods

Sponsors only Insiders 1.11.0

The public method will include only public objects: those added to __all__ or not starting with an underscore (except for special methods/attributes).

find_stubs_package class-attribute instance-attribute ¤

find_stubs_package: bool = False

Whether to load stubs package (package-stubs) when extracting docstrings.

force_inspection class-attribute instance-attribute ¤

force_inspection: bool = False

Whether to force using dynamic analysis when loading data.

group_by_category class-attribute instance-attribute ¤

group_by_category: bool = True

Group the object's children by categories: attributes, classes, functions, and modules.

heading class-attribute instance-attribute ¤

heading: str = ''

A custom string to override the autogenerated heading of the root object.

heading_level class-attribute instance-attribute ¤

heading_level: int = 2

The initial heading level to use.

inherited_members class-attribute instance-attribute ¤

inherited_members: bool | list[str] = False

A boolean, or an explicit list of inherited members to render.

If true, select all inherited members, which can then be filtered with members. If false or empty list, do not select any inherited member.

line_length class-attribute instance-attribute ¤

line_length: int = 60

Maximum line length when formatting code/signatures.

members class-attribute instance-attribute ¤

members: list[str] | bool | None = None

A boolean, or an explicit list of members to render.

If true, select all members without further filtering. If false or empty list, do not render members. If none, select all members and apply further filtering with filters and docstrings.

members_order class-attribute instance-attribute ¤

members_order: Literal['alphabetical', 'source'] = 'alphabetical'

The members ordering to use.

  • alphabetical: order by the members names,
  • source: order members as they appear in the source file.

merge_init_into_class class-attribute instance-attribute ¤

merge_init_into_class: bool = False

Whether to merge the __init__ method into the class' signature and docstring.

modernize_annotations class-attribute instance-attribute ¤

modernize_annotations: bool = False

Whether to modernize annotations, for example Optional[str] into str | None.

parameter_headings class-attribute instance-attribute ¤

parameter_headings: bool = False

Whether to render headings for parameters (therefore showing parameters in the ToC).

preload_modules class-attribute instance-attribute ¤

preload_modules: list[str] = field(default_factory=list)

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 modules must be listed as an array of strings.

relative_crossrefs class-attribute instance-attribute ¤

relative_crossrefs: bool = False

Whether to enable the relative crossref syntax.

scoped_crossrefs class-attribute instance-attribute ¤

scoped_crossrefs: bool = False

Whether to enable the scoped crossref ability.

separate_signature class-attribute instance-attribute ¤

separate_signature: bool = False

Whether to put the whole signature in a code block below the heading.

If Black or Ruff are installed, the signature is also formatted using them.

show_bases class-attribute instance-attribute ¤

show_bases: bool = True

Show the base classes of a class.

show_category_heading class-attribute instance-attribute ¤

show_category_heading: bool = False

When grouped by categories, show a heading for each category.

show_docstring_attributes class-attribute instance-attribute ¤

show_docstring_attributes: bool = True

Whether to display the 'Attributes' section in the object's docstring.

show_docstring_classes class-attribute instance-attribute ¤

show_docstring_classes: bool = True

Whether to display the 'Classes' section in the object's docstring.

show_docstring_description class-attribute instance-attribute ¤

show_docstring_description: bool = True

Whether to display the textual block (including admonitions) in the object's docstring.

show_docstring_examples class-attribute instance-attribute ¤

show_docstring_examples: bool = True

Whether to display the 'Examples' section in the object's docstring.

show_docstring_functions class-attribute instance-attribute ¤

show_docstring_functions: bool = True

Whether to display the 'Functions' or 'Methods' sections in the object's docstring.

show_docstring_modules class-attribute instance-attribute ¤

show_docstring_modules: bool = True

Whether to display the 'Modules' section in the object's docstring.

show_docstring_other_parameters class-attribute instance-attribute ¤

show_docstring_other_parameters: bool = True

Whether to display the 'Other Parameters' section in the object's docstring.

show_docstring_parameters class-attribute instance-attribute ¤

show_docstring_parameters: bool = True

Whether to display the 'Parameters' section in the object's docstring.

show_docstring_raises class-attribute instance-attribute ¤

show_docstring_raises: bool = True

Whether to display the 'Raises' section in the object's docstring.

show_docstring_receives class-attribute instance-attribute ¤

show_docstring_receives: bool = True

Whether to display the 'Receives' section in the object's docstring.

show_docstring_returns class-attribute instance-attribute ¤

show_docstring_returns: bool = True

Whether to display the 'Returns' section in the object's docstring.

show_docstring_warns class-attribute instance-attribute ¤

show_docstring_warns: bool = True

Whether to display the 'Warns' section in the object's docstring.

show_docstring_yields class-attribute instance-attribute ¤

show_docstring_yields: bool = True

Whether to display the 'Yields' section in the object's docstring.

show_if_no_docstring class-attribute instance-attribute ¤

show_if_no_docstring: bool = False

Show the object heading even if it has no docstring or children with docstrings.

show_inheritance_diagram class-attribute instance-attribute ¤

show_inheritance_diagram: bool = False

Show the inheritance diagram of a class using Mermaid.

show_labels class-attribute instance-attribute ¤

show_labels: bool = True

Whether to show labels of the members.

show_object_full_path class-attribute instance-attribute ¤

show_object_full_path: bool = False

Show the full Python path of every object.

show_overloads class-attribute instance-attribute ¤

show_overloads: bool = True

Show the overloads of a function or method.

show_root_full_path class-attribute instance-attribute ¤

show_root_full_path: bool = True

Show the full Python path for the root object heading.

show_root_heading class-attribute instance-attribute ¤

show_root_heading: bool = False

Show the heading of the object at the root of the documentation tree.

The root object is the object referenced by the identifier after :::.

show_root_members_full_path class-attribute instance-attribute ¤

show_root_members_full_path: bool = False

Show the full Python path of the root members.

show_root_toc_entry class-attribute instance-attribute ¤

show_root_toc_entry: bool = True

If the root heading is not shown, at least add a ToC entry for it.

show_signature class-attribute instance-attribute ¤

show_signature: bool = True

Show methods and functions signatures.

show_signature_annotations class-attribute instance-attribute ¤

show_signature_annotations: bool = False

Show the type annotations in methods and functions signatures.

show_source class-attribute instance-attribute ¤

show_source: bool = True

Show the source code of this object.

show_submodules class-attribute instance-attribute ¤

show_submodules: bool = False

When rendering a module, show its submodules recursively.

show_symbol_type_heading class-attribute instance-attribute ¤

show_symbol_type_heading: bool = False

Show the symbol type in headings (e.g. mod, class, meth, func and attr).

show_symbol_type_toc class-attribute instance-attribute ¤

show_symbol_type_toc: bool = False

Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).

signature_crossrefs class-attribute instance-attribute ¤

signature_crossrefs: bool = False

Whether to render cross-references for type annotations in signatures.

summary class-attribute instance-attribute ¤

summary: bool | SummaryOption = field(default_factory=SummaryOption)

Whether to render summaries of modules, classes, functions (methods) and attributes.

toc_label class-attribute instance-attribute ¤

toc_label: str = ''

A custom string to override the autogenerated toc label of the root object.

unwrap_annotated class-attribute instance-attribute ¤

unwrap_annotated: bool = False

Whether to unwrap Annotated types to show only the type without the annotations.

coerce classmethod ¤

coerce(**data: Any) -> MutableMapping[str, Any]

Coerce data.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

PythonOptions dataclass ¤

PythonOptions(
    allow_inspection: bool = True,
    force_inspection: bool = False,
    annotations_path: Literal["brief", "source", "full"] = "brief",
    backlinks: Literal["flat", "tree", False] = False,
    docstring_options: (
        GoogleStyleOptions
        | NumpyStyleOptions
        | SphinxStyleOptions
        | AutoStyleOptions
        | None
    ) = None,
    docstring_section_style: Literal["table", "list", "spacy"] = "table",
    docstring_style: Literal["auto", "google", "numpy", "sphinx"] | None = "google",
    extensions: list[str | dict[str, Any]] = list(),
    filters: list[tuple[Pattern, bool]] | Literal["public"] = lambda: [
        (compile(removeprefix("!")), startswith("!")) for filtr in _DEFAULT_FILTERS
    ](),
    find_stubs_package: bool = False,
    group_by_category: bool = True,
    heading: str = "",
    heading_level: int = 2,
    inherited_members: bool | list[str] = False,
    line_length: int = 60,
    members: list[str] | bool | None = None,
    members_order: Literal["alphabetical", "source"] = "alphabetical",
    merge_init_into_class: bool = False,
    modernize_annotations: bool = False,
    parameter_headings: bool = False,
    preload_modules: list[str] = list(),
    relative_crossrefs: bool = False,
    scoped_crossrefs: bool = False,
    show_overloads: bool = True,
    separate_signature: bool = False,
    show_bases: bool = True,
    show_category_heading: bool = False,
    show_docstring_attributes: bool = True,
    show_docstring_classes: bool = True,
    show_docstring_description: bool = True,
    show_docstring_examples: bool = True,
    show_docstring_functions: bool = True,
    show_docstring_modules: bool = True,
    show_docstring_other_parameters: bool = True,
    show_docstring_parameters: bool = True,
    show_docstring_raises: bool = True,
    show_docstring_receives: bool = True,
    show_docstring_returns: bool = True,
    show_docstring_warns: bool = True,
    show_docstring_yields: bool = True,
    show_if_no_docstring: bool = False,
    show_inheritance_diagram: bool = False,
    show_labels: bool = True,
    show_object_full_path: bool = False,
    show_root_full_path: bool = True,
    show_root_heading: bool = False,
    show_root_members_full_path: bool = False,
    show_root_toc_entry: bool = True,
    show_signature_annotations: bool = False,
    show_signature: bool = True,
    show_source: bool = True,
    show_submodules: bool = False,
    show_symbol_type_heading: bool = False,
    show_symbol_type_toc: bool = False,
    signature_crossrefs: bool = False,
    summary: SummaryOption = SummaryOption(),
    toc_label: str = "",
    unwrap_annotated: bool = False,
    extra: dict[str, Any] = dict(),
)

Final options passed as template context.

Methods:

  • coerce

    Create an instance from a dictionary.

  • from_data

    Create an instance from a dictionary.

Attributes:

allow_inspection class-attribute instance-attribute ¤

allow_inspection: bool = True

Whether to allow inspecting modules when visiting them is not possible.

annotations_path class-attribute instance-attribute ¤

annotations_path: Literal['brief', 'source', 'full'] = 'brief'

The verbosity for annotations path: brief (recommended), source (as written in the source), or full.

backlinks: Literal['flat', 'tree', False] = False

Whether to render backlinks, and how.

docstring_options class-attribute instance-attribute ¤

docstring_options: (
    GoogleStyleOptions
    | NumpyStyleOptions
    | SphinxStyleOptions
    | AutoStyleOptions
    | None
) = None

The options for the docstring parser.

See docstring parsers and their options in Griffe docs.

docstring_section_style class-attribute instance-attribute ¤

docstring_section_style: Literal['table', 'list', 'spacy'] = 'table'

The style used to render docstring sections.

docstring_style class-attribute instance-attribute ¤

docstring_style: Literal['auto', 'google', 'numpy', 'sphinx'] | None = 'google'

The docstring style to use: auto, google, numpy, sphinx, or None.

extensions class-attribute instance-attribute ¤

extensions: list[str | dict[str, Any]] = field(default_factory=list)

A list of Griffe extensions to load.

extra class-attribute instance-attribute ¤

extra: dict[str, Any] = field(default_factory=dict)

Extra options.

filters class-attribute instance-attribute ¤

filters: list[tuple[Pattern, bool]] | Literal["public"] = field(
    default_factory=lambda: [
        (compile(removeprefix("!")), startswith("!")) for filtr in _DEFAULT_FILTERS
    ]
)

A list of filters, or "public".

find_stubs_package class-attribute instance-attribute ¤

find_stubs_package: bool = False

Whether to load stubs package (package-stubs) when extracting docstrings.

force_inspection class-attribute instance-attribute ¤

force_inspection: bool = False

Whether to force using dynamic analysis when loading data.

group_by_category class-attribute instance-attribute ¤

group_by_category: bool = True

Group the object's children by categories: attributes, classes, functions, and modules.

heading class-attribute instance-attribute ¤

heading: str = ''

A custom string to override the autogenerated heading of the root object.

heading_level class-attribute instance-attribute ¤

heading_level: int = 2

The initial heading level to use.

inherited_members class-attribute instance-attribute ¤

inherited_members: bool | list[str] = False

A boolean, or an explicit list of inherited members to render.

If true, select all inherited members, which can then be filtered with members. If false or empty list, do not select any inherited member.

line_length class-attribute instance-attribute ¤

line_length: int = 60

Maximum line length when formatting code/signatures.

members class-attribute instance-attribute ¤

members: list[str] | bool | None = None

A boolean, or an explicit list of members to render.

If true, select all members without further filtering. If false or empty list, do not render members. If none, select all members and apply further filtering with filters and docstrings.

members_order class-attribute instance-attribute ¤

members_order: Literal['alphabetical', 'source'] = 'alphabetical'

The members ordering to use.

  • alphabetical: order by the members names,
  • source: order members as they appear in the source file.

merge_init_into_class class-attribute instance-attribute ¤

merge_init_into_class: bool = False

Whether to merge the __init__ method into the class' signature and docstring.

modernize_annotations class-attribute instance-attribute ¤

modernize_annotations: bool = False

Whether to modernize annotations, for example Optional[str] into str | None.

parameter_headings class-attribute instance-attribute ¤

parameter_headings: bool = False

Whether to render headings for parameters (therefore showing parameters in the ToC).

preload_modules class-attribute instance-attribute ¤

preload_modules: list[str] = field(default_factory=list)

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 modules must be listed as an array of strings.

relative_crossrefs class-attribute instance-attribute ¤

relative_crossrefs: bool = False

Whether to enable the relative crossref syntax.

scoped_crossrefs class-attribute instance-attribute ¤

scoped_crossrefs: bool = False

Whether to enable the scoped crossref ability.

separate_signature class-attribute instance-attribute ¤

separate_signature: bool = False

Whether to put the whole signature in a code block below the heading.

If Black or Ruff are installed, the signature is also formatted using them.

show_bases class-attribute instance-attribute ¤

show_bases: bool = True

Show the base classes of a class.

show_category_heading class-attribute instance-attribute ¤

show_category_heading: bool = False

When grouped by categories, show a heading for each category.

show_docstring_attributes class-attribute instance-attribute ¤

show_docstring_attributes: bool = True

Whether to display the 'Attributes' section in the object's docstring.

show_docstring_classes class-attribute instance-attribute ¤

show_docstring_classes: bool = True

Whether to display the 'Classes' section in the object's docstring.

show_docstring_description class-attribute instance-attribute ¤

show_docstring_description: bool = True

Whether to display the textual block (including admonitions) in the object's docstring.

show_docstring_examples class-attribute instance-attribute ¤

show_docstring_examples: bool = True

Whether to display the 'Examples' section in the object's docstring.

show_docstring_functions class-attribute instance-attribute ¤

show_docstring_functions: bool = True

Whether to display the 'Functions' or 'Methods' sections in the object's docstring.

show_docstring_modules class-attribute instance-attribute ¤

show_docstring_modules: bool = True

Whether to display the 'Modules' section in the object's docstring.

show_docstring_other_parameters class-attribute instance-attribute ¤

show_docstring_other_parameters: bool = True

Whether to display the 'Other Parameters' section in the object's docstring.

show_docstring_parameters class-attribute instance-attribute ¤

show_docstring_parameters: bool = True

Whether to display the 'Parameters' section in the object's docstring.

show_docstring_raises class-attribute instance-attribute ¤

show_docstring_raises: bool = True

Whether to display the 'Raises' section in the object's docstring.

show_docstring_receives class-attribute instance-attribute ¤

show_docstring_receives: bool = True

Whether to display the 'Receives' section in the object's docstring.

show_docstring_returns class-attribute instance-attribute ¤

show_docstring_returns: bool = True

Whether to display the 'Returns' section in the object's docstring.

show_docstring_warns class-attribute instance-attribute ¤

show_docstring_warns: bool = True

Whether to display the 'Warns' section in the object's docstring.

show_docstring_yields class-attribute instance-attribute ¤

show_docstring_yields: bool = True

Whether to display the 'Yields' section in the object's docstring.

show_if_no_docstring class-attribute instance-attribute ¤

show_if_no_docstring: bool = False

Show the object heading even if it has no docstring or children with docstrings.

show_inheritance_diagram class-attribute instance-attribute ¤

show_inheritance_diagram: bool = False

Show the inheritance diagram of a class using Mermaid.

show_labels class-attribute instance-attribute ¤

show_labels: bool = True

Whether to show labels of the members.

show_object_full_path class-attribute instance-attribute ¤

show_object_full_path: bool = False

Show the full Python path of every object.

show_overloads class-attribute instance-attribute ¤

show_overloads: bool = True

Show the overloads of a function or method.

show_root_full_path class-attribute instance-attribute ¤

show_root_full_path: bool = True

Show the full Python path for the root object heading.

show_root_heading class-attribute instance-attribute ¤

show_root_heading: bool = False

Show the heading of the object at the root of the documentation tree.

The root object is the object referenced by the identifier after :::.

show_root_members_full_path class-attribute instance-attribute ¤

show_root_members_full_path: bool = False

Show the full Python path of the root members.

show_root_toc_entry class-attribute instance-attribute ¤

show_root_toc_entry: bool = True

If the root heading is not shown, at least add a ToC entry for it.

show_signature class-attribute instance-attribute ¤

show_signature: bool = True

Show methods and functions signatures.

show_signature_annotations class-attribute instance-attribute ¤

show_signature_annotations: bool = False

Show the type annotations in methods and functions signatures.

show_source class-attribute instance-attribute ¤

show_source: bool = True

Show the source code of this object.

show_submodules class-attribute instance-attribute ¤

show_submodules: bool = False

When rendering a module, show its submodules recursively.

show_symbol_type_heading class-attribute instance-attribute ¤

show_symbol_type_heading: bool = False

Show the symbol type in headings (e.g. mod, class, meth, func and attr).

show_symbol_type_toc class-attribute instance-attribute ¤

show_symbol_type_toc: bool = False

Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).

signature_crossrefs class-attribute instance-attribute ¤

signature_crossrefs: bool = False

Whether to render cross-references for type annotations in signatures.

summary class-attribute instance-attribute ¤

summary: SummaryOption = field(default_factory=SummaryOption)

Whether to render summaries of modules, classes, functions (methods) and attributes.

toc_label class-attribute instance-attribute ¤

toc_label: str = ''

A custom string to override the autogenerated toc label of the root object.

unwrap_annotated class-attribute instance-attribute ¤

unwrap_annotated: bool = False

Whether to unwrap Annotated types to show only the type without the annotations.

coerce classmethod ¤

coerce(**data: Any) -> MutableMapping[str, Any]

Create an instance from a dictionary.

from_data classmethod ¤

from_data(**data: Any) -> Self

Create an instance from a dictionary.

SphinxStyleOptions dataclass ¤

SphinxStyleOptions()

Sphinx style docstring options.

SummaryOption dataclass ¤

SummaryOption(
    attributes: bool = False,
    functions: bool = False,
    classes: bool = False,
    modules: bool = False,
)

Summary option.

Attributes:

  • attributes (bool) –

    Whether to render summaries of attributes.

  • classes (bool) –

    Whether to render summaries of classes.

  • functions (bool) –

    Whether to render summaries of functions (methods).

  • modules (bool) –

    Whether to render summaries of modules.

attributes class-attribute instance-attribute ¤

attributes: bool = False

Whether to render summaries of attributes.

classes class-attribute instance-attribute ¤

classes: bool = False

Whether to render summaries of classes.

functions class-attribute instance-attribute ¤

functions: bool = False

Whether to render summaries of functions (methods).

modules class-attribute instance-attribute ¤

modules: bool = False

Whether to render summaries of modules.

do_as_attributes_section ¤

do_as_attributes_section(
    context: Context, attributes: Sequence[Attribute], *, check_public: bool = True
) -> DocstringSectionAttributes

Build an attributes section from a list of attributes.

Parameters:

  • attributes ¤

    (Sequence[Attribute]) –

    The attributes to build the section from.

  • check_public ¤

    (bool, default: True ) –

    Whether to check if the attribute is public.

Returns:

do_as_classes_section ¤

do_as_classes_section(
    context: Context, classes: Sequence[Class], *, check_public: bool = True
) -> DocstringSectionClasses

Build a classes section from a list of classes.

Parameters:

  • classes ¤

    (Sequence[Class]) –

    The classes to build the section from.

  • check_public ¤

    (bool, default: True ) –

    Whether to check if the class is public.

Returns:

do_as_functions_section ¤

do_as_functions_section(
    context: Context, functions: Sequence[Function], *, check_public: bool = True
) -> DocstringSectionFunctions

Build a functions section from a list of functions.

Parameters:

  • functions ¤

    (Sequence[Function]) –

    The functions to build the section from.

  • check_public ¤

    (bool, default: True ) –

    Whether to check if the function is public.

Returns:

do_as_modules_section ¤

do_as_modules_section(
    context: Context, modules: Sequence[Module], *, check_public: bool = True
) -> DocstringSectionModules

Build a modules section from a list of modules.

Parameters:

  • modules ¤

    (Sequence[Module]) –

    The modules to build the section from.

  • check_public ¤

    (bool, default: True ) –

    Whether to check if the module is public.

Returns:

do_backlink_tree(backlinks: list[Backlink]) -> Tree[BacklinkCrumb]

Build a tree of backlinks.

Parameters:

Returns:

do_crossref ¤

do_crossref(path: str, *, brief: bool = True) -> Markup

Deprecated. Filter to create cross-references.

Parameters:

  • path ¤

    (str) –

    The path to link to.

  • brief ¤

    (bool, default: True ) –

    Show only the last part of the path, add full path as hover.

Returns:

  • Markup

    Markup text.

do_filter_objects ¤

do_filter_objects(
    objects_dictionary: dict[str, Object | Alias],
    *,
    filters: Sequence[tuple[Pattern, bool]] | Literal["public"] | None = None,
    members_list: bool | list[str] | None = None,
    inherited_members: bool | list[str] = False,
    keep_no_docstrings: bool = True
) -> list[Object | Alias]

Filter a dictionary of objects based on their docstrings.

Parameters:

  • objects_dictionary ¤

    (dict[str, Object | Alias]) –

    The dictionary of objects.

  • filters ¤

    (Sequence[tuple[Pattern, bool]] | Literal['public'] | None, default: None ) –

    Filters to apply, based on members' names, or "public". Each element is a tuple: a pattern, and a boolean indicating whether to reject the object if the pattern matches.

  • members_list ¤

    (bool | list[str] | None, default: None ) –

    An optional, explicit list of members to keep. When given and empty, return an empty list. When given and not empty, ignore filters and docstrings presence/absence.

  • inherited_members ¤

    (bool | list[str], default: False ) –

    Whether to keep inherited members or exclude them.

  • keep_no_docstrings ¤

    (bool, default: True ) –

    Whether to keep objects with no/empty docstrings (recursive check).

Returns:

do_format_attribute ¤

do_format_attribute(
    context: Context,
    attribute_path: Markup,
    attribute: Attribute,
    line_length: int,
    *,
    crossrefs: bool = False
) -> str

Format an attribute.

Parameters:

  • context ¤

    (Context) –

    Jinja context, passed automatically.

  • attribute_path ¤

    (Markup) –

    The path of the callable we render the signature of.

  • attribute ¤

    (Attribute) –

    The attribute we render the signature of.

  • line_length ¤

    (int) –

    The line length.

  • crossrefs ¤

    (bool, default: False ) –

    Whether to cross-reference types in the signature.

Returns:

  • str

    The same code, formatted.

do_format_code ¤

do_format_code(code: str, line_length: int) -> str

Format code.

Parameters:

  • code ¤

    (str) –

    The code to format.

  • line_length ¤

    (int) –

    The line length.

Returns:

  • str

    The same code, formatted.

do_format_signature ¤

do_format_signature(
    context: Context,
    callable_path: Markup,
    function: Function,
    line_length: int,
    *,
    annotations: bool | None = None,
    crossrefs: bool = False
) -> str

Format a signature.

Parameters:

  • context ¤

    (Context) –

    Jinja context, passed automatically.

  • callable_path ¤

    (Markup) –

    The path of the callable we render the signature of.

  • function ¤

    (Function) –

    The function we render the signature of.

  • line_length ¤

    (int) –

    The line length.

  • annotations ¤

    (bool | None, default: None ) –

    Whether to show type annotations.

  • crossrefs ¤

    (bool, default: False ) –

    Whether to cross-reference types in the signature.

Returns:

  • str

    The same code, formatted.

do_get_template ¤

do_get_template(env: Environment, obj: str | Object) -> str

Get the template name used to render an object.

Parameters:

  • env ¤

    (Environment) –

    The Jinja environment, passed automatically.

  • obj ¤

    (str | Object) –

    A Griffe object, or a template name.

Returns:

  • str

    A template name.

do_multi_crossref ¤

do_multi_crossref(text: str, *, code: bool = True) -> Markup

Deprecated. Filter to create cross-references.

Parameters:

  • text ¤

    (str) –

    The text to scan.

  • code ¤

    (bool, default: True ) –

    Whether to wrap the result in a code tag.

Returns:

  • Markup

    Markup text.

do_order_members ¤

do_order_members(
    members: Sequence[Object | Alias],
    order: Order,
    members_list: bool | list[str] | None,
) -> Sequence[Object | Alias]

Order members given an ordering method.

Parameters:

Returns:

do_split_path ¤

do_split_path(path: str, full_path: str) -> Iterator[tuple[str, str, str, str]]

Split object paths for building cross-references.

Parameters:

  • path ¤

    (str) –

    The path to split.

  • full_path ¤

    (str) –

    The full path, used to compute correct paths for each part of the path.

Yields:

get_handler ¤

get_handler(
    handler_config: MutableMapping[str, Any], tool_config: MkDocsConfig, **kwargs: Any
) -> PythonHandler

Return an instance of PythonHandler.

Parameters:

  • handler_config ¤

    (MutableMapping[str, Any]) –

    The handler configuration.

  • tool_config ¤

    (MkDocsConfig) –

    The tool (SSG) configuration.

Returns:

config ¤

Deprecated. Import from mkdocstrings_handlers.python directly.

handler ¤

Deprecated. Import from mkdocstrings_handlers.python directly.

rendering ¤

Deprecated. Import from mkdocstrings_handlers.python directly.

Was this page helpful?