Skip to content
Fork of un33k/python-slugify to fix issue 68
Python
Branch: master
Clone or download
Pull request Compare This branch is 33 commits ahead, 22 commits behind un33k:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
slugify
tests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
MANIFEST.in
README.md
appveyor.yml
conftest.py
setup.py
test-requirements.txt

README.md

permissive-slugify

Fork of un33k/python-slugify to fix issue 68.

License Version
Travis CI Coverage
AppVeyor Supported versions
Wheel Implementation
Status Downloads
Show your support

Improvements

  • Support for extras_require and cmdclass
  • Refactored
  • Deploy from Travis CI
  • Added Appveyor Integration
  • Uses pytest
  • Uses CodeCov

How to install

By default, permissive-slugify uses Unidecode as decoder which is GPL-licensed.

pip install permissive-slugify

Specifying decoder

You can specify which decoder will be used:

  • Unidecode - (GPL-licensed).

    pip install permissive-slugify[unidecode]
    easy_install permissive-slugify[unidecode]
  • text-unidecode (GPL & Perl Artistic)

    pip install permissive-slugify[text-unidecode]
    easy_install permissive-slugify[text-unidecode]

How to use

# -*- coding: utf-8 -*-
from slugify import slugify

txt = "This is a test ---"
slug = slugify(txt)
assert slug == "this-is-a-test"

txt = '影師嗎'
slug = slugify(txt)
assert slug == "ying-shi-ma"

txt = 'C\'est déjà l\'été.'
slug = slugify(txt)
assert slug == "c-est-deja-l-ete"

txt = 'Nín hǎo. Wǒ shì zhōng guó rén'
slug = slugify(txt)
assert slug == "nin-hao-wo-shi-zhong-guo-ren"

txt = 'Компьютер'
slug = slugify(txt)
assert slug == "kompiuter"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=9)
assert slug == "jaja-lol"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=15, word_boundary=True)
assert slug == "jaja-lol-a"

txt = 'jaja---lol-méméméoo--a'
slug = slugify(txt, max_length=20, word_boundary=True, separator=".")
assert slug == "jaja.lol.mememeoo.a"

txt = 'one two three four five'
slug = slugify(txt, max_length=13, word_boundary=True, save_order=True)
assert slug == "one-two-three"

txt = 'the quick brown fox jumps over the lazy dog'
slug = slugify(txt, stopwords=['the'])
assert slug == 'quick-brown-fox-jumps-over-lazy-dog'

txt = 'the quick brown fox jumps over the lazy dog in a hurry'
slug = slugify(txt, stopwords=['the', 'in', 'a', 'hurry'])
assert slug == 'quick-brown-fox-jumps-over-lazy-dog'

txt = 'thIs Has a stopword Stopword'
slug = slugify(txt, stopwords=['Stopword'], lowercase=False)
assert slug == 'thIs-Has-a-stopword'

txt = "___This is a test___"
regex_pattern = r'[^-a-z0-9_]+'
slug = slugify(txt, regex_pattern=regex_pattern)
assert slug == "___this-is-a-test___"

txt = "___This is a test___"
regex_pattern = r'[^-a-z0-9_]+'
slug = slugify(txt, separator='_', regex_pattern=regex_pattern)
assert slug != "_this_is_a_test_"

txt = '10 | 20 %'
slug = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])
assert slug == "10-or-20-percent"

References

Author

You can’t perform that action at this time.