Package: awesome-slugify
Python flexible slugify functionPyPi:https://pypi.python.org/pypi/awesome-slugifyGithub:https://github.com/dimka665/awesome-slugifyInstallpipinstallawesome-slugifyUsagefromslugifyimportslugifyslugify('Any text')# 'Any-text'Custom slugifyfromslugifyimportslugify,Slugify,UniqueSlugifyslugify('Any text',to_lower=True)# 'any-text'custom_slugify=Slugify(to_lower=True)custom_slugify('Any text')# 'any-text'custom_slugify.separator='_'custom_slugify('Any text')# 'any_text'custom_slugify=UniqueSlugify()custom_slugify('Any text')# 'any-text'custom_slugify('Any text')# 'any-text-1'slugify function optional argsto_lower# if True convert text to lowercasemax_length# output string max lengthseparator# separator stringcapitalize# if True upper first letterSlugify class argspretranslate=None# function or dict for replace before translationtranslate=unidecode.unidecode# function for slugifying or Nonesafe_chars=''# additional safe charsstop_words=()# remove these words from slugto_lower=False# default to_lower valuemax_length=None# default max_length valueseparator='-'# default separator valuecapitalize=False# default capitalize valueUniqueSlugify class args# all Slugify class args +uids=[]# initial unique idsPredefined slugify functionsSome slugify functions is predefined this way:fromslugifyimportSlugify,CYRILLIC,GERMAN,GREEKslugify=Slugify()slugify_unicode=Slugify(translate=None)slugify_url=Slugify()slugify_url.to_lower=Trueslugify_url.stop_words=('a','an','the')slugify_url.max_length=200slugify_filename=Slugify()slugify_filename.separator='_'slugify_filename.safe_chars='-.'slugify_filename.max_length=255slugify_ru=Slugify(pretranslate=CYRILLIC)slugify_de=Slugify(pretranslate=GERMAN)slugify_el=Slugify(pretranslate=GREEK)ExamplesfromslugifyimportSlugify,UniqueSlugify,slugify,slugify_unicodefromslugifyimportslugify_url,slugify_filenamefromslugifyimportslugify_ru,slugify_deslugify('one kožušček')# one-kozuscekslugify('one two three',separator='.')# one.two.threeslugify('one two three four',max_length=12)# one-two-four   (12 chars)slugify('one TWO',to_lower=True)# one-twoslugify('one TWO',capitalize=True)# One-TWOslugify_filename(u'Дrаft №2.txt')# Draft_2.txtslugify_url(u'Дrаft №2.txt')# draft-2-txtmy_slugify=Slugify()my_slugify.separator='.'my_slugify.pretranslate={'я':'i','♥':'love'}my_slugify('Я ♥ борщ')# I.love.borshch  (custom translate)slugify('Я ♥ борщ')# Ia-borshch  (standard translation)slugify_ru('Я ♥ борщ')# Ya-borsch   (alternative russian translation)slugify_unicode('Я ♥ борщ')# Я-борщ      (sanitize only)slugify_de('ÜBER Über slugify')# UEBER-Ueber-slugifyslugify_unique=UniqueSlugify(separator='_')slugify_unique('one TWO')# One_TWOslugify_unique('one TWO')# One_TWO_1slugify_unique=UniqueSlugify(uids=['cellar-door'])slugify_unique('cellar door')# cellar-door-1Custom Unique Slugify CheckerfromslugifyimportUniqueSlugifydefmy_unique_check(text,uids):iftextinuids:returnFalsereturnnotSomeDBClass.objects.filter(slug_field=text).exists()custom_slugify_unique=UniqueSlugify(unique_check=my_unique_check)# Checks the database for a matching documentcustom_slugify_unique('te occidere possunt')Running UnitTests$virtualenvvenv$venv/bin/pipinstall-rrequirements.txt$venv/bin/nosetestsslugify