ufoLib2
raw JSON → 0.18.1 verified Fri May 01 auth: no python
ufoLib2 is a UFO font processing library for reading, writing, and manipulating Unified Font Object (UFO) files. It provides Python objects for font, layer, glyph, and other UFO structures with lazy loading and efficient serialization. Current version: 0.18.1. Requires Python >=3.9. Maintained by the fonttools project; release cadence is irregular with several minor releases per year.
pip install ufoLib2 Common errors
error ModuleNotFoundError: No module named 'ufoLib2' ↓
cause Library not installed.
fix
pip install ufoLib2
error AttributeError: module 'ufoLib2' has no attribute 'Glyph' ↓
cause Glyph is not exported at package level.
fix
from ufoLib2.objects import Glyph
error TypeError: save() takes 1 positional argument but 2 were given ↓
cause Trying to save with a file path as argument without keyword? Actually save only takes the path as positional.
fix
font.save('/path/to/font.ufo')
error ufoLib2.errors.UFOError: Invalid UFO version: 3 ↓
cause UFO file has format spec version that is not supported or malformed.
fix
Ensure the UFO is valid; check ufo/lib/formatversion.txt. ufoLib2 supports UFO v3 and v2.
error ImportError: cannot import name 'Font' from 'ufoLib2.objects' (unknown location) ↓
cause Wrong import path or outdated version.
fix
Use 'from ufoLib2 import Font' instead.
Warnings
breaking Python 3.8 support dropped in v0.18.0. Use Python >=3.9. ↓
fix Upgrade Python to 3.9 or later.
deprecated The 'fs' module (import fs) will be removed; replaced with tempfile.TemporaryDirectory. Do not rely on fs internals. ↓
fix Replace usage of tempfs with tempfile.TemporaryDirectory.
gotcha Font objects are lazily loaded by default. Modifying glyphs or layers may require explicit loading. ↓
fix Access properties or call .load() to trigger loading. Use Font.open(ufo, lazy=False) to disable lazy loading.
gotcha Saving a UFO creates a directory (UFO format) not a single file. Ensure the save path ends with .ufo and the parent directory exists. ↓
fix Use font.save('/path/to/MyFont.ufo') which creates a directory.
breaking cattrs minimum version upped to 1.10.0 as of v0.13.1. Older cattrs may cause errors with converters. ↓
fix Ensure cattrs >=1.10.0 is installed if using converters extra.
deprecated Use of 'from ufoLib2.objects import Font' is discouraged; prefer 'from ufoLib2 import Font'. ↓
fix Change import to 'from ufoLib2 import Font'.
Install
pip install ufoLib2[converters] pip install ufoLib2[json,msgpack] Imports
- Font wrong
from ufoLib2.objects import Fontcorrectfrom ufoLib2 import Font - Glyph wrong
from ufoLib2 import Glyphcorrectfrom ufoLib2.objects import Glyph - Layer wrong
from ufoLib2 import Layercorrectfrom ufoLib2.objects import Layer
Quickstart
from ufoLib2 import Font
# Create a new font
font = Font()
font.info.unitsPerEm = 1000
# Save to a temporary path (will create .ufo directory)
import tempfile
with tempfile.TemporaryDirectory() as tmpdir:
ufo_path = f"{tmpdir}/MyFont.ufo"
font.save(ufo_path)
print(f"Saved to {ufo_path}")
# Open an existing UFO
font2 = Font.open(ufo_path)
print(font2.info.unitsPerEm)