Skip to main content

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


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 details)

Uploaded Source

File details

Details for the file awesome-slugify-1.3.3.tar.gz.

File metadata

File hashes

Hashes for awesome-slugify-1.3.3.tar.gz
Algorithm Hash digest
SHA256 4cf6859c784e0dbce1b16e5b7f3256b52d2285ec5e098c593335d543dc1df513
MD5 194502c6df4c85b2fba1c39d7c1d81ad
BLAKE2b-256 601fb8fe8f4bb410840c1664830500d6dd432b0cd04632b36a65f8e37a7038db

See more details on using hashes here.

Supported by

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