Generate API documentation with Quarto.
Project description
quartodoc
Generate python API documentation for quarto.
Install
pip install quartodoc
Or for the latest changes:
python3 -m pip install -e git+https://github.com/machow/quartodoc.git#egg=quartodoc
Basic use
from quartodoc import get_function, MdRenderer
# get function object ---
f_obj = get_function("quartodoc", "get_function")
# render ---
renderer = MdRenderer(header_level = 1)
print(
renderer.to_md(f_obj)
)
# get_function
`get_function(module: str, func_name: str, parser: str = 'numpy')`
Fetch a function.
## Parameters
| Name | Type | Description | Default |
|-------------|--------|----------------------------|-----------|
| `module` | str | A module name. | required |
| `func_name` | str | A function name. | required |
| `parser` | str | A docstring parser to use. | `'numpy'` |
## Examples
```python
>>> get_function("quartodoc", "get_function")
<Function('get_function', ...
```
How it works
quartodoc consists of two pieces:
- collection: using the library griffe to statically collect information about functions and classes in a program.
- docstring parsing: also handled by griffe, which breaks it into a tree structure.
- docstring rendering: use plum-dispatch on methods like MdRenderer.to_md to decide how to visit and render each piece of the tree (e.g. the examples section, a parameter, etc..).
Here is a quick example of how you can grab a function from griffe and walk through it.
from griffe.loader import GriffeLoader
from griffe.docstrings.parsers import Parser
griffe = GriffeLoader(docstring_parser = Parser("numpy"))
mod = griffe.load_module("quartodoc")
f_obj = mod._modules_collection["quartodoc.get_function"]
f_obj.name
'get_function'
docstring = f_obj.docstring.parsed
docstring
[<griffe.docstrings.dataclasses.DocstringSectionText at 0x105a2c310>,
<griffe.docstrings.dataclasses.DocstringSectionParameters at 0x10f7961f0>,
<griffe.docstrings.dataclasses.DocstringSectionExamples at 0x10f7965b0>]
Note that quartodoc’s MdRenderer can be called on any part of the parsed docstring.
from quartodoc import MdRenderer
renderer = MdRenderer()
print(
renderer.to_md(docstring[1])
)
| Name | Type | Description | Default |
|-------------|--------|----------------------------|-----------|
| `module` | str | A module name. | required |
| `func_name` | str | A function name. | required |
| `parser` | str | A docstring parser to use. | `'numpy'` |
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
quartodoc-0.5.0.tar.gz
(748.9 kB
view details)
Built Distribution
quartodoc-0.5.0-py3-none-any.whl
(61.7 kB
view details)
File details
Details for the file quartodoc-0.5.0.tar.gz
.
File metadata
- Download URL: quartodoc-0.5.0.tar.gz
- Upload date:
- Size: 748.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c4645ad5428702fa5eae3d9501c6aa5c7ce691c48936fb0ea3076422537709 |
|
MD5 | c5418ca050278d269e1762fd633c59a0 |
|
BLAKE2b-256 | c0ecb7381b181ad97f2414da049b13823b7e39bfe6ac6318871a5f69dcfefb4b |
File details
Details for the file quartodoc-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: quartodoc-0.5.0-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53791d7f4fb7e366ac17f4120fc6fa72292608eba931ced65d9a3e73c854d40b |
|
MD5 | 00ea4846a34d7c2fb18c73660b990d67 |
|
BLAKE2b-256 | 54c34d301bf8191e0eb447af01056893026cc53e8186b68d26829bb3289caa99 |