Module

fonts.downloader

Font downloader using Google Fonts API.

No external dependencies - uses only Python stdlib.

Classes

FontVariant dataclass
A specific font variant (weight + style).
1

A specific font variant (weight + style).

Attributes

Name Type Description
family str
weight int
style str
url str

Methods 1

filename property
Generate filename for this variant.
str
def filename(self) -> str

Generate filename for this variant.

Returns

str

GoogleFontsDownloader
Downloads fonts from Google Fonts. Uses the Google Fonts CSS API to get font URLs, then downloads …
4

Downloads fonts from Google Fonts.

Uses the Google Fonts CSS API to get font URLs, then downloads the actual .woff2 files. No API key required.

Methods 1

download_font
Download a font family with specified weights.
4 list[FontVariant]
def download_font(self, family: str, weights: list[int], styles: list[str] | None = None, output_dir: Path | None = None) -> list[FontVariant]

Download a font family with specified weights.

Parameters 4
family str

Font family name (e.g., "Inter", "Roboto")

weights list[int]

List of weights (e.g., [400, 700])

styles list[str] | None

List of styles (e.g., ["normal", "italic"])

output_dir Path | None

Directory to save font files (required)

Returns

list[FontVariant]

List of downloaded FontVariant objects

Internal Methods 3
_build_css_url
Build Google Fonts CSS API URL.
3 str
def _build_css_url(self, family: str, weights: list[int], styles: list[str]) -> str

Build Google Fonts CSS API URL.

Parameters 3
family str
weights list[int]
styles list[str]
Returns

str

_extract_font_urls
Fetch CSS from Google Fonts and extract .woff2 URLs.
1 dict[str, str]
def _extract_font_urls(self, css_url: str) -> dict[str, str]

Fetch CSS from Google Fonts and extract .woff2 URLs.

Parameters 1
css_url str
Returns

dict[str, str]

Dict mapping weight-style to URL (e.g., "400-normal" -> "https://...")

_download_file
Download a file from URL to output path.
2 None
def _download_file(self, url: str, output_path: Path) -> None

Download a file from URL to output path.

Parameters 2
url str
output_path Path