Preview a Sphinx inventory file via CLI
mainYou can preview the contents of a Sphinx inventory file using the sphinx.ext.intersphinx module from the command line.
python -m sphinx.ext.intersphinx <file_name>repository·main·Indexed 42 days ago
https://github.com/machow/quartodocA tool for generating Python package API reference documentation using Markdown and Quarto. It serves as a modern alternative to Sphinx, providing a Builder engine to automate the creation of .qmd files, index pages, and Sphinx-compatible inventory files for cross-referencing.
You can preview the contents of a Sphinx inventory file using the sphinx.ext.intersphinx module from the command line.
python -m sphinx.ext.intersphinx <file_name>make build command.make buildYou can install quartodoc via pip or directly from the GitHub repository.
Important: You must have Quarto installed on your system before using quartodoc to generate documentation.
python -m pip install quartodocpython -m pip install git+https://github.com/machow/quartodoc.gitThe Builder class uses a registry system to support different documentation layouts via the style parameter. Currently supported styles include:
pkgdown: Builds an API in the style of the R pkgdown package (multiple pages).single-page: Embeds all API documentation onto a single large page.Quartodoc allows you to create cross-reference links to Python objects (functions, classes, modules, etc.) using a specific syntax. This enables users to click a name in the documentation and be taken to the corresponding reference section.
[](:function:name)[](full.path.to.Object)[](:function:`print`)
[](`dascore.clients.dirspool.DirectorySpool`)To programmatically access a Sphinx inventory file (typically objects.inv), use sphinx.util.inventory.InventoryFile.load. This allows you to look up object locations, versions, and URLs within the inventory.
Once loaded, the InventoryFile object behaves like a dictionary where keys are domain/type identifiers (e.g., py:function) and values are mappings of object names to their metadata tuples.
from sphinx.util.inventory import InventoryFile
from os import path
SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/"
SQLALCHEMY_INV_URL = f"{SQLALCHEMY_DOCS_URL}/objects.inv"
# Load the inventory file
with open("objects_sqla.inv", "rb") as f:
inv = InventoryFile.load(f, SQLALCHEMY_DOCS_URL, path.join)
# List available domains/types
print(list(inv))
# Access specific object metadata
# Returns: (Project Name, Version, URL, Status)
print(inv["py:function"]["sqlalchemy.create_engine"])The Interlaced element is used to group a collection of objects where their documentation (signatures, examples, etc.) is interleaved rather than listed as complete blocks for each object. This is useful for presenting related items together.
Attributes:
kind: Fixed to "interlaced".package (Union[str, None, MISSING]): If specified, object lookups are relative to this path.contents (list[Union[Auto, Doc, _AutoDefault]]): The list of objects to interlace. Note that Interlaced cannot contain Page or Section elements.Use get_object() to retrieve a Griffe object representing a Python entity (module, class, function, etc.) using an import path. The path should follow the format module:object (e.g., quartodoc:MdRenderer.render).
Key parameters:
path: The import path.parser: The docstring parser to use ("google", "sphinx", or "numpy"). Defaults to "numpy".load_aliases: If True, it will attempt to load modules for aliases imported from other modules.dynamic: If True, it uses dynamic import to find the target. This is useful if docstrings are set at runtime rather than being hard-coded in the source.Note: The object_name parameter is deprecated.
from quartodoc.autosummary import get_object
# Fetch a specific method
obj = get_object("quartodoc:get_object")
# Fetch a module
mod = get_object("quartodoc")Call build() on a Builder instance to execute the documentation generation pipeline. The pipeline performs the following steps:
.qmd files for each documented object.You can pass a filter string (supporting * wildcards) to build() to only write documentation for objects matching a specific pattern (e.g., build(filter="MyClass*")).
builder = Builder(package="my_pkg", sections=sections)
# Build everything
builder.build()
# Build only objects matching a pattern
builder.build(filter="utils.*")The Inventories class acts as a registry for EnhancedItem objects (the items found within inventory files). It allows you to perform lookups to resolve a Ref into a specific URI.
Key methods:
from_items(items): Create an Inventories instance from a list of EnhancedItem objects.lookup_reference(ref): Resolves a Ref object to its corresponding EnhancedItem. Raises InvLookupError if the reference is not found or is ambiguous.ref_to_anchor(ref, text): Converts a reference string or Ref object into a Link object containing the resolved URL and display text.from quartodoc.interlinks import Inventories, EnhancedItem, Ref
# Setup items
item = EnhancedItem.make_simple('my_inv', 'https://example.com/api', 'my_func')
invs = Inventories.from_items([item])
# Resolve a reference
link = invs.ref_to_anchor("my_func")
print(link.url) # https://example.com/api/my_func.htmlA specialized version of get_object specifically for retrieving functions within a module.
from quartodoc.autosummary import get_function
# Fetch the function 'get_function' from the 'quartodoc' module
func = get_function("quartodoc", "get_function")If you are working with Pandoc-style representations (where backticks might be encoded as %60), use pandoc_ref_to_anchor.
Unlike ref_to_anchor, this method:
%60 as a backtick.warnings.warn instead of raising exceptions if a lookup fails.Unchanged object if the string doesn't look like a reference, or a Code object if the lookup fails, ensuring the document structure remains intact.from quartodoc.interlinks import Inventories
# Assuming invs is an initialized Inventories instance
# This will return a Link, Code, or Unchanged object
element = invs.pandoc_ref_to_anchor("%60my_func%60", "my_func")