Skip to main content

The hyphenation library of OpenOffice and FireFox wrapped for Python

Project description

PyHyphen is a wrapper around the high quality hyphenation library
hyphen-2.4 (May 2008) that ships
with OpenOffice.org and Mozilla products. Hence, all dictionaries
compatible with OpenOffice can be used.

This distribution of PyHyphen runs on Windows and Linux with Python 2.4, 2.5 and 2.6.
There is also a distribution for Python 3.0 (if not yet on the pypi, check out the svn repository).

The windows distributions may include pre-compiled binary files of the extension
module hnj containing the C library that does the ground work.

By default, the appropriate binary, if available, will be installed rather
than compiling the C sources.
Currently, the P2.x distribution ships with binaries for P2.4 and 2.5.

PyHyphen also contains textwrap2, an enhanced though backwards-compatible version of the standard Python module textwrap. Not very surprisingly, textwrap2 can hyphenate words when wrapping them.

Changes in version 0.8:
- upgraded to C library hyphen 2.4 (supports compound words and parameters for the
minimum number of characters to be cut off by hyphenation) Note that this might
require small code changes to existing applications.
- an enhanced dictionary for en_US
- many small improvements under the hood
- support for Python 2.4-2.6 and 3.0


Code example:

from hyphen import hyphenator
from hyphen.dictools import *

# Download and install some dictionaries in the default directory using the default
# repository, usually the OpenOffice website
for lang in ['de_DE', 'fr_FR', 'en_UK', 'hu_HU']:
if not is_installed(lang): install(lang)

# Create some hyphenators
h_de = hyphenator('de_DE')
h_en = hyphenator(lmin = 3, rmin = 3) # the en_US dictionary is used by default!
h_hu = hyphenator('hu_HU')

# Now hyphenate some words

print h_hu.inserted(u'asszonnyal')
'asz=szony=nyal'

print h_en.pairs('beautiful')
[[u'beau', u'tiful'], [u'beauti', u'ful']]

print h_en.wrap('beautiful', 6)
[u'beau-', u'tiful']

print h_en.wrap('beautiful', 7)
[u'beauti-', u'ful']

from textwrap2 import fill
print fill('very long text...', width = 40, use_hyphenator = h_en)

The PyHyphen's Subversion repository is hosted at http://pyhyphen.googlecode.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyHyphen-0.8.tar.gz (144.0 kB view details)

Uploaded Source

File details

Details for the file PyHyphen-0.8.tar.gz.

File metadata

  • Download URL: PyHyphen-0.8.tar.gz
  • Upload date:
  • Size: 144.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyHyphen-0.8.tar.gz
Algorithm Hash digest
SHA256 942a2799fc9ab7f9a8f200b251c748b21b6a4e84cb2287ba80f1e65b12202b1d
MD5 a98fbdce330ac4aecddb81d5a6507578
BLAKE2b-256 aa5d0ad5fab0be209fd55e2d2c7028450f01b6790888b08aee1b2698960c12c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page