Skip to main content

Golem Documentation

Michael Bernstein

API Reference Generator & Inline Macro

Golem includes a built-in API reference documentation generator plugin (golem.plugins.apidoc) that inspects Python source modules, extracts type annotations and docstrings, and renders standard AsciiDoc API documentation.

1. Generating API Reference Pages (golem apidoc)

You can generate comprehensive API reference pages for your Python packages either automatically during build or via the CLI:

Terminal
BASH
golem apidoc [PACKAGE] [--output <dir>] [--docstring-style <style>]

Configuration via golem.toml or pyproject.toml

Configure API generation settings in your project configuration:

golem.toml
TOML
[api]
packages = ["my_package", "my_package.core"]
output_dir = "api"
docstring_style = "auto" # Options: "auto", "google", "numpy", "sphinx", "asciidoc"

During builds or CI/CD pipelines, Golem reads this configuration and generates hierarchical reference pages under content_dir/api/ matching your package structure.

2. Block Macro: golem.apidoc::

In technical manuals, guides, or tutorials, you often want to splice live API documentation for a specific class or function directly into your narrative prose.

Golem provides the golem.apidoc:: block macro:

engine_guide.adoc
ASCIIDOC
= Engine Architecture Guide

Here is the specification for the primary BuildEngine class:

golem.apidoc::golem.engine.BuildEngine[depth=all]

Macro Parameters

Parameter

Default

Description

target

(Required)

Full Python import path of the target module, class, method, or function (e.g. "golem.config.GolemConfig"), specified as the macro target after ::.

depth

"all"

Introspection depth: "all" (full class with all methods and attributes), "methods" (methods only), "summary" (class signature and overview docstring).

style

"auto"

Docstring parsing format ("auto", "google", "numpy", "sphinx", "asciidoc").

heading_level_offset

0

Integer offset applied to all headings in the generated API documentation. Useful when the macro appears inside a section (e.g. heading_level_offset=1 ensures generated == Headings become === Headings to match the embedding depth).

Macro Processing — AST-Level ASG Splice

When Golem processes documents containing golem.apidoc:: block macros, macro expansion runs via the on_asg_created plugin hook using an AST NodeTransformer:

  1. AsciiDoctrine parses golem.apidoc::target[attrs] into a BlockNode with name == "golem.apidoc".
  2. The on_asg_created hook receives the typed Node document tree.
  3. ApidocMacroTransformer(AsgTransformer) traverses the AST.
  4. For each block macro node matching name == "golem.apidoc":
    1. AsciiDocApi.get_asg_nodes() resolves the Python target on sys.path, renders it to AsciiDoc markup, and resolves it into a list of typed AST Node objects.
  5. The transformer replaces the macro node with the returned node list.
  6. Verbatim blocks (listing, literal, verse) and backtick-escaped inline code are protected from macro expansion.
  7. Backslash-escaped macros (golem.apidoc::[...]) are unescaped to literal text without triggering expansion.
  8. If the target cannot be resolved, a [WARNING] admonition block is inserted with diagnostic details so the failure is visible in rendered output.