Skip to main content

Automatic documentation from sources, for MkDocs.

Project description

mkdocstrings

ci documentation pypi version conda version gitter

Automatic documentation from sources, for MkDocs.


mkdocstrings_gif1


Features

  • Language agnostic: just like mkdocs, mkdocstrings is written in Python but is language-agnostic. It means you can use it for any language, as long as you implement a handler for it. Currently, we only have a Python handler. Maybe you'd like to contribute another one :wink:?
  • Multiple themes support: each handler can offer multiple themes. Currently, we offer the :star: Material theme :star: as well as basic support for the ReadTheDocs theme for the Python handler.
  • Cross-references to other objects: mkdocstrings makes it possible to reference other headings from your Markdown files with the classic Markdown syntax: [identifier][] or [title][identifier]. This feature is language agnostic as well: you can cross-reference any heading that appear in your Markdown pages. If the handler for a particular language renders headings for documented objects, you'll be able to reference them!
  • Inline injection in Markdown: instead of generating Markdown files, mkdocstrings allows you to inject documentation anywhere in your Markdown contents. The syntax is simple: ::: identifier followed by a 4-spaces indented YAML block. The identifier and YAML configuration will be passed to the appropriate handler to collect and render documentation.
  • Global and local configuration: each handler can be configured globally in mkdocs.yml, and locally for each "autodoc" instruction.
  • Watch source code directories: you can tell mkdocstrings to add directories to be watched by mkdocs when serving the documentation, for auto-reload.
  • Sane defaults: you should be able to just drop the plugin in your configuration and enjoy your auto-generated docs.

Python handler features

  • Data collection from source code: collection of the object-tree and the docstrings is done by pytkdocs. The following features are possible thanks to it:
    • Support for type annotations: pytkdocs collects your type annotations and mkdocstrings uses them to display parameters types or return types.
    • Recursive documentation of Python objects: just use the module dotted-path as identifier, and you get the full module docs. You don't need to inject documentation for each class, function, etc.
    • Support for documented attribute: attributes (variables) followed by a docstring (triple-quoted string) will be recognized by pytkdocs in modules, classes and even in __init__ methods.
    • Support for objects properties: pytkdocs detects if a method is a staticmethod, a classmethod, etc., it also detects if a property is read-only or writable, and more! These properties will be displayed next to the object signature by mkdocstrings.
    • Google-style sections support in docstrings: pytkdocs understands Arguments:, Raises: and Returns: sections, and returns structured data for mkdocstrings to render them.
    • reStructuredText-style sections support in docstrings: pytkdocs understands all the reStructuredText fields, and returns structured data for mkdocstrings to render them.
    • Admonition support in docstrings: blocks like Note: or Warning: will be transformed to their admonition equivalent. We do not support nested admonitions in docstrings!
    • Support for reStructuredText in docstrings: pytkdocs can parse simple RST.
  • Every object has a TOC entry: we render a heading for each object, meaning mkdocs picks them into the Table of Contents, which is nicely display by the Material theme. Thanks to mkdocstrings cross-reference ability, you can even reference other objects within your docstrings, with the classic Markdown syntax: [this object][package.module.object] or directly with [package.module.object][]
  • Source code display: mkdocstrings can add a collapsible div containing the highlighted source code of the Python object.

To get an example of what is possible, check mkdocstrings' own documentation, auto-generated from sources by itself of course, and the following GIF:

mkdocstrings_gif2

Roadmap

See the Feature Roadmap issue on the bugtracker.

Requirements

mkdocstrings requires Python 3.6 or above.

To install Python 3.6, I recommend using pyenv.
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"

# install Python 3.6
pyenv install 3.6.12

# make it available globally
pyenv global system 3.6.12

This project currently only works with the Material theme of MkDocs. Therefore, it is required that you have it installed.

pip install mkdocs-material

Installation

With pip:

python3.6 -m pip install mkdocstrings

With conda:

conda install -c conda-forge mkdocstrings

Quick usage

# mkdocs.yml
theme:
  name: "material"

plugins:
- search
- mkdocstrings

In one of your markdown files:

# Reference

::: my_library.my_module.my_class

See the Usage section of the docs for more examples!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocstrings-0.14.0b1.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

mkdocstrings-0.14.0b1-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file mkdocstrings-0.14.0b1.tar.gz.

File metadata

  • Download URL: mkdocstrings-0.14.0b1.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.9.14-arch1-1

File hashes

Hashes for mkdocstrings-0.14.0b1.tar.gz
Algorithm Hash digest
SHA256 81eac96a539701547fa81c7be15993ccb71710cc94fbd7fbbf8a179e690ecea1
MD5 56a4e99907689f6f7e872d2b172348e1
BLAKE2b-256 7f7244de82d609635fbc74ddffe3108e358144a0e02ef714237fd6a8e8d69398

See more details on using hashes here.

File details

Details for the file mkdocstrings-0.14.0b1-py3-none-any.whl.

File metadata

  • Download URL: mkdocstrings-0.14.0b1-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.9.14-arch1-1

File hashes

Hashes for mkdocstrings-0.14.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 d63d965ecc0259cdcc6acf1262ec4a229000fc6e6ba81f53aed70d47b2d45589
MD5 9104535116d96fc2a42472265c79b894
BLAKE2b-256 a341a65017bd2346087240ba6e8644c822092b5d31ccbcff6c9a2f6b37d3278b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page