sphinx-fonts¶
Sphinx extension for self-hosted web fonts via Fontsource. It downloads font
assets during the HTML build, caches them locally, copies them into
_static/fonts/, and exposes template context values that themes can render as
inline @font-face and preload tags.
$ pip install sphinx-fonts
Downstream conf.py¶
extensions = ["sphinx_fonts"]
sphinx_fonts = [
{
"family": "IBM Plex Sans",
"package": "@fontsource/ibm-plex-sans",
"version": "5.2.8",
"weights": [400, 500, 600, 700],
"styles": ["normal", "italic"],
"subset": "latin",
},
]
sphinx_font_preload = [
("IBM Plex Sans", 400, "normal"),
]
sphinx_font_css_variables = {
"--font-stack": '"IBM Plex Sans", system-ui, sans-serif',
}
Live specimen¶
This site uses sphinx-fonts, so the samples below are rendered with the same
template context that downstream themes receive.
Sans stack
Sphinx DX should feel intentional, readable, and fast.
Monospace stack
merge_sphinx_config(project="demo", version="1.0.0")
Configuration values¶
Config Value Index
Name |
Type |
Default |
Rebuild |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- sphinx_fonts¶
- Type:
list- Default:
[]
Font family dicts (family, package, version, weights, styles).
Registered by
sphinx_fonts.setup().Rebuild:
html.
- sphinx_font_fallbacks¶
- Type:
list- Default:
[]
Fallback @font-face declarations with metric overrides for CLS.
Registered by
sphinx_fonts.setup().Rebuild:
html.
- sphinx_font_css_variables¶
- Type:
dict- Default:
{}
CSS custom properties for Furo font stacks (e.g. –font-stack)
Registered by
sphinx_fonts.setup().Rebuild:
html.
- sphinx_font_preload¶
- Type:
list- Default:
[]
Critical font variants to preload (family, weight, style).
Registered by
sphinx_fonts.setup().Rebuild:
html.
Template context¶
The extension injects these values during html-page-context:
Variable |
Type |
Description |
|---|---|---|
|
|
File metadata for generated |
|
|
Font filenames to preload |
|
|
Metric-adjusted fallback declarations |
|
|
CSS custom properties for theme font stacks |
Notes¶
Fonts are cached under
~/.cache/sphinx-fonts.Non-HTML builders return early and do not download assets.
sphinx-gpthemeconsumes this template context automatically;gp-sphinxpreconfigures IBM Plex defaults for it.
Copyable config snippet
extensions = [
"sphinx_fonts",
]
Package metadata
Source on GitHub: sphinx-fonts
PyPI: sphinx-fonts
Maturity:
Beta
Registered Surface
sphinx_fonts
Config values
Name |
Default |
Rebuild |
Types |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|