Created 9 July 2007, last updated 12 July 2007
Hyphenate.py implements Frank Liang’s hyphenation algorithm (the one used in TeX) in Python.
This module provides a single function to hyphenate words. hyphenate_word takes a string (the word), and returns a list of parts that can be separated by hyphens:
['hy', 'phen', 'ation']
['su', 'per', 'cal', 'ifrag', 'ilis', 'tic', 'ex', 'pi', 'ali', 'do', 'cious']
This Python code is in the public domain.
The module as provided only hyphenates English words, but if you can find TeX hyphenation patterns for another language (and can deal with the character encoding issues you’ll encounter in them), the same algorithm will work for other languages.
The Liang algorithm does not provide all possible hyphenation points. It merely tries to provide some of them, without providing any wrong ones. So the set of breaks from hyphenate.py will be a subset of the full set of break points.