Classes
FontVariant
dataclass
A specific font variant (weight + style).
FontVariant
dataclass 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.
filename
property 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
…
GoogleFontsDownloader
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.
download_font
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 of downloaded FontVariant objectslist[FontVariant]
—
Internal Methods 3
_build_css_url
Build Google Fonts CSS API URL.
_build_css_url
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.
_extract_font_urls
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 mapping weight-style to URL (e.g., "400-normal" -> "https://...")dict[str, str]
—
_download_file
Download a file from URL to output path.
_download_file
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 |