| 1 |
<h1 align="center">mkdocstrings-python</h1> |
| 2 |
|
| 3 |
<p align="center">A Python handler for <a href="https://github.com/mkdocstrings/mkdocstrings"><i>mkdocstrings</i></a>.</p> |
| 4 |
|
| 5 |
[](https://github.com/mkdocstrings/python/actions?query=workflow%3Aci) |
| 6 |
[](https://mkdocstrings.github.io/python/) |
| 7 |
[](https://pypi.org/project/mkdocstrings-python/) |
| 8 |
[](https://app.gitter.im/#/room/#mkdocstrings_python:gitter.im) |
| 9 |
|
| 10 |
--- |
| 11 |
|
| 12 |
<p align="center"><img src="logo.png"></p> |
| 13 |
|
| 14 |
The Python handler uses [Griffe](https://mkdocstrings.github.io/griffe) |
| 15 |
to collect documentation from Python source code. |
| 16 |
The word "griffe" can sometimes be used instead of "signature" in French. |
| 17 |
Griffe is able to visit the Abstract Syntax Tree (AST) of the source code to extract useful information. |
| 18 |
It is also able to execute the code (by importing it) and introspect objects in memory |
| 19 |
when source code is not available. Finally, it can parse docstrings following different styles. |
| 20 |
|
| 21 |
## Installation |
| 22 |
|
| 23 |
You can install this handler as a *mkdocstrings* extra: |
| 24 |
|
| 25 |
```toml title="pyproject.toml" |
| 26 |
# PEP 621 dependencies declaration |
| 27 |
# adapt to your dependencies manager |
| 28 |
[project] |
| 29 |
dependencies = [ |
| 30 |
"mkdocstrings[python]>=0.18", |
| 31 |
] |
| 32 |
``` |
| 33 |
|
| 34 |
You can also explicitly depend on the handler: |
| 35 |
|
| 36 |
```toml title="pyproject.toml" |
| 37 |
# PEP 621 dependencies declaration |
| 38 |
# adapt to your dependencies manager |
| 39 |
[project] |
| 40 |
dependencies = [ |
| 41 |
"mkdocstrings-python", |
| 42 |
] |
| 43 |
``` |
| 44 |
|
| 45 |
## Preview |
| 46 |
|
| 47 |
<!-- TODO: update the GIF with a more recent screen capture. Maybe use mp4 instead --> |
| 48 |
 |
| 49 |
|
| 50 |
## Features |
| 51 |
|
| 52 |
- **Data collection from source code**: collection of the object-tree and the docstrings is done thanks to |
| 53 |
[Griffe](https://github.com/mkdocstrings/griffe). |
| 54 |
|
| 55 |
- **Support for type annotations:** Griffe collects your type annotations and *mkdocstrings* uses them |
| 56 |
to display parameter types or return types. It is even able to automatically add cross-references |
| 57 |
to other objects from your API, from the standard library or third-party libraries! |
| 58 |
See [how to load inventories](https://mkdocstrings.github.io/usage/#cross-references-to-other-projects-inventories) to enable it. |
| 59 |
|
| 60 |
- **Recursive documentation of Python objects:** just use the module dotted-path as an identifier, and you get the full |
| 61 |
module docs. You don't need to inject documentation for each class, function, etc. |
| 62 |
|
| 63 |
- **Support for documented attributes:** attributes (variables) followed by a docstring (triple-quoted string) will |
| 64 |
be recognized by Griffe in modules, classes and even in `__init__` methods. |
| 65 |
|
| 66 |
- **Multiple docstring-styles support:** common support for Google-style, Numpydoc-style, |
| 67 |
and Sphinx-style docstrings. See [Griffe's documentation](https://mkdocstrings.github.io/griffe/docstrings/) on docstrings support. |
| 68 |
|
| 69 |
- **Admonition support in Google docstrings:** blocks like `Note:` or `Warning:` will be transformed |
| 70 |
to their [admonition](https://squidfunk.github.io/mkdocs-material/reference/admonitions/) equivalent. |
| 71 |
*We do not support nested admonitions in docstrings!* |
| 72 |
|
| 73 |
- **Every object has a TOC entry:** we render a heading for each object, meaning *MkDocs* picks them into the Table |
| 74 |
of Contents, which is nicely displayed by the Material theme. Thanks to *mkdocstrings* cross-reference ability, |
| 75 |
you can reference other objects within your docstrings, with the classic Markdown syntax: |
| 76 |
`[this object][package.module.object]` or directly with `[package.module.object][]` |
| 77 |
|
| 78 |
- **Source code display:** *mkdocstrings* can add a collapsible div containing the highlighted source code |
| 79 |
of the Python object. |
| 80 |
|
| 81 |
## Sponsors |
| 82 |
|
| 83 |
<!-- sponsors-start --> |
| 84 |
|
| 85 |
<div id="premium-sponsors" style="text-align: center;"> |
| 86 |
|
| 87 |
<div id="silver-sponsors"><b>Silver sponsors</b><p> |
| 88 |
<a href="https://fastapi.tiangolo.com/"><img alt="FastAPI" src="https://raw.githubusercontent.com/tiangolo/fastapi/master/docs/en/docs/img/logo-margin/logo-teal.png" style="height: 200px; "></a><br> |
| 89 |
</p></div> |
| 90 |
|
| 91 |
<div id="bronze-sponsors"><b>Bronze sponsors</b><p> |
| 92 |
<a href="https://www.nixtla.io/"><picture><source media="(prefers-color-scheme: light)" srcset="https://www.nixtla.io/img/logo/full-black.svg"><source media="(prefers-color-scheme: dark)" srcset="https://www.nixtla.io/img/logo/full-white.svg"><img alt="Nixtla" src="https://www.nixtla.io/img/logo/full-black.svg" style="height: 60px; "></picture></a><br> |
| 93 |
</p></div> |
| 94 |
</div> |
| 95 |
|
| 96 |
--- |
| 97 |
|
| 98 |
<div id="sponsors"><p> |
| 99 |
<a href="https://github.com/ofek"><img alt="ofek" src="https://avatars.githubusercontent.com/u/9677399?u=386c330f212ce467ce7119d9615c75d0e9b9f1ce&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 100 |
<a href="https://github.com/samuelcolvin"><img alt="samuelcolvin" src="https://avatars.githubusercontent.com/u/4039449?u=42eb3b833047c8c4b4f647a031eaef148c16d93f&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 101 |
<a href="https://github.com/tlambert03"><img alt="tlambert03" src="https://avatars.githubusercontent.com/u/1609449?u=922abf0524b47739b37095e553c99488814b05db&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 102 |
<a href="https://github.com/ssbarnea"><img alt="ssbarnea" src="https://avatars.githubusercontent.com/u/102495?u=c7bd9ddf127785286fc939dd18cb02db0a453bce&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 103 |
<a href="https://github.com/femtomc"><img alt="femtomc" src="https://avatars.githubusercontent.com/u/34410036?u=f13a71daf2a9f0d2da189beaa94250daa629e2d8&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 104 |
<a href="https://github.com/cmarqu"><img alt="cmarqu" src="https://avatars.githubusercontent.com/u/360986?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 105 |
<a href="https://github.com/kolenaIO"><img alt="kolenaIO" src="https://avatars.githubusercontent.com/u/77010818?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 106 |
<a href="https://github.com/ramnes"><img alt="ramnes" src="https://avatars.githubusercontent.com/u/835072?u=3fca03c3ba0051e2eb652b1def2188a94d1e1dc2&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 107 |
<a href="https://github.com/machow"><img alt="machow" src="https://avatars.githubusercontent.com/u/2574498?u=c41e3d2f758a05102d8075e38d67b9c17d4189d7&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 108 |
<a href="https://github.com/BenHammersley"><img alt="BenHammersley" src="https://avatars.githubusercontent.com/u/99436?u=4499a7b507541045222ee28ae122dbe3c8d08ab5&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 109 |
<a href="https://github.com/trevorWieland"><img alt="trevorWieland" src="https://avatars.githubusercontent.com/u/28811461?u=74cc0e3756c1d4e3d66b5c396e1d131ea8a10472&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 110 |
<a href="https://github.com/MarcoGorelli"><img alt="MarcoGorelli" src="https://avatars.githubusercontent.com/u/33491632?u=7de3a749cac76a60baca9777baf71d043a4f884d&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 111 |
<a href="https://github.com/analog-cbarber"><img alt="analog-cbarber" src="https://avatars.githubusercontent.com/u/7408243?u=fe0e7bf2882d1c9c901a341c2502e1518466527a&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 112 |
<a href="https://github.com/OdinManiac"><img alt="OdinManiac" src="https://avatars.githubusercontent.com/u/22727172?u=36ab20970f7f52ae8e7eb67b7fcf491fee01ac22&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 113 |
<a href="https://github.com/rstudio-sponsorship"><img alt="rstudio-sponsorship" src="https://avatars.githubusercontent.com/u/58949051?u=0c471515dd18111be30dfb7669ed5e778970959b&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 114 |
<a href="https://github.com/schlich"><img alt="schlich" src="https://avatars.githubusercontent.com/u/21191435?u=6f1240adb68f21614d809ae52d66509f46b1e877&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 115 |
<a href="https://github.com/butterlyn"><img alt="butterlyn" src="https://avatars.githubusercontent.com/u/53323535?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 116 |
<a href="https://github.com/livingbio"><img alt="livingbio" src="https://avatars.githubusercontent.com/u/10329983?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 117 |
<a href="https://github.com/NemetschekAllplan"><img alt="NemetschekAllplan" src="https://avatars.githubusercontent.com/u/912034?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 118 |
<a href="https://github.com/EricJayHartman"><img alt="EricJayHartman" src="https://avatars.githubusercontent.com/u/9259499?u=7e58cc7ec0cd3e85b27aec33656aa0f6612706dd&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 119 |
<a href="https://github.com/15r10nk"><img alt="15r10nk" src="https://avatars.githubusercontent.com/u/44680962?u=f04826446ff165742efa81e314bd03bf1724d50e&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 120 |
<a href="https://github.com/activeloopai"><img alt="activeloopai" src="https://avatars.githubusercontent.com/u/34816118?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 121 |
<a href="https://github.com/roboflow"><img alt="roboflow" src="https://avatars.githubusercontent.com/u/53104118?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 122 |
<a href="https://github.com/cmclaughlin"><img alt="cmclaughlin" src="https://avatars.githubusercontent.com/u/1061109?u=ddf6eec0edd2d11c980f8c3aa96e3d044d4e0468&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 123 |
<a href="https://github.com/RapidataAI"><img alt="RapidataAI" src="https://avatars.githubusercontent.com/u/104209891?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 124 |
<a href="https://github.com/rodolphebarbanneau"><img alt="rodolphebarbanneau" src="https://avatars.githubusercontent.com/u/46493454?u=6c405452a40c231cdf0b68e97544e07ee956a733&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 125 |
<a href="https://github.com/theSymbolSyndicate"><img alt="theSymbolSyndicate" src="https://avatars.githubusercontent.com/u/111542255?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 126 |
<a href="https://github.com/blakeNaccarato"><img alt="blakeNaccarato" src="https://avatars.githubusercontent.com/u/20692450?u=bb919218be30cfa994514f4cf39bb2f7cf952df4&v=4" style="height: 32px; border-radius: 100%;"></a> |
| 127 |
<a href="https://github.com/ChargeStorm"><img alt="ChargeStorm" src="https://avatars.githubusercontent.com/u/26000165?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 128 |
<a href="https://github.com/Cusp-AI"><img alt="Cusp-AI" src="https://avatars.githubusercontent.com/u/178170649?v=4" style="height: 32px; border-radius: 100%;"></a> |
| 129 |
</p></div> |
| 130 |
|
| 131 |
|
| 132 |
*And 4 more private sponsor(s).* |
| 133 |
|
| 134 |
<!-- sponsors-end --> |