A slugifier that works in unicode
Python
Latest commit a73321c Oct 9, 2015 @davedash davedash Merge pull request #19 from DylannCordel/py3.x_tox_and_travis
python 3.x compat + tox and travis support
Permalink
Failed to load latest commit information.
slugify python 3.x compatibilit and tox + travis auto tests Jun 11, 2015
.gitignore
.travis.yml python 3.x compatibilit and tox + travis auto tests Jun 11, 2015
LICENSE initial commit where I steal code from amo Mar 24, 2011
MANIFEST.in Markdown everywhere Mar 24, 2011
README.md add new param (`space_replacement`) and exemples Jun 11, 2015
dev-requirements.txt add tests for only_ascii, lower and spaces combinations Jun 11, 2015
requirements.txt add tests for only_ascii, lower and spaces combinations Jun 11, 2015
setup.py Revert "opens README.md in utf-8 encoding" Jan 13, 2015
tox.ini python 3.x compatibilit and tox + travis auto tests Jun 11, 2015

README.md

Unicode Slugify

Unicode Slugify is a slugifier that generates unicode slugs. It was originally used in the Firefox Add-ons web site to generate slugs for add-ons and add-on collections. Many of these add-ons and collections had unicode characters and required more than simple transliteration.

Usage

from slugify import slugify, SLUG_OK

# Default usage : lower, spaces replaced with "-", only alphanum and "-_~" chars, keeps unicode
slugify(u'Bän...g (bang)')
# u'bäng-bang'

# Keep capital letters and spaces
slugify(u'Bän...g (bang)', lower=False, spaces=True)
# u'Bäng bang'

# Replace non ascii chars with their "best" representation
slugify(u'北京 (capital of China)', only_ascii=True)
# u'bei-jing-capital-of-china'

# Allow some extra chars
slugify(u'北京 (capital of China)', ok=SLUG_OK+'()', only_ascii=True)
# u'bei-jing-(capital-of-china)'

# "snake_case" exemple
def snake_case(s):
    # As "-" is not in allowed Chars, first one (`_`) is used for space remplacement
    return slugify(s, ok='_', only_ascii=True)
snake_case(u'北京 (capital of china)')
# u'bei_jing_capital_of_china'

# "CamelCase" exemple
def camel_case(s):
    return slugify(s.title(), ok='', only_ascii=True, lower=False)
camel_case(u'北京 (capital of china)')
# u'BeiJingCapitalOfChina'

Thanks

Tomaz Solc, unidecode, https://pypi.python.org/pypi/Unidecode