sphinx-ux-autodoc-layout¶
Alpha
Rendered output is stable. The Python API, CSS class names, and Sphinx config value names may change without a major version bump. Pin your dependency to a specific version range in production.
Wraps contiguous desc_content runs into semantic api_region nodes
and rebuilds Python autodoc entries into stable api-* components.
Large field-list parameter sections still use native <details>/<summary>,
while inline signature expansion uses a custom disclosure that reveals
Sphinx’s native multiline parameter-list rendering.
It is now the shared presenter for the whole autodoc family. desc-backed
entries use it directly, and section-card consumers reuse the same inner shell
through the public build_api_card_entry() helper.
$ pip install sphinx-ux-autodoc-layout
Pipeline position¶
Hooks doctree-resolved at priority 600, after sphinx-autodoc-api-style
at 500. Consumes the api_slot nodes that producer packages inject into
desc_signature during earlier transforms, and composes them into the final
gp-sphinx-api-layout-right subcomponent (badges, source link, permalink).
The extension also overrides Sphinx’s built-in desc_signature HTML visitor
(app.add_node(addnodes.desc_signature, override=True, ...)). This is a
deliberate platform decision: taking ownership of signature rendering allows
the gp-sphinx-api-link permalink to be placed inside the managed layout rather than
appended by Sphinx’s default handler.
Event |
Hook |
Priority |
|---|---|---|
|
|
600 (after api-style at 500) |
|
— |
not used |
Downstream conf.py¶
With gp-sphinx:
conf = merge_sphinx_config(
project="my-project",
version="1.0.0",
copyright="2026, Your Name",
source_repository="https://github.com/your-org/my-project/",
extra_extensions=["sphinx_ux_autodoc_layout"],
api_layout_enabled=True,
api_collapsed_threshold=10,
)
Or without merge_sphinx_config:
extensions = ["sphinx.ext.autodoc", "sphinx_ux_autodoc_layout"]
api_layout_enabled = True
Working usage examples¶
Render one compact function:
```{eval-rst}
.. autofunction:: my_project.api.compact_function
```
Render a class with grouped content regions and member entries:
```{eval-rst}
.. autoclass:: my_project.api.LayoutDemo
:members:
```
Live demos¶
Class with members (regions + fold)¶
-
class api_demo_layout.LayoutDemo¶
Bases:
objectA class demonstrating all layout regions.
The class docstring forms the narrative region. The parameter field list below forms the fields region (folded if large enough). Nested methods form the members region.
Parameters (13)
- Parameters:
host (str) – Server hostname.
port (int) – Server port number.
username (str) – Authentication username.
password (str) – Authentication password.
database (str) – Database name.
timeout (float) – Connection timeout in seconds.
retries (int) – Number of connection retries.
ssl (bool) – Enable SSL/TLS.
pool_size (int) – Connection pool size.
pool_timeout (float) – Pool checkout timeout.
echo (bool) – Log all SQL statements.
encoding (str) – Character encoding.
isolation_level (str) – Transaction isolation level.
The class above renders with:
narrative region (class docstring)
fields region with fold (13 parameters > threshold of 10)
members region (connect, execute, close methods)
Small function (no fold)¶
-
api_demo_layout.compact_function(name, value=0)¶
Format a name-value pair.
This should render without any fold – just a narrative region followed by a fields region.
Configuration¶
Setting |
Default |
Meaning |
|---|---|---|
|
|
Enables the transform |
|
|
Folds large field-list sections |
|
|
Minimum field count before folding |
|
|
Shows |
CSS classes¶
Class |
Element |
Purpose |
|---|---|---|
|
|
Managed autodoc shell |
|
|
Signature row shell |
|
|
Description/content shell |
|
|
Header split between left and right |
|
|
Signature text, custom disclosure, permalink |
|
|
Badge container and source link |
|
|
Compact signature row |
|
|
Managed permalink in the left layout |
|
|
Wrapper for badge group output |
|
|
Wrapper for the |
|
|
Wraps paragraphs, notes, examples |
|
|
Wraps field lists (Parameters, Returns) |
|
|
Wraps nested method/attribute entries |
|
|
Compatibility alias on content sections |
|
|
Compatibility alias on narrative sections |
|
|
Compatibility alias on parameter sections |
|
|
Compatibility alias on footer/member sections |
|
|
Disclosure wrapper for large sections |
|
|
Click target showing field count |
API reference¶
-
sphinx_ux_autodoc_layout.build_api_card_entry(*, profile_class, signature_children, content_children=(), badge_group=None, permalink=None, entry_classes=(), signature_classes=(), content_classes=())¶
Build a shared
gp-sphinx-api-*card entry for non-descconsumers.Parameters (10)
- Parameters:
profile_class (str) – Stable profile class such as
"gp-sphinx-api-profile--fastmcp-tool".signature_children (Sequence[nodes.Node]) – Children placed inside the
gp-sphinx-api-signaturewrapper.content_children (Sequence[nodes.Node]) – Children appended to
gp-sphinx-api-content.badge_group (nodes.Node | None) – Shared badge group rendered inside
gp-sphinx-api-badge-container.permalink (api_permalink | None) – Explicit header permalink placed in
gp-sphinx-api-layout-left.entry_classes (tuple[str, ...]) – Extra CSS classes for the outer
gp-sphinx-api-entrywrapper.signature_classes (tuple[str, ...]) – Extra classes for the
gp-sphinx-api-signaturewrapper.content_classes (tuple[str, ...]) – Extra classes for the
gp-sphinx-api-contentwrapper.
- Returns:
Shared card entry tree using the stable
gp-sphinx-api-*contract.- Return type:
nodes.Element
-
sphinx_ux_autodoc_layout.build_api_summary_section(*children, classes=())¶
Wrap summary or index content in the shared
gp-sphinx-api-summaryregion.Examples
>>> from docutils import nodes >>> section = build_api_summary_section(nodes.paragraph("", "Summary")) >>> section.get("name") 'gp-sphinx-api-summary'
-
sphinx_ux_autodoc_layout.build_api_table_section(name, *children, classes=())¶
Wrap one or more table-like body nodes in a shared API section.
-
sphinx_ux_autodoc_layout.build_api_facts_section(rows, *, classes=())¶
Render a shared
gp-sphinx-api-factssection from typed fact rows.
Copyable config snippet
extensions = [
"sphinx_ux_autodoc_layout",
]
Registered Surface
sphinx_ux_autodoc_layout
Config values
Name |
Default |
Rebuild |
Types |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|