Skip to main content

Slugging done right. Tries to support close to 300 languages.

Project description

Slugger solves the seemingly simple problem of turning a title into an url frienly slug:

>>> from slugger import Slugger
>>> s = Slugger(lang='en_US')
>>> s.sluggify(u'Headless-body-in-topless-bar')

Unlike many other slugging libraries, it also handles language-specific ascii-translation. Compare the ä, ö and ü in German

>>> s = Slugger(lang='de_DE')
>>> s.sluggify(u'Türöffner')

against Swedish:

>>> s = Slugger(lang='sv_SE')
>>> s.sluggify(u'Färsk Ägg')

Criterias of what makes a good slug vary, common requirements are a maximum length and a reduced character set that is highly URL-friendly.

To generate high-quality slugs, Slugger leverages the locale information from glibc (included in the package), the unihandecode library and some hand-written replacements.

>>> s = Slugger('en_US')
>>> s.sluggify(u'Bed & Breakfast')
>>> s.sluggify(u'Folding@Home')

These are also language-aware:

>>> s = Slugger('fr_FR')
>>> s.sluggify(u'Toi & Moi')

Help out

If you find a badly generated slug, please report on github. Also, any help in implementing better support for more languages is appreciated; see the official documentation on how to get involved in development.

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

slugger-0.2.2.tar.gz (4.5 MB view hashes)

Uploaded source

Supported by

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