1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
|
# Members options
[](){#option-members}
## `members`
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] |
<autoref identifier="bool" optional>bool</autoref> | None</code> :material-equal: `None`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
An explicit list of members to render.
Only members declared in this list will be rendered.
A member without a docstring will still be rendered,
even if [`show_if_no_docstring`][] is set to false.
The members will be rendered in the specified order,
regardless of the value of [`members_order`][].
**Note that members will still be grouped by category,
according to the [`group_by_category`][] option.**
Passing a falsy value (`no`, `false` in YAML) or an empty list (`[]`)
will tell the Python handler not to render any member.
Passing a truthy value (`yes`, `true` in YAML)
will tell the Python handler to render every member.
Any given value, except for an explicit `None` (`null` in YAML)
will tell the handler to ignore [`filters`][] for the object's members.
Filters will still be applied to the next layers of members (grand-children).
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
members:
- hello # (1)
```
1. :warning: Most of the time it won't make sense to use this option at the global level.
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
members:
- ThisClass
- this_function
```
```python title="package/module.py"
"""Module docstring."""
def this_function():
"""Function docstring."""
class ThisClass:
"""Class docstring."""
def method(self):
"""Method docstring."""
this_attribute = 0
"""Attribute docstring."""
```
/// admonition | Preview
type: preview
//// tab | With `members: true`
<p>Module docstring.</p>
<h2><code>this_function</code></h2>
<p>Function docstring.</p>
<h2><code>ThisClass</code></h2>
<p>Class docstring.</p>
<h3><code>method</code></h3>
<p>Method docstring.</p>
<h2><code>this_attribute</code></h2>
<p>Attribute docstring.</p>
////
//// tab | With `members: false` or `members: []`
<p>Module docstring.</p>
////
//// tab | With `members: [ThisClass]`
<p>Module docstring.</p>
<h2><code>ThisClass</code></h2>
<p>Class docstring.</p>
<h3><code>method</code></h3>
<p>Method docstring.</p>
////
///
INFO: **The default behavior (with unspecified `members` or `members: null`) is to use [`filters`][].**
[](){#option-inherited_members}
## `inherited_members`
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] |
<autoref identifier="bool" optional>bool</autoref></code> :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
An explicit list of inherited members (for classes) to render.
Inherited members are always fetched from classes that are in the same package
as the currently rendered class. To fetch members inherited from base classes,
themselves coming from external packages, use the [`preload_modules`][preload_modules] option.
For example, if your class inherits from Pydantic's `BaseModel`, and you want to render
`BaseModel`'s methods in your class, use `preload_modules: [pydantic]`.
The `pydantic` package must be available in the current environment.
Passing a falsy value (`no`, `false` in YAML) or an empty list (`[]`)
will tell the Python handler not to render any inherited member.
Passing a truthy value (`yes`, `true` in YAML)
will tell the Python handler to render every inherited member.
When all inherited members are selected with `inherited_members: true`,
it is possible to specify both members and inherited members in the `members` list:
```yaml
inherited_members: true
members:
- inherited_member_a
- inherited_member_b
- member_x
- member_y
```
The alternative is not supported:
```yaml
inherited_members:
- inherited_member_a
- inherited_member_b
members:
- member_x
- member_y
```
...because it would make members ordering ambiguous/unspecified.
You can render inherited members *only* by setting `inherited_members: true`
(or a list of inherited members) and setting `members: false`:
```yaml
inherited_members: true
members: false
```
```yaml
inherited_members:
- inherited_member_a
- inherited_member_b
members: false
```
You can render *all declared members* and all or specific inherited members
by leaving `members` as null (default):
```yaml
inherited_members:
- inherited_member_a
- inherited_member_b
# members: null # (1)
```
1. In this case, only declared members will be subject
to further filtering with [`filters`][filters] and [`docstrings`][show_if_no_docstring].
```yaml
inherited_members: true # (1)
# members: null
```
1. In this case, both declared and inherited members will be subject
to further filtering with [`filters`][filters] and [`docstrings`][show_if_no_docstring].
You can render *all declared members* and all or specific inherited members,
avoiding further filtering with [`filters`][filters] and [`docstrings`][show_if_no_docstring]
by setting `members: true`:
```yaml
inherited_members: true
members: true
```
```yaml
inherited_members:
- inherited_member_a
- inherited_member_b
members: true
```
The general rule is that declared or inherited members specified in lists
are never filtered out.
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
inherited_members: false
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
inherited_members: true
```
```python title="package/module.py"
"""Module docstring."""
class Base:
"""Base class."""
def base(self):
"""Base method."""
class Main(Base):
"""Main class."""
def main(self):
"""Main method."""
```
/// admonition | Preview
type: preview
//// tab | With inherited members
<p>Module docstring.</p>
<h2><code>Base</code></h2>
<p>Base class.</p>
<h3><code>base</code></h3>
<p>Base method.</p>
<h2><code>Main</code></h2>
<p>Main class.</p>
<h3><code>base</code></h3>
<p>Base method.</p>
<h3><code>main</code></h3>
<p>Main method.</p>
////
//// tab | Without inherited members
<p>Module docstring.</p>
<h2><code>Base</code></h2>
<p>Base class.</p>
<h3><code>base</code></h3>
<p>Base method.</p>
<h2><code>Main</code></h2>
<p>Main class.</p>
<h3><code>main</code></h3>
<p>Main method.</p>
////
///
[](){#option-members_order}
## `members_order`
- **:octicons-package-24: Type `str | list[str]` :material-equal: `"alphabetical"`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
The members ordering to use. Possible values:
- `__all__` ([:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } — [:octicons-tag-24: Insiders 1.12.0](../../insiders/changelog.md#1.12.0)): Order according to `__all__` attributes. Since classes do not define `__all__` attributes, you can specify a second ordering method by using a list.
- `alphabetical`: Order by the members names.
- `source`: Order members as they appear in the source file.
The order applies for all members, recursively.
The order will be ignored for members that are explicitely sorted using the [`members`][] option.
**Note that members will still be grouped by category,
according to the [`group_by_category`][] option.**
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
members_order: alphabetical
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
members_order: source
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
members_order: [__all__, source]
```
```python title="package/module.py"
"""Module docstring."""
def function_b():
"""Function a."""
def function_a():
"""Function b."""
def function_c():
"""Function c."""
```
/// admonition | Preview
type: preview
//// tab | With alphabetical order
<p>Module docstring.</p>
<h2><code>function_a</code></h2>
<p>Function a.</p>
<h2><code>function_b</code></h2>
<p>Function b.</p>
<h2><code>function_c</code></h2>
<p>Function c.</p>
////
//// tab | With source order
<p>Module docstring.</p>
<h2><code>function_b</code></h2>
<p>Function b.</p>
<h2><code>function_a</code></h2>
<p>Function a.</p>
<h2><code>function_c</code></h2>
<p>Function c.</p>
////
///
[](){#option-filters}
## `filters`
- **:octicons-package-24: Type <code><autoref identifier="list" optional>list</autoref>[<autoref identifier="str" optional>str</autoref>] | <autoref identifier="typing.Literal" optional>Literal</autoref>["public"] | None</code> :material-equal: `["!^_[^_]"]`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
A list of filters, or `"public"`.
**Filtering methods**
[](){#option-filters-public}
[:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } —
[:octicons-tag-24: Insiders 1.11.0](../../insiders/changelog.md#1.11.0)
The `public` filtering method will include only public objects: those added to the `__all__` attribute of modules, or not starting with a single underscore. Special methods and attributes ("dunder" methods/attributes, starting and ending with two underscores), like `__init__`, `__call__`, `__mult__`, etc., are always considered public.
**List of filters**
Filters are regular expressions. These regular expressions are evaluated by Python
and so must match the syntax supported by the [`re`][] module.
A filter starting with `!` (negative filter) will exclude matching objects instead of including them.
The default value (`["!^_[^_]"]`) means: *render every object, except those
starting with one underscore, unless they start with two underscores*.
It means that an object whose name is `hello`, `__hello`, or `__hello__`
will be rendered, but not one whose name is `_hello`.
Each filter takes precedence over the previous one. This allows for fine-grain
selection of objects by adding more specific filters. For example, you can
start by unselecting objects that start with `_`, and add a second filter
that re-select objects that start with `__`. The default filters can
therefore be rewritten like this:
```yaml
filters:
- "!^_"
- "^__"
```
If there are no negative filters, the handler considers that everything
is **unselected** first, and then selects things based on your positive filters.
If there is at least one negative filter, the handler considers that everything
is **selected** first, and then re-selects/unselects things based on your other filters.
In short, `filters: ["a"]` means *"keep ***nothing*** except names containing `a`"*, while
`filters: ["!a"]` means *"keep ***everything*** except names containing `a`"*.
An empty list of filters tells the Python handler to render every object.
The [`members`][] option takes precedence over filters
(filters will still be applied recursively to lower members in the hierarchy).
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
filters:
- "!^_[^_]"
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
filters: public
```
```python title="package/module.py"
def hello():
...
def _world():
...
```
/// admonition | Preview
type: preview
//// tab | With `filters: []`
<p>Module docstring.</p>
<h2><code>hello</code></h2>
<p>Function docstring.</p>
<h2><code>_world</code></h2>
<p>Function docstring.</p>
////
//// tab | With `filters: ["hello"]`
<p>Module docstring.</p>
<h2><code>hello</code></h2>
<p>Function docstring.</p>
////
//// tab | With `filters: ["!hello"]`
<p>Module docstring.</p>
<h2><code>_world</code></h2>
<p>Function docstring.</p>
////
///
/// admonition | Common filters
type: tip
Here are some common filters that you might to want to use.
- `["!^_"]`: exclude all private/protected/special objects
- `["!^_", "^__init__$"]`: same as above, but keep `__init__` methods
- `["!^_[^_]"]`: exclude all private/protected objects, keep special ones (default filters)
///
[](){#option-group_by_category}
## `group_by_category`
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
Group the object members by categories: attributes, classes, functions, and modules.
Members within a same category will be ordered according to the [`members_order`][] option.
You can use the [`show_category_heading`][] option to also render a heading for each category.
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
group_by_category: true
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
group_by_category: false
```
```python title="package/module.py"
def function_a():
...
class ClassB:
...
attribute_C = 0
def function_d():
...
```
/// admonition | Preview
type: preview
//// tab | With category grouping
<p>Module docstring.</p>
<h2><code>attribute_c</code></h2>
<p>Attribute docstring.</p>
<h2><code>ClassB</code></h2>
<p>Class docstring.</p>
<h2><code>function_a</code></h2>
<p>Function docstring.</p>
<h2><code>function_d</code></h2>
<p>Function docstring.</p>
////
//// tab | Without category grouping
<p>Module docstring.</p>
<h2><code>function_a</code></h2>
<p>Function docstring.</p>
<h2><code>ClassB</code></h2>
<p>Class docstring.</p>
<h2><code>attribute_c</code></h2>
<p>Attribute docstring.</p>
<h2><code>function_d</code></h2>
<p>Function docstring.</p>
////
///
[](){#option-show_submodules}
## `show_submodules`
- **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
When rendering a module, show its submodules recursively.
This is false by default, because most of the time we render only one module per page,
and when rendering a package (a tree of modules and their members) on a single page,
we quickly run out of [heading levels][heading_level].
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_submodules: true
```
```md title="or in docs/some_page.md (local configuration)"
::: package.subpackage
options:
show_submodules: false
```
```tree title="package"
package
__init__.py
subpackage
__init__.py
submodule.py
```
/// admonition | Preview
type: preview
//// tab | With submodules
<p>Subpackage docstring.</p>
<h2><code>subpackage_member</code></h2>
<p>Member docstring.</p>
<h2><code>submodule</code></h2>
<p>Submodule docstring.</p>
<h3><code>submodule_member</code></h3>
<p>Member docstring.</p>
////
//// tab | Without submodules
<p>Subpackage docstring.</p>
<h2><code>subpackage_member</code></h2>
<p>Member docstring.</p>
////
///
[](){#option-summary}
## `summary`
[:octicons-tag-24: Insiders 1.2.0](../../insiders/changelog.md#1.2.0)
- **:octicons-package-24: Type <code><autoref identifier="bool" optional>bool</autoref> | <autoref identifier="dict" optional>dict</autoref>[<autoref identifier="str" optional>str</autoref>, <autoref identifier="bool" optional>bool</autoref>]</code> :material-equal: `False`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
Whether to render summaries of modules, classes, functions (methods) and attributes.
This option accepts a boolean (`yes`, `true`, `no`, `false` in YAML)
or a dictionary with one or more of the following keys: `attributes`, `functions`, `classes`, `modules`,
with booleans as values. Class methods summary is (de)activated with the `functions` key.
By default, `summary` is false, and by extension all values are false.
Examples:
```yaml
summary: true
```
```yaml
summary: false
```
```yaml
summary:
attributes: false
functions: true
modules: false
```
Summaries will be rendered as the corresponding docstring sections.
For example, the summary for attributes will be rendered as an Attributes docstring section.
The section will be rendered in accordance with the [`docstring_section_style`][] option.
If the objects appearing in the summary are also rendered on the page
(or somewhere else on the site), their name will automatically link to their rendered documentation.
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
summary: true
```
```md title="or in docs/some_page.md (local configuration)"
::: path.to.module
options:
summary: false
```
/// admonition | Preview
type: preview
//// tab | With all summaries
```
::: path.to.module.MyClass
options:
summary: true
```
<h2>MyClass</h2>
<p>Class docstring.</p>
<p>Methods:</p>
<ul>
<li><a href="#my_method1">my_method1</a>: Summary of the method (first docstring line).</li>
<li><a href="#my_method2">my_method2</a>: Summary of the method (first docstring line).</li>
</ul>
<p>Attributes:</p>
<ul>
<li><a href="#attr1">attr1</a>: Summary of the attribute (first docstring line).</li>
<li><a href="#attr2">attr2</a>: Summary of the attribute (first docstring line).</li>
</ul>
////
//// tab | With methods summary only
```
::: path.to.module.MyClass
options:
summary:
functions: true
```
<h2>MyClass</h2>
<p>Class docstring.</p>
<p>Methods:</p>
<ul>
<li><a href="#my_method1">my_method1</a>: Summary of the method (first docstring line).</li>
<li><a href="#my_method2">my_method2</a>: Summary of the method (first docstring line).</li>
</ul>
////
///
[](){#option-show_labels}
## `show_labels`
- **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
<!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
Whether to show labels of the members.
```yaml title="in mkdocs.yml (global configuration)"
plugins:
- mkdocstrings:
handlers:
python:
options:
show_labels: true
```
```md title="or in docs/some_page.md (local configuration)"
::: package.module
options:
show_labels: false
```
```python title="package/module.py"
class SomeClass:
some_attr: int
```
/// admonition | Preview
type: preview
//// tab | With labels
<code class="highlight language-python">
<span class="n">some_attr</span><span class="p">:</span>
<span class="nb">int</span>
</code>
<small><code>instance-attribute</code></small>
////
//// tab | Without labels
<code class="highlight language-python">
<span class="n">some_attr</span><span class="p">:</span>
<span class="nb">int</span>
</code>
////
///
|