API Reference

class pyphen.Pyphen(filename=None, lang=None, left=2, right=2, cache=True)

Hyphenation class, with methods to hyphenate strings in various ways.

inserted(word, hyphen='-')

Get the word as a string with all the possible hyphens inserted.

Parameters:
  • word – unicode string of the word to hyphenate

  • hyphen – unicode string used as hyphen character

E.g. for the dutch word 'lettergrepen', this method returns the unicode string 'let-ter-gre-pen'. The hyphen string to use can be given as the second parameter, that defaults to '-'.

iterate(word)

Iterate over all hyphenation possibilities, the longest first.

Parameters:

word – unicode string of the word to hyphenate

positions(word)

Get a list of positions where the word can be hyphenated.

Parameters:

word – unicode string of the word to hyphenate

See also HyphDict.positions. The points that are too far to the left or right are removed.

wrap(word, width, hyphen='-')

Get the longest possible first part and the last part of a word.

Parameters:
  • word – unicode string of the word to hyphenate

  • width – maximum length of the first part

  • hyphen – unicode string used as hyphen character

The first part has the hyphen already attached.

Returns None if there is no hyphenation point before width, or if the word could not be hyphenated.

pyphen.language_fallback(language)

Get a fallback language available in our dictionaries.

http://www.unicode.org/reports/tr35/#Locale_Inheritance

We use the normal truncation inheritance. This function needs aliases including scripts for languages with multiple regions available.

pyphen.LANGUAGES

Dict of languages including codes as keys and dictionary Path as values.