fonttools

raw JSON →
4.62.1 verified Tue May 12 auth: no python install: verified quickstart: stale

fonttools is a Python library for manipulating font files, currently at version 4.62.1, with a release cadence of approximately every few months.

pip install fonttools
error ImportError: No module named fontTools
cause The 'fonttools' library is not installed in the Python environment being used, or the Python environment is not correctly configured to find it.
fix
pip install fonttools
error AttributeError: 'tuple' object has no attribute 'minimum'
cause When calling 'fontTools.varLib.instancer.instantiateSTAT' or related variable font functions, axis limits are provided as plain tuples (e.g., '(500, 900)'), but the functions expect 'AxisTriple' objects.
fix
from fontTools.varLib.instancer import AxisTriple; instantiateSTAT(font, {"wght":AxisTriple(500,500,900)})
error ImportError: No module named brotli
cause The 'brotli' compression library, a required dependency for processing WOFF2 font files, is not installed in the Python environment.
fix
pip install brotli
error SyntaxError: invalid syntax (when trying to run 'ttx' command directly in Python script)
cause The 'ttx' command is a command-line utility provided by 'fonttools' and cannot be executed directly as a Python statement within a script; it must be run via the operating system's shell.
fix
import os; os.system("ttx /path/to/font.ttf") OR import subprocess; subprocess.run(["ttx", "/path/to/font.ttf"])
breaking fonttools 4.60.0 dropped support for Python 3.9.
fix Upgrade to Python 3.10 or later.
deprecated The 'fonttools[ufo]' extra now uses 'fontTools.misc.filesystem' instead of 'pyfilesystem2'.
fix Update your imports to 'from fontTools.misc.filesystem import ...'.
gotcha Ensure 'setuptools' is installed to avoid build errors during installation.
fix Install 'setuptools' using 'pip install setuptools'.
gotcha The 'TTFont' constructor received a path to a font file that does not exist. Ensure the specified font file path is correct and the file is accessible.
fix Verify that the path provided to 'TTFont' (e.g., 'path_to_font.ttf') correctly points to an existing font file on your system.
gotcha The TTFont() constructor failed because the specified font file could not be found.
fix Ensure the font file specified in the TTFont() constructor (e.g., 'path_to_font.ttf') exists at the given path and that the application has the necessary read permissions.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.08s 39.5M
3.10 slim (glibc) - - 0.04s 43M
3.11 alpine (musl) - - 0.13s 43.9M
3.11 slim (glibc) - - 0.10s 48M
3.12 alpine (musl) - - 0.10s 35.3M
3.12 slim (glibc) - - 0.11s 39M
3.13 alpine (musl) - - 0.10s 34.9M
3.13 slim (glibc) - - 0.10s 38M
3.9 alpine (musl) - - 0.07s 38.7M
3.9 slim (glibc) - - 0.06s 42M

This script demonstrates loading a TrueType font, accessing its tables, and saving changes.

from fontTools.ttLib import TTFont

# Load a TrueType font file
font = TTFont('path_to_font.ttf')

# Access font tables
print(font.keys())

# Save changes to the font
font.save('path_to_new_font.ttf')