API Reference¶
Colour palette¶
All semantic badge colours live in sab_palettes.css (registered by
this extension). Every sphinx-autodoc-* package uses the SAB.*
constants instead of its own colour classes. The live demo below shows
every variant.
Colour class |
|
Used for |
|---|---|---|
|
|
Python functions (blue) |
|
|
Python classes (indigo) |
|
|
Instance / class / static methods (cyan) |
|
|
Properties (teal) |
|
|
Attributes (slate) |
|
|
Module-level data (grey) |
|
|
Exceptions (rose/red) |
|
|
Type aliases (violet) |
|
|
Modules (green) |
|
|
async modifier (purple outline) |
|
|
classmethod modifier (amber outline) |
|
|
staticmethod modifier (grey outline) |
|
|
abstract modifier (indigo outline) |
|
|
final modifier (emerald outline) |
|
|
deprecated (muted red, shared across domains) |
|
|
pytest fixtures (green) |
|
|
session-scope fixtures (amber) |
|
|
module-scope fixtures (teal) |
|
|
class-scope fixtures (slate) |
|
|
factory fixtures (amber outline) |
|
|
override hooks (violet outline) |
|
|
autouse fixtures (rose outline) |
|
|
Sphinx config values (amber) |
|
|
Sphinx rebuild mode (grey outline) |
|
|
docutils directives (violet) |
|
|
docutils roles (violet) |
|
|
docutils directive options (violet) |
API reference¶
-
class sphinx_ux_badges.BadgeSpec¶class sphinx_ux_badges.BadgeSpec¶
Bases:
objectTyped badge descriptor used by producer extensions.
- Parameters:
text (
str) – Visible badge label.tooltip (
str) – Tooltip and aria label for the badge.icon (
str) – Optional icon rendered via::before.classes (
tuple[str, ...]) – Additional CSS classes for package-specific color and role styling.style (
{"full","icon-only","inline-icon"}) – Structural variant.fill (
{"filled","outline"}) – Visual fill variant.size (
str) – Optional size token:"xxs","xs","sm","md","lg", or"xl".tabindex (
str) – Focus behavior token forwarded toBadgeNode.
Examples
>>> spec = BadgeSpec("config", tooltip="Sphinx config value") >>> spec.text 'config'
-
sphinx_ux_badges.build_badge(text, *, tooltip='', icon='', classes=(), style='full', fill='filled', size='', tabindex='0')¶sphinx_ux_badges.build_badge(text, *, tooltip='', icon='', classes=(), style='full', fill='filled', size='', tabindex='0')¶
Build a single badge node.
- Parameters:
text (
str) – Visible label. Empty string for icon-only badges.tooltip (
str) – Hover text andaria-label.icon (
str) – Emoji character for CSS::before.classes (
Sequence[str]) – Additional CSS classes (plugin prefix + color class).style (
{“full”, “icon-only”, “inline-icon”}) – Structural variant.fill (
{“filled”, “outline”}) – Visual fill variant.size (
str) – Optional size tier:"xxs","xs","sm","md","lg", or"xl". Empty string uses the default (no extra class).tabindex (
str) –"0"for focusable,""to skip.
- Return type:
Examples
>>> b = build_badge("async", tooltip="Asynchronous", classes=[SAB.MOD_ASYNC]) >>> b.astext() 'async'
>>> b = build_badge( ... "", ... style="icon-only", ... classes=["gp-sphinx-fastmcp__safety-readonly"], ... ) >>> SAB.ICON_ONLY in b["classes"] True
>>> b = build_badge("big", size="lg") >>> SAB.LG in b["classes"] True
-
sphinx_ux_badges.build_badge_group(badges, *, classes=())¶sphinx_ux_badges.build_badge_group(badges, *, classes=())¶
Wrap badges in a group container with inter-badge spacing.
Examples
>>> from sphinx_ux_badges._nodes import BadgeNode >>> g = build_badge_group([BadgeNode("a"), BadgeNode("b")]) >>> SAB.BADGE_GROUP in g["classes"] True
-
sphinx_ux_badges.build_toolbar(badge_group, *, classes=())¶sphinx_ux_badges.build_toolbar(badge_group, *, classes=())¶
Wrap a badge group in a toolbar (
margin-left: autofor flex titles).- Parameters:
badge_group (
nodes.inline) – Badge group frombuild_badge_group().classes (
Sequence[str]) – Additional CSS classes on the toolbar.
- Return type:
nodes.inline
Examples
>>> from sphinx_ux_badges._nodes import BadgeNode >>> g = build_badge_group([BadgeNode("x")]) >>> t = build_toolbar(g, classes=["gp-sphinx-fastmcp__toolbar"]) >>> SAB.TOOLBAR in t["classes"] True
-
class sphinx_ux_badges.BadgeNode¶class sphinx_ux_badges.BadgeNode¶
Bases:
inlineInline badge rendered as
<span>with ARIA and icon support.Subclasses
nodes.inlineso unregistered builders (text, LaTeX, man) fall back tovisit_inlinevia MRO dispatch inSphinxTranslator.dispatch_visit.Examples
>>> b = BadgeNode("hello", badge_tooltip="greeting") >>> b["badge_tooltip"] 'greeting'
>>> b.astext() 'hello'
Constructor parameters
Parameter
Default
Description
text""Visible label. Empty string for icon-only badges.
badge_tooltip""Hover text and
aria-label.badge_icon""Emoji character rendered via CSS
::before.badge_style"full"Structural variant:
"full","icon-only","inline-icon".badge_size""Optional size:
"xxs","xs","sm","md","lg", or"xl". Empty means default.tabindex"0""0"for keyboard-focusable,""to skip.classesNoneAdditional CSS classes (plugin prefix + color class).
-
class sphinx_ux_badges._css.SAB¶class sphinx_ux_badges._css.SAB¶
Bases:
objectCSS class constants under the
gp-sphinx-namespace.The
gp-sphinx-prefix identifies these classes as part of the gp-sphinx workspace. The badge block (gp-sphinx-badge) and its sibling blocks (gp-sphinx-badge-group,gp-sphinx-toolbar) are tier-A shared concepts — any extension may consume them directly, and the theme may restyle them once for every consumer.Covers both structural variants (size, outline, icon-only) and the unified semantic colour palette from
sab_palettes.css(filename is historical).All consuming
sphinx-autodoc-*packages use these constants for shared badge primitives (group, badge, toolbar, type, modifier, state classes). Extension-specific layout and semantic classes live under each package’s own namespace (e.g.gp-sphinx-fastmcp__*for FastMCP tool sections,gp-sphinx-pytest-fixtures__*for fixture-index layout).Examples
>>> SAB.PREFIX 'gp-sphinx-badge'
>>> SAB.OUTLINE 'gp-sphinx-badge--outline'
>>> SAB.TYPE_METHOD 'gp-sphinx-badge--type-method'
>>> SAB.STATE_AUTOUSE 'gp-sphinx-badge--state-autouse'
CSS custom properties¶
All colors and metrics are exposed as CSS custom properties on :root.
Override them in your project’s custom.css or via
add_css_file().
Defaults¶
:root {
/* ── Color hooks (set by downstream extensions) ────── */
--gp-sphinx-badge-bg: transparent; /* badge background */
--gp-sphinx-badge-fg: inherit; /* badge text color */
--gp-sphinx-badge-border: none; /* badge border shorthand */
/* ── Metrics ───────────────────────────────────────── */
--gp-sphinx-badge-font-size: 0.75em;
--gp-sphinx-badge-font-weight: 700;
--gp-sphinx-badge-padding-v: 0.35em; /* vertical padding */
--gp-sphinx-badge-padding-h: 0.65em; /* horizontal padding */
--gp-sphinx-badge-radius: 0.25rem; /* border-radius */
--gp-sphinx-badge-icon-gap: 0.28rem; /* gap between icon and label */
/* ── Depth (inset shadow on solid badges) ──────────── */
--gp-sphinx-badge-buff-shadow:
inset 0 1px 0 rgba(255, 255, 255, 0.2),
inset 0 -1px 2px rgba(0, 0, 0, 0.12);
--gp-sphinx-badge-buff-shadow-dark-ui:
inset 0 1px 0 rgba(255, 255, 255, 0.1),
inset 0 -1px 2px rgba(0, 0, 0, 0.28);
}
Property reference¶
Property |
Purpose |
|---|---|
|
Badge background color. Extensions set this per badge class (e.g. green for “readonly”). |
|
Badge text color. Falls back to |
|
Border shorthand ( |
|
Font size. Context-aware sizing (headings, body, TOC) overrides this. |
|
Font weight. Default |
|
Vertical and horizontal padding. |
|
Border radius for pill shape. |
|
Gap between the |
|
Subtle inset highlight + shadow for depth on light backgrounds. |
|
Stronger inset shadow variant for dark theme / |
CSS class reference¶
All classes use the sab- prefix (sphinx autodoc badges).
Class |
Applied by |
Description |
|---|---|---|
|
|
Base class. Always present on every badge. |
|
|
Transparent background, inherits text color. |
|
|
16 × 16 colored box with emoji |
|
|
Bare emoji inside a code chip, no background. |
|
|
Flex container with |
|
|
Flex push-right ( |
|
|
Minimum size (status dots, very tight layouts). |
|
|
Extra small (dense tables, tight UI). |
|
|
Small inline badges. |
|
|
Medium — larger than the default but smaller than |
|
|
Large (section titles, callouts). |
|
|
Extra large (hero / landing emphasis). |
Context-aware sizing¶
Badge size adapts automatically based on where it appears in the document.
CSS selectors handle it. Explicit size classes (gp-sphinx-badge--size-xs … gp-sphinx-badge--size-xl) override
contextual sizing when present (higher specificity than context rules).
Context |
Font size |
Selectors |
|---|---|---|
Heading ( |
|
|
Body ( |
|
|
TOC sidebar |
|
|