|
| 1 | +(sphinx-autodoc-api-style)= |
| 2 | + |
| 3 | +# sphinx-autodoc-api-style |
| 4 | + |
| 5 | +{bdg-warning-line}`Alpha` {bdg-link-secondary-line}`GitHub <https://github.com/git-pull/gp-sphinx/tree/main/packages/sphinx-autodoc-api-style>` {bdg-link-secondary-line}`PyPI <https://pypi.org/project/sphinx-autodoc-api-style/>` |
| 6 | + |
| 7 | +Sphinx extension that adds type and modifier badges to standard Python domain |
| 8 | +entries (functions, classes, methods, properties, attributes, data, |
| 9 | +exceptions). Mirrors the badge system from |
| 10 | +{doc}`sphinx-autodoc-pytest-fixtures` so API pages and fixture pages share a |
| 11 | +consistent visual language. |
| 12 | + |
| 13 | +```console |
| 14 | +$ pip install sphinx-autodoc-api-style |
| 15 | +``` |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +- **Type badges** (rightmost): `function`, `class`, `method`, `property`, |
| 20 | + `attribute`, `data`, `exception` — each with a distinct color |
| 21 | +- **Modifier badges** (left of type): `async`, `classmethod`, `staticmethod`, |
| 22 | + `abstract`, `final`, `deprecated` |
| 23 | +- **Card containers**: bordered cards with secondary-background headers |
| 24 | +- **Dark mode**: full light/dark theming via CSS custom properties |
| 25 | +- **Accessibility**: keyboard-focusable badges with tooltip popups |
| 26 | +- **Non-invasive**: hooks into `doctree-resolved` without replacing directives |
| 27 | + |
| 28 | +## How it works |
| 29 | + |
| 30 | +Add `sphinx_autodoc_api_style` to your Sphinx extensions. With `gp-sphinx`, |
| 31 | +use `extra_extensions`: |
| 32 | + |
| 33 | +```python |
| 34 | +conf = merge_sphinx_config( |
| 35 | + project="my-project", |
| 36 | + version="1.0.0", |
| 37 | + copyright="2026, Your Name", |
| 38 | + source_repository="https://github.com/your-org/my-project/", |
| 39 | + extra_extensions=["sphinx_autodoc_api_style"], |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +Or without `merge_sphinx_config`: |
| 44 | + |
| 45 | +```python |
| 46 | +extensions = ["sphinx_autodoc_api_style"] |
| 47 | +``` |
| 48 | + |
| 49 | +No special directives are needed — existing `.. autofunction::`, |
| 50 | +`.. autoclass::`, `.. automodule::` directives automatically receive badges. |
| 51 | + |
| 52 | +## Live demo |
| 53 | + |
| 54 | +```{py:module} gas_demo_api |
| 55 | +``` |
| 56 | + |
| 57 | +### Functions |
| 58 | + |
| 59 | +```{eval-rst} |
| 60 | +.. autofunction:: gas_demo_api.demo_function |
| 61 | +``` |
| 62 | + |
| 63 | +```{eval-rst} |
| 64 | +.. autofunction:: gas_demo_api.demo_async_function |
| 65 | +``` |
| 66 | + |
| 67 | +```{eval-rst} |
| 68 | +.. autofunction:: gas_demo_api.demo_deprecated_function |
| 69 | +``` |
| 70 | + |
| 71 | +### Module data |
| 72 | + |
| 73 | +```{eval-rst} |
| 74 | +.. autodata:: gas_demo_api.DEMO_CONSTANT |
| 75 | +``` |
| 76 | + |
| 77 | +### Exceptions |
| 78 | + |
| 79 | +```{eval-rst} |
| 80 | +.. autoexception:: gas_demo_api.DemoError |
| 81 | +``` |
| 82 | + |
| 83 | +### Classes |
| 84 | + |
| 85 | +```{eval-rst} |
| 86 | +.. autoclass:: gas_demo_api.DemoClass |
| 87 | + :members: |
| 88 | + :undoc-members: |
| 89 | +``` |
| 90 | + |
| 91 | +### Abstract base classes |
| 92 | + |
| 93 | +```{eval-rst} |
| 94 | +.. autoclass:: gas_demo_api.DemoAbstractBase |
| 95 | + :members: |
| 96 | +``` |
| 97 | + |
| 98 | +## Badge reference |
| 99 | + |
| 100 | +### Type badges |
| 101 | + |
| 102 | +| Object type | CSS class | Color | |
| 103 | +|-------------|-----------|-------| |
| 104 | +| `function` | `gas-type-function` | Blue | |
| 105 | +| `class` | `gas-type-class` | Indigo | |
| 106 | +| `method` | `gas-type-method` | Cyan | |
| 107 | +| `property` | `gas-type-property` | Teal | |
| 108 | +| `attribute` | `gas-type-attribute` | Slate | |
| 109 | +| `data` | `gas-type-data` | Grey | |
| 110 | +| `exception` | `gas-type-exception` | Rose | |
| 111 | + |
| 112 | +### Modifier badges |
| 113 | + |
| 114 | +| Modifier | CSS class | Style | |
| 115 | +|----------|-----------|-------| |
| 116 | +| `async` | `gas-mod-async` | Purple outlined | |
| 117 | +| `classmethod` | `gas-mod-classmethod` | Amber outlined | |
| 118 | +| `staticmethod` | `gas-mod-staticmethod` | Grey outlined | |
| 119 | +| `abstract` | `gas-mod-abstract` | Indigo outlined | |
| 120 | +| `final` | `gas-mod-final` | Emerald outlined | |
| 121 | +| `deprecated` | `gas-deprecated` | Red/grey outlined | |
| 122 | + |
| 123 | +## CSS prefix |
| 124 | + |
| 125 | +All CSS classes use the `gas-` prefix (**g**p-sphinx **a**pi **s**tyle) to avoid |
| 126 | +collision with `spf-` (sphinx pytest fixtures) or other extensions. |
| 127 | + |
| 128 | +```{package-reference} sphinx-autodoc-api-style |
| 129 | +``` |
| 130 | + |
| 131 | +[Source on GitHub](https://github.com/git-pull/gp-sphinx/tree/main/packages/sphinx-autodoc-api-style) · [PyPI](https://pypi.org/project/sphinx-autodoc-api-style/) |
0 commit comments