Registry / serialization / python-slugify

python-slugify

JSON →
library8.0.4pypypi✓ verified 27d ago

Python-slugify is an actively maintained library that generates URL-friendly slugs from strings, with robust Unicode support. It is designed to create clean, human-readable, and SEO-friendly slugs by converting text, handling special characters, and replacing spaces. The library sees regular updates, with an average release cycle of approximately 71 days.

pip install python-slugify
INSTALL
IMPORT
SIG · PYTHON-SLUGIFY
P
python-slugify
serializationpythonv8.0.4
Install
1.8s avg
Import
91ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.092s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.090s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

slugify
from slugify import slugify
from slugify import slugify
A different, outdated Python 2-only package named 'slugify' (installed via `pip install slugify`) uses the same import path. Ensure you installed `python-slugify` to avoid conflicts and Python 3 incompatibility.

The primary `slugify` function is imported and used to convert strings into URL-friendly slugs. It supports various customization options like separators, maximum length, and preserving Unicode characters.

from slugify import slugify # Basic usage text = "This is a Test String with Unicode: Lörem Ipsüm!" slug = slugify(text) print(f"Basic Slug: {slug}") # Custom separator slug_with_underscore = slugify(text, separator='_') print(f"Slug with underscore: {slug_with_underscore}") # Max length short_slug = slugify("A very very long title indeed", max_length=10) print(f"Short Slug: {short_slug}") # Keep unicode characters (requires allow_unicode=True) unicode_slug = slugify("你好世界", allow_unicode=True) print(f"Unicode Slug: {unicode_slug}")
slugify --version
Debug
Known issues
gotchaThere is a separate, older Python 2-only package also named `slugify` on PyPI. Installing `pip install slugify` will give you the wrong package. Always use `pip install python-slugify` to ensure you get the correct, actively maintained Python 3 library, as both packages use `from slugify import slugify` for import.
fix
Ensure `pip uninstall slugify` is run if the wrong package was installed, then `pip install python-slugify`. If possible, avoid installing both packages in the same environment.
affects: All versions of `python-slugify` when `slugify` (Python 2 package) is also present.
breakingPython 3.6 support was dropped in version 7.0.0. For the latest versions (8.x.x), the minimum required Python version is 3.10. Older Python versions should use earlier library releases.
fix
Upgrade your Python interpreter to 3.10 or newer, or pin `python-slugify` to a version compatible with your Python environment (e.g., `<7.0.0` for Python 3.6).
affects: >=7.0.0
gotchaThe optional `Unidecode` dependency (installed via `pip install python-slugify[unidecode]`) is GPL licensed. If your project's license is incompatible with GPL, ensure you do not install this extra. The default `text-unidecode` dependency is permissively licensed.
fix
If GPL license is a concern, do not install `python-slugify[unidecode]`. The package works with the default `text-unidecode` which is permissively licensed.
affects: All versions
breakingThe behavior of the `regex_pattern` parameter was inverted in version 6.0.1. It now defines characters to be *disallowed* rather than *allowed*. This changes how custom character filtering works.
fix
Review and update any custom `regex_pattern` configurations to align with the new 'disallowed characters' logic.
affects: >=6.0.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'python_slugify'
The user attempted to import the library using 'python_slugify' or 'python-slugify' instead of the correct package name, which is 'slugify'.
fix
Use `from slugify import slugify` or `import slugify` to correctly import the library.
TypeError: 'module' object is not callable
The user imported the `slugify` module directly using `import slugify` and then attempted to call the module itself as a function, instead of calling the `slugify` function provided within the module.
fix
Import the function directly using `from slugify import slugify` and then call `slugify("my string")`, or if using `import slugify`, call `slugify.slugify("my string")`.
TypeError: expected string or bytes-like object
The `slugify` function received an input that was not a string or bytes-like object (e.g., an integer, list, or None) instead of the required text.
fix
Ensure the input passed to the `slugify` function is always a string, converting other types using `str()` if needed (e.g., `slugify(str(my_number))`).
Upgrade
Version history
8.0.4latest on PyPI · released Feb 8, 2024
Audit
Dependencies
pythonrequiredRequired Python interpreter version for the library.
text-unidecoderequiredDefault dependency for Unicode decoding (permissively licensed).
UnidecodeoptionalAlternative, optional dependency for Unicode decoding. Note: this package is GPL licensed.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
python-slugify — pip install python-slugify · libregistry