Access Font Metadata Using FontForge Python

This guide explains how to programmatically extract font metadata—such as the family name, PostScript name, weight, and version—using the FontForge Python module. By leveraging FontForge's built-in Python scripting capabilities, you can automate font inspection and batch-process typography files directly from your terminal or Python scripts.

Prerequisites

To use FontForge in Python, you must have FontForge installed with its Python bindings enabled. You can run scripts using the FontForge executable directly (fontforge -script script.py) or by importing fontforge into a standard Python environment configured to recognize the library.

Opening a Font File

To begin inspecting metadata, load your font file using the fontforge.open() method. This function loads the font into memory and returns a font object.

import fontforge

# Open the target font file
font = fontforge.open("path/to/your/font.ttf")

Accessing Core Metadata Properties

FontForge exposes standard font metadata as direct attributes on the font object. The most commonly used metadata properties include:

  • Family Name: font.familyname (e.g., "Helvetica", "Roboto")
  • PostScript Name: font.fontname (e.g., "Helvetica-Bold")
  • Full Human-Readable Name: font.fullname (e.g., "Helvetica Bold")
  • Weight: font.weight (e.g., "Bold", "Regular")
  • Version: font.version (e.g., "1.000")
  • Copyright: font.copyright

Here is a complete example reading and displaying these properties:

import fontforge

font_path = "OpenSans-Regular.ttf"
font = fontforge.open(font_path)

print(f"Font Name (PostScript): {font.fontname}")
print(f"Family Name:            {font.familyname}")
print(f"Full Name:              {font.fullname}")
print(f"Weight:                 {font.weight}")
print(f"Version:                {font.version}")
print(f"Copyright:              {font.copyright}")

# Always close the font when done to free memory
font.close()

Accessing the Full SFNT Name Table

TrueType and OpenType fonts store detailed, localized metadata inside the name table. If you need access to specific name table records (such as manufacturer name, designer, or localized family names), use the sfnt_names attribute.

The sfnt_names property returns a tuple of tuples containing:

  1. Language ID / Name (e.g., 'English (US)')
  2. String Type (e.g., 'Family', 'SubFamily', 'Fullname', 'Designer')
  3. The string value

You can iterate through these records like this:

import fontforge

font = fontforge.open("OpenSans-Regular.ttf")

for lang, name_type, value in font.sfnt_names:
    print(f"[{lang}] {name_type}: {value}")

font.close()

This approach allows you to inspect every metadata record defined in the font's OpenType specifications without relying on high-level properties alone.