Skip to main content

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


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.4.2.tar.gz (150.5 kB view details)

Uploaded Source

Built Distribution

quartodoc-0.4.2-py2.py3-none-any.whl (58.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file quartodoc-0.4.2.tar.gz.

File metadata

  • Download URL: quartodoc-0.4.2.tar.gz
  • Upload date:
  • Size: 150.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for quartodoc-0.4.2.tar.gz
Algorithm Hash digest
SHA256 045e1c996f1d8a5586edc199a7d13407f6e1559789fd7813c2bc1d10e6b5f19b
MD5 efbd506bf6612134ba4d5c65af416afa
BLAKE2b-256 0d0d752fca0c1ba0b87d5adf8c60a1add7a67cd66c905e8e52a1bbf66eef3804

See more details on using hashes here.

File details

Details for the file quartodoc-0.4.2-py2.py3-none-any.whl.

File metadata

  • Download URL: quartodoc-0.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 58.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for quartodoc-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3642367e6f3f9fa8d954eb248ec7720fff5d074b64037cdf39ae1eb9ab3a848a
MD5 9d894d2ab8da2d3a879fe751fa8e4312
BLAKE2b-256 4f80146af964bf2cc48a33af9e8255733b3f44443b513e65ae9c66921dfc0e0d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page