Python flexible slugify function
Project description
Python flexible slugify function
Install
pip install awesome-slugify
Usage
from slugify import slugify
slugify(u'Any text') # u'Any-text'
slugify optional args
to_lower # if True convert text to lowercase
max_length # output string max length
separator # separator string
capitalize # if True upper first letter
Custom slugify
from slugify import Slugify
custom_slugify = Slugify(separator='.')
custom_slugify(u'Any text') # u'Any.text'
Slugify args
pretranslate = None # function or dict for replace before translation
translate = unidecode.unidecode # function for slugifying or None
safe_chars = '' # additional safe chars
to_lower = False # default to_lower value
max_length = None # default max_length value
separator = '-' # default separator value
capitalize = False # default capitalize value
Examples
from slugify import slugify, slugify_unicode, slugify_ru
from slugify import Slugify
slugify('one kožušček') # one-kozuscek
slugify('one two three', separator='.') # one.two.three
slugify('one two three four', max_length=12) # one-two-four (12 chars)
slugify('one TWO', capitalize=True) # One-TWO
slugify('Я ♥ борщ') # Ia-borshch (standard translation)
slugify_ru('Я ♥ борщ') # Ya-borsch (alternative russian translation)
slugify_unicode('Я ♥ борщ') # Я-борщ (sanitize only)
filename_slugify = Slugify(safe_chars='-_.', separator='_')
filename_slugify(u'Дrаft №2.txt') # Draft_2.txt
my_slugify = Slugify(pretranslate={'я': 'i', '♥': 'love', 'щ': 'sch'}, separator='.')
my_slugify('Я ♥ борщ') # I.love.borsch (custom translate)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
awesome-slugify-1.3.3.tar.gz
(6.5 kB
view hashes)