Automatic documentation from sources, for MkDocs.
Project description
mkdocstrings
Automatic documentation from sources, for MkDocs.
Features
-
Language-agnostic: just like MkDocs, mkdocstrings is written in Python but is language-agnostic. It means you can use it with any programming language, as long as there is a handler for it. The Python handler is built-in. Others are external. Maybe you'd like to add another one to the list? :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-links across pages: mkdocstrings makes it possible to reference headings in other Markdown files with the classic Markdown linking syntax:
[identifier][]
or[title][identifier]
-- and you don't need to remember which exact page this object was on. This works for any heading that's produced by a mkdocstrings language handler, and you can opt to include any Markdown heading into the global referencing scheme.Note: in versions prior to 0.15 all Markdown headers were included, but now you need to opt in.
-
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.
-
Reasonable 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 astaticmethod
, aclassmethod
, 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
understandsArguments:
,Raises:
andReturns:
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. Note: only RST style is supported, not the whole markup. - Admonition support in docstrings: blocks like
Note:
orWarning:
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.
- Support for type annotations:
- 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:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mkdocstrings-0.15.0.tar.gz
.
File metadata
- Download URL: mkdocstrings-0.15.0.tar.gz
- Upload date:
- Size: 28.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.11.1-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e46125c7381beccb79f213468fb4e5c4492d1c6881c06b8afbec30c737733c |
|
MD5 | e6bd68b4f9c98e0a72e90f28b0e2053a |
|
BLAKE2b-256 | 8cf5fa4154389be3ba56ab78a3ad309cad30cb59b10e42e847ffd3b69796ca6b |
File details
Details for the file mkdocstrings-0.15.0-py3-none-any.whl
.
File metadata
- Download URL: mkdocstrings-0.15.0-py3-none-any.whl
- Upload date:
- Size: 40.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.11.1-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9891420c6b9e91903a4cdf4eaf5b79dab71f3af992f7871fb43fb0f869bb26f |
|
MD5 | 013e66dd857fccf608bd78df5f8be25b |
|
BLAKE2b-256 | b87fe2b9ea48c6328fc5ae8a066bafbf3c5412ce8f400feefe4dfce35025d2a3 |