griffe2md ¤
griffe2md package.
Output API docs to Markdown using Griffe.
Modules:
-
cli
–Deprecated. Import from
griffe2md
directly. -
main
–Deprecated. Import from
griffe2md
directly. -
rendering
–Deprecated. Import from
griffe2md
directly.
Classes:
-
ConfigDict
–Configuration for griffe2md, griffe and mkdocstrings.
-
Order
–Enumeration for the possible members ordering.
Functions:
-
do_any
–Check if at least one of the item in the sequence evaluates to true.
-
do_as_attributes_section
–Build an attributes section from a list of attributes.
-
do_as_classes_section
–Build a classes section from a list of classes.
-
do_as_functions_section
–Build a functions section from a list of functions.
-
do_as_modules_section
–Build a modules section from a list of modules.
-
do_filter_objects
–Filter a dictionary of objects based on their docstrings.
-
do_format_attribute
–Format an attribute using Black.
-
do_format_code
–Format code using Black.
-
do_format_signature
–Format a signature using Black.
-
do_heading
–Render a Markdown heading.
-
do_order_members
–Order members given an ordering method.
-
do_split_path
–Split object paths for building cross-references.
-
from_private_package
–Tell if an alias points to an object coming from a corresponding private package.
-
get_parser
–Return the CLI argument parser.
-
load_config
–Load the configuration if config file or config entry in pyproject.toml exists.
-
prepare_context
–Prepare Jinja context.
-
prepare_env
–Prepare Jinja environment.
-
render_object_docs
–Render docs for a given object.
-
render_package_docs
–Render docs for a given package.
-
write_package_docs
–Write docs for a given package to a file or stdout.
Attributes:
-
CONFIG_FILE_PATHS
–Paths to default configuration files.
-
default_config
(ConfigDict
) –Default configuration values.
-
order_map
–Order mapping for sorting objects.
CONFIG_FILE_PATHS module-attribute
¤
CONFIG_FILE_PATHS = (
Path(".config/griffe2md.toml"),
Path("config/griffe2md.toml"),
Path("pyproject.toml"),
)
Paths to default configuration files.
default_config module-attribute
¤
default_config: ConfigDict = {
"docstring_style": "google",
"docstring_options": {"ignore_init_summary": True},
"show_root_heading": True,
"show_root_full_path": True,
"show_root_members_full_path": True,
"show_object_full_path": True,
"show_category_heading": False,
"show_if_no_docstring": True,
"show_signature": True,
"show_signature_annotations": False,
"signature_crossrefs": False,
"separate_signature": True,
"line_length": 80,
"merge_init_into_class": True,
"show_docstring_attributes": True,
"show_docstring_description": True,
"show_docstring_examples": True,
"show_docstring_other_parameters": True,
"show_docstring_parameters": True,
"show_docstring_raises": True,
"show_docstring_receives": True,
"show_docstring_returns": True,
"show_docstring_warns": True,
"show_docstring_yields": True,
"show_bases": True,
"show_submodules": True,
"group_by_category": False,
"heading_level": 2,
"members_order": "alphabetical",
"docstring_section_style": "list",
"members": None,
"inherited_members": True,
"filters": ["!^_"],
"annotations_path": "brief",
"preload_modules": None,
"load_external_modules": False,
"allow_inspection": True,
"summary": True,
"show_docstring_classes": True,
"show_docstring_functions": True,
"show_docstring_modules": True,
}
Default configuration values.
order_map module-attribute
¤
order_map = {
alphabetical.value: _sort_key_alphabetical,
source.value: _sort_key_source,
}
Order mapping for sorting objects.
ConfigDict ¤
Bases: TypedDict
Configuration for griffe2md, griffe and mkdocstrings.
Attributes:
-
allow_inspection
(bool
) –Allow using introspection on modules for which sources aren't available (compiled modules, etc.).
-
annotations_path
(Literal['brief', 'source', 'full']
) –The verbosity for annotations path:
brief
(recommended),source
(as written in the source), orfull
. -
docstring_options
(dict
) –mkdocstring configuration
-
docstring_section_style
(Literal['list', 'table']
) –The style used to render docstring sections.
-
docstring_style
(Literal['google', 'numpy', 'sphinx', 'auto'] | None
) –The style in which docstrings are written:
auto
,google
,numpy
,sphinx
, orNone
. -
filters
(list[str] | list[tuple[Pattern[str], bool]]
) –A list of filters.
-
group_by_category
(bool
) –Group the object's children by categories: attributes, classes, functions, and modules.
-
heading_level
(int
) –The initial heading level to use.
-
inherited_members
(bool | list[str]
) –A boolean, or an explicit list of inherited members to render.
-
line_length
(int
) –Maximum line length when formatting code/signatures.
-
load_external_modules
(bool
) –Whether to always load external modules/packages.
-
members
(list[str] | bool | None
) –A boolean, or an explicit list of members to render.
-
members_order
(Literal['alphabetical', 'source']
) –The members ordering to use.
-
merge_init_into_class
(bool
) –Whether to merge the
__init__
method into the class' signature and docstring. -
preload_modules
(list[str] | None
) –Pre-load modules that are not specified directly in autodoc instructions (
::: identifier
). -
separate_signature
(bool
) –Whether to put the whole signature in a code block below the heading.
-
show_bases
(bool
) –Show the base classes of a class.
-
show_category_heading
(bool
) –When grouped by categories, show a heading for each category.
-
show_docstring_attributes
(bool
) –Whether to display the 'Attributes' section in the object's docstring.
-
show_docstring_classes
(bool
) –Whether to display the 'Classes' section in the object's docstring.
-
show_docstring_description
(bool
) –Whether to display the textual block (including admonitions) in the object's docstring.
-
show_docstring_examples
(bool
) –Whether to display the 'Examples' section in the object's docstring.
-
show_docstring_functions
(bool
) –Whether to display the 'Functions' section in the object's docstring.
-
show_docstring_modules
(bool
) –Whether to display the 'Modules' section in the object's docstring.
-
show_docstring_other_parameters
(bool
) –Whether to display the 'Other Parameters' section in the object's docstring.
-
show_docstring_parameters
(bool
) –Whether to display the 'Parameters' section in the object's docstring.
-
show_docstring_raises
(bool
) –Whether to display the 'Raises' section in the object's docstring.
-
show_docstring_receives
(bool
) –Whether to display the 'Receives' section in the object's docstring.
-
show_docstring_returns
(bool
) –Whether to display the 'Returns' section in the object's docstring.
-
show_docstring_warns
(bool
) –Whether to display the 'Warns' section in the object's docstring.
-
show_docstring_yields
(bool
) –Whether to display the 'Yields' section in the object's docstring.
-
show_if_no_docstring
(bool
) –Show the object heading even if it has no docstring or children with docstrings.
-
show_object_full_path
(bool
) –Show the full Python path of every object.
-
show_root_full_path
(bool
) –Show the full Python path for the root object heading.
-
show_root_heading
(bool
) –Show the heading of the object at the root of the documentation tree.
-
show_root_members_full_path
(bool
) –Show the full Python path of the root members.
-
show_signature
(bool
) –Show methods and functions signatures.
-
show_signature_annotations
(bool
) –Show the type annotations in methods and functions signatures.
-
show_submodules
(bool
) –When rendering a module, show its submodules recursively.
-
signature_crossrefs
(bool
) –Whether to render cross-references for type annotations in signatures.
-
summary
(bool | dict
) –Whether to render summaries of modules, classes, functions (methods) and attributes.
allow_inspection instance-attribute
¤
allow_inspection: bool
Allow using introspection on modules for which sources aren't available (compiled modules, etc.).
annotations_path instance-attribute
¤
annotations_path: Literal['brief', 'source', 'full']
The verbosity for annotations path: brief
(recommended), source
(as written in the source), or full
.
docstring_section_style instance-attribute
¤
docstring_section_style: Literal['list', 'table']
The style used to render docstring sections.
docstring_style instance-attribute
¤
docstring_style: (
Literal["google", "numpy", "sphinx", "auto"] | None
)
The style in which docstrings are written: auto
, google
, numpy
, sphinx
, or None
.
filters instance-attribute
¤
A 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).
group_by_category instance-attribute
¤
group_by_category: bool
Group the object's children by categories: attributes, classes, functions, and modules.
inherited_members instance-attribute
¤
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 instance-attribute
¤
line_length: int
Maximum line length when formatting code/signatures.
load_external_modules instance-attribute
¤
load_external_modules: bool
Whether to always load external modules/packages.
members instance-attribute
¤
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 instance-attribute
¤
members_order: Literal['alphabetical', 'source']
The members ordering to use.
alphabetical
: order members alphabetically;source
: order members as they appear in the source file.
merge_init_into_class instance-attribute
¤
merge_init_into_class: bool
Whether to merge the __init__
method into the class' signature and docstring.
preload_modules instance-attribute
¤
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.
separate_signature instance-attribute
¤
separate_signature: bool
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_category_heading instance-attribute
¤
show_category_heading: bool
When grouped by categories, show a heading for each category.
show_docstring_attributes instance-attribute
¤
show_docstring_attributes: bool
Whether to display the 'Attributes' section in the object's docstring.
show_docstring_classes instance-attribute
¤
show_docstring_classes: bool
Whether to display the 'Classes' section in the object's docstring.
show_docstring_description instance-attribute
¤
show_docstring_description: bool
Whether to display the textual block (including admonitions) in the object's docstring.
show_docstring_examples instance-attribute
¤
show_docstring_examples: bool
Whether to display the 'Examples' section in the object's docstring.
show_docstring_functions instance-attribute
¤
show_docstring_functions: bool
Whether to display the 'Functions' section in the object's docstring.
show_docstring_modules instance-attribute
¤
show_docstring_modules: bool
Whether to display the 'Modules' section in the object's docstring.
show_docstring_other_parameters instance-attribute
¤
show_docstring_other_parameters: bool
Whether to display the 'Other Parameters' section in the object's docstring.
show_docstring_parameters instance-attribute
¤
show_docstring_parameters: bool
Whether to display the 'Parameters' section in the object's docstring.
show_docstring_raises instance-attribute
¤
show_docstring_raises: bool
Whether to display the 'Raises' section in the object's docstring.
show_docstring_receives instance-attribute
¤
show_docstring_receives: bool
Whether to display the 'Receives' section in the object's docstring.
show_docstring_returns instance-attribute
¤
show_docstring_returns: bool
Whether to display the 'Returns' section in the object's docstring.
show_docstring_warns instance-attribute
¤
show_docstring_warns: bool
Whether to display the 'Warns' section in the object's docstring.
show_docstring_yields instance-attribute
¤
show_docstring_yields: bool
Whether to display the 'Yields' section in the object's docstring.
show_if_no_docstring instance-attribute
¤
show_if_no_docstring: bool
Show the object heading even if it has no docstring or children with docstrings.
show_object_full_path instance-attribute
¤
show_object_full_path: bool
Show the full Python path of every object.
show_root_full_path instance-attribute
¤
show_root_full_path: bool
Show the full Python path for the root object heading.
show_root_heading instance-attribute
¤
show_root_heading: bool
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 instance-attribute
¤
show_root_members_full_path: bool
Show the full Python path of the root members.
show_signature_annotations instance-attribute
¤
show_signature_annotations: bool
Show the type annotations in methods and functions signatures.
show_submodules instance-attribute
¤
show_submodules: bool
When rendering a module, show its submodules recursively.
Order ¤
Enumeration for the possible members ordering.
Attributes:
-
alphabetical
–Alphabetical order.
-
source
–Source code order.
do_any ¤
Check if at least one of the item in the sequence evaluates to true.
The any
builtin as a filter for Jinja templates.
Parameters:
-
seq
(Sequence
) –An iterable object.
-
attribute
(str | None
, default:None
) –The attribute name to use on each object of the iterable.
Returns:
-
bool
–A boolean telling if any object of the iterable evaluated to True.
Source code in src/griffe2md/_internal/rendering.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
do_as_attributes_section ¤
do_as_attributes_section(
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:
-
DocstringSectionAttributes
–An attributes docstring section.
Source code in src/griffe2md/_internal/rendering.py
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 |
|
do_as_classes_section ¤
do_as_classes_section(
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:
-
DocstringSectionClasses
–A classes docstring section.
Source code in src/griffe2md/_internal/rendering.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
do_as_functions_section ¤
do_as_functions_section(
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:
-
DocstringSectionFunctions
–A functions docstring section.
Source code in src/griffe2md/_internal/rendering.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
do_as_modules_section ¤
do_as_modules_section(
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:
-
DocstringSectionModules
–A modules docstring section.
Source code in src/griffe2md/_internal/rendering.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
|
do_filter_objects ¤
do_filter_objects(
objects_dictionary: dict[str, Object | Alias],
*,
filters: Sequence[tuple[Pattern, bool]] | 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]] | None
, default:None
) –Filters to apply, based on members' names. 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:
-
list[Object | Alias]
–A list of objects.
Source code in src/griffe2md/_internal/rendering.py
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 |
|
do_format_attribute ¤
do_format_attribute(
context: Context,
attribute_path: Markup,
attribute: Attribute,
line_length: int,
*,
crossrefs: bool = False,
) -> str
Format an attribute using Black.
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 to give to Black.
-
crossrefs
(bool
, default:False
) –Whether to cross-reference types in the signature.
Returns:
-
str
–The same code, formatted.
Source code in src/griffe2md/_internal/rendering.py
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 |
|
do_format_code ¤
Format code using Black.
Parameters:
Returns:
-
str
–The same code, formatted.
Source code in src/griffe2md/_internal/rendering.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
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 using Black.
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 to give to Black.
-
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.
Source code in src/griffe2md/_internal/rendering.py
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 |
|
do_heading ¤
Render a Markdown heading.
Source code in src/griffe2md/_internal/rendering.py
266 267 268 |
|
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:
-
members
(Sequence[Object | Alias]
) –The members to order.
-
order
(Order
) –The ordering method.
-
members_list
(bool | list[str] | None
) –An optional member list (manual ordering).
Returns:
-
Sequence[Object | Alias]
–The same members, ordered.
Source code in src/griffe2md/_internal/rendering.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
do_split_path ¤
Split object paths for building cross-references.
Parameters:
-
path
(str
) –The path to split.
Returns:
Source code in src/griffe2md/_internal/rendering.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
from_private_package ¤
from_private_package(obj: Object | Alias) -> bool
Tell if an alias points to an object coming from a corresponding private package.
For example, return true for an alias in package ast
pointing at an object in package _ast
.
Parameters:
-
obj
(Object | Alias
) –The object (alias) to check.
Returns:
-
bool
–True or false.
Source code in src/griffe2md/_internal/rendering.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
get_parser ¤
get_parser() -> ArgumentParser
Return the CLI argument parser.
Returns:
-
ArgumentParser
–An argparse parser.
Source code in src/griffe2md/_internal/cli.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
load_config ¤
load_config() -> ConfigDict | None
Load the configuration if config file or config entry in pyproject.toml exists.
If neither config file was found or pyproject.toml file doesn't have a [tool.griffe2md]
section, None is returned.
Source code in src/griffe2md/_internal/config.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
prepare_context ¤
prepare_context(
obj: Object, config: ConfigDict | None = None
) -> dict
Prepare Jinja context.
Parameters:
-
obj
(Object
) –A Griffe object.
-
config
(ConfigDict | None
, default:None
) –The configuration options.
Returns:
-
dict
–The Jinja context.
Source code in src/griffe2md/_internal/main.py
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 |
|
prepare_env ¤
prepare_env(env: Environment | None = None) -> Environment
Prepare Jinja environment.
Parameters:
-
env
(Environment | None
, default:None
) –A Jinja environment.
Returns:
-
Environment
–The Jinja environment.
Source code in src/griffe2md/_internal/main.py
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 |
|
render_object_docs ¤
render_object_docs(
obj: Object, config: ConfigDict | None = None
) -> str
Render docs for a given object.
Parameters:
-
obj
(Object
) –The Griffe object to render docs for.
-
config
(ConfigDict | None
, default:None
) –The rendering configuration.
Returns:
-
str
–Markdown.
Source code in src/griffe2md/_internal/main.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
render_package_docs ¤
render_package_docs(
package: str, config: ConfigDict | None = None
) -> str
Render docs for a given package.
Parameters:
-
package
(str
) –The package (name) to render docs for.
-
config
(ConfigDict | None
, default:None
) –The rendering configuration.
Returns:
-
str
–Markdown.
Source code in src/griffe2md/_internal/main.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
write_package_docs ¤
write_package_docs(
package: str,
config: ConfigDict | None = None,
output: IO | str | None = None,
) -> None
Write docs for a given package to a file or stdout.
Parameters:
-
package
(str
) –The package to render docs for.
-
config
(ConfigDict | None
, default:None
) –The rendering configuration.
-
output
(IO | str | None
, default:None
) –The file to write to.
Source code in src/griffe2md/_internal/main.py
152 153 154 155 156 157 158 159 160 161 162 163 164 |
|