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:
golem apidoc [PACKAGE] [--output <dir>] [--docstring-style <style>]
Configuration via golem.toml or pyproject.toml
Configure API generation settings in your project configuration:
[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 Architecture Guide
Here is the specification for the primary BuildEngine class:
golem.apidoc::golem.engine.BuildEngine[depth=all]
Macro Parameters
Parameter | Default | Description |
| (Required) | Full Python import path of the target module, class, method, or function (e.g. |
|
| Introspection depth: |
|
| Docstring parsing format ( |
|
| Integer offset applied to all headings in the generated API documentation. Useful when the macro appears inside a section (e.g. |
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:
- AsciiDoctrine parses
golem.apidoc::target[attrs]into aBlockNodewithname == "golem.apidoc". - The
on_asg_createdhook receives the typedNodedocument tree. ApidocMacroTransformer(AsgTransformer)traverses the AST.- For each block macro node matching
name == "golem.apidoc":AsciiDocApi.get_asg_nodes()resolves the Python target onsys.path, renders it to AsciiDoc markup, and resolves it into a list of typed ASTNodeobjects.
- The transformer replaces the macro node with the returned node list.
- Verbatim blocks (
listing,literal,verse) and backtick-escaped inline code are protected from macro expansion. - Backslash-escaped macros (
golem.apidoc::[...]) are unescaped to literal text without triggering expansion. - If the target cannot be resolved, a
[WARNING]admonition block is inserted with diagnostic details so the failure is visible in rendered output.