Skip to main content

Quarto Documentation for Python Packages

Small Python script to convert Python Google-Style docstrings to quarto files to be used to render a Python package documentation using a quarto website. This script started as the author was not happy with existing software to document Python packages, namely sphinx altough having a variety of features.

As sphinx has been used previously, this parser partially relies on the sphinx syntax for cross-referencing classes, functions, and methods.

Under the hood

Uses the Python standard libraries importlib to import all visible classes and functions of an existing package and inspect to inspect these objects. The Python package docstring_parser is used to parse Google style docstrings which are then converted into quarto .qmd files.

Usage

In the simplest case:

python3 makedocs.py <action> -p <package>

... where <action> can be init or document. init will initialize a new project and stores all necessary files in a directory _quarto. If initialized once, an error will be thrown if executed again to avoid overwriting changes made by the user. The argument --overwrite can be used to force-overwrite the existing quarto files as well as _quarto.yml. document will only update the man pages created from the Python docstrings as well as update the 'Function references' and 'Class references' section in the _quarto.yml file.

Additional options are available to change a few things. For more details see:

python3 makedocs.py --help

Cross referencing

Based on the syntax of sphinx, cross-referencing in the docstrings is done via :py:class:, :py:func: and :py:meth: followed by the name/path of the class, function, or method.

  • :py:class:\package.module.class`` references a class
  • :py:class:\class <package.module.class>`references a class but will only displayclass` (custom text) in the rendered quarto document.
  • :py:class\class`` expects the class to be in the same module as the class it is references from.

Similarely functions can be cross-referenced with the same system:

  • :py:func:\package.module.function`` references a func
  • :py:func:\function <package.module.function>`references a func but will only displayfunction` (custom text) in the rendered quarto document.
  • :py:func\function`` expects the func to be in the same module as the func it is references from.

Last but not least, sibling methods can be referenced within a class using:

  • :py:meth:\method``

The script does not validate if these references are valid, but will link to them in the quarto documents. quarto render will throw warnings if links cannot be resolved.

Examples

One additional feature is a special comment in the Example section of each Google style docstring. Whenver a line (code line) starts with #:, the example will be split at this point, resulting in multiple quarto code chunks allowing for 'in-line' (in-between chunks) output in the exercises. A line solely containing #: also initiales a new code chunk but will not be shown (hidden chunk splitter). As an example, this could look as follows in the docstring:

    Example:

    >>> # Basic addition
    >>> a = 10 + 3
    >>> a
    >>> #: Basic subtraction
    >>> 20 - 4
    >>> #:
    >>> 20 - 5

Metadata

Release files for pyp2qmd 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyp2qmd 0.1.2
File Size Uploaded
pyp2qmd-0.1.2.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyp2qmd 0.1.2
File Interpreter ABI Platform
pyp2qmd-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 56.9 kB

Release files / pyp2qmd-0.1.2.tar.gz

Download URL pyp2qmd-0.1.2.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c74ccb132549a9bbad6f95e51ee40d8639f2378e8f5fbc1b43e017a282e9d219
BLAKE2b-256 checksum
How to use checksums
c035e7fa409dbaced84a7e6d52cae28ec358b4d7a4d38bc426d30b0223201549
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / pyp2qmd-0.1.2-py3-none-any.whl

Download URL pyp2qmd-0.1.2-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
256929a03d038c684845b486eb2db32935db6f3e5168f12496deb0542291ded1
BLAKE2b-256 checksum
How to use checksums
8a1fa88f8a852f3515a52e13c4b251555110bfd805fbc92ba1435be8d7aaaa70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page