Python Slugify: Robust Unicode Slug Generation in Python
This repository profile is provided by osrepos.com, an open source repository discovery platform.

Summary
Python Slugify is a powerful Python library designed to create clean, URL-friendly slugs from Unicode strings. It offers extensive customization options, including handling HTML entities, setting max lengths, and defining stopwords. This tool ensures your text is properly formatted for web use, supporting various languages and complex character sets.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
Python Slugify is a robust and highly customizable Python library designed to convert strings, especially those containing Unicode characters, into clean, URL-friendly "slugs." A slug is a simplified version of a title or name, typically used in URLs, that contains only letters, numbers, and hyphens. This library excels at handling complex character sets, ensuring your web content has consistent and readable identifiers.
It makes a best effort to create slugs from unicode strings while keeping it DRY. By default, it uses text-unidecode for its decoding needs, but also offers an alternative with Unidecode for those who prefer it, which can be installed as python-slugify[unidecode]. For more details, visit the official GitHub repository.
Installation
Installing Python Slugify is straightforward using pip:
pip install python-slugify
If you prefer to use the Unidecode package for decoding, you can install it with the following command:
pip install python-slugify[unidecode]
Examples
Python Slugify provides a flexible slugify function with numerous options to tailor the output to your specific needs. Here are some common use cases:
Basic Usage:
from slugify import slugify
txt = "This is a test ---"
r = slugify(txt)
print(r)
# Output: this-is-a-test
Handling Unicode Characters:
txt = '???'
r = slugify(txt)
print(r)
# Output: ying-shi-ma
txt = 'C\'est déjà l\'été.'
r = slugify(txt)
print(r)
# Output: c-est-deja-l-ete
txt = 'Nín h?o. W? shì zh?ng guó rén'
r = slugify(txt)
print(r)
# Output: nin-hao-wo-shi-zhong-guo-ren
txt = '?????????'
r = slugify(txt)
print(r)
# Output: kompiuter
Allowing Unicode in Slugs:
txt = '???'
r = slugify(txt, allow_unicode=True)
print(r)
# Output: ???
Limiting Length and Word Boundaries:
txt = 'jaja---lol-méméméoo--a'
r = slugify(txt, max_length=9)
print(r)
# Output: jaja-lol
txt = 'jaja---lol-méméméoo--a'
r = slugify(txt, max_length=15, word_boundary=True)
print(r)
# Output: jaja-lol-a
Custom Separators and Stopwords:
txt = 'jaja---lol-méméméoo--a'
r = slugify(txt, max_length=20, word_boundary=True, separator=".")
print(r)
# Output: jaja.lol.mememeoo.a
txt = 'the quick brown fox jumps over the lazy dog'
r = slugify(txt, stopwords=['the'])
print(r)
# Output: quick-brown-fox-jumps-over-lazy-dog
Custom Replacements:
txt = '10 | 20 %'
r = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])
print(r)
# Output: 10-or-20-percent
For more examples and advanced usage, refer to the project's test file.
Why Use It
Python Slugify stands out for several reasons, making it an excellent choice for developers needing robust slug generation:
- Comprehensive Unicode Support: It effectively handles a wide array of international characters, converting them into readable ASCII equivalents or preserving them if
allow_unicodeis set. - High Customizability: With options for
max_length,word_boundary,separator,stopwords,regex_pattern,lowercase, andreplacements, you have fine-grained control over the generated slugs. - Ease of Use: The
slugifyfunction is intuitive and simple to integrate into any Python project. - Command-Line Tool: A convenient command-line utility is included, allowing for quick slug generation directly from your terminal.
- Active Maintenance: The project is actively maintained, as indicated by its support matrix for various Python versions.
Whether you are building a blog, an e-commerce site, or any application that requires clean and SEO-friendly URLs, Python Slugify provides a reliable and flexible solution.
Links
- GitHub Repository: https://github.com/un33k/python-slugify
- PyPI Project: https://pypi.org/project/python-slugify/
- License: MIT License
- Sponsor: Neekware Inc.
Related repositories
Similar repositories that may be relevant next.

unicode-slugify: A Robust Python Slugifier for Unicode Strings
July 31, 2026
unicode-slugify is a Python library developed by Mozilla, designed to generate URL-friendly slugs from strings containing Unicode characters. It offers powerful customization options, allowing users to control case, spaces, and allowed characters, making it suitable for diverse web development needs. This tool ensures that your slugs remain readable and functional across different languages.

pyparsing: A Python Library for Creating PEG Parsers
July 30, 2026
pyparsing is a Python library that offers an alternative to traditional lex/yacc or regular expressions for creating simple grammars. It allows developers to construct parsers directly in Python code, leveraging a Parsing Expression Grammar (PEG) approach. This library simplifies handling common parsing challenges like whitespace, quoted strings, and embedded comments, making text processing more intuitive.
python-nameparser: A Robust Python Module for Parsing Human Names
July 30, 2026
python-nameparser is a powerful Python module designed to accurately parse human names into distinct components like title, given, middle, family, and suffix. It offers immutable results, flexible configuration, and supports locale-specific parsing, making it an essential tool for text processing and data normalization tasks. The module recently released version 2.0, enhancing its capabilities while maintaining backward compatibility for most existing code.
django-wordpress: Integrate WordPress Content into Django
July 29, 2026
django-wordpress provides a robust solution for integrating WordPress content directly into Django applications. It offers read-only models and views, ensuring the safety of your WordPress database while allowing seamless access to posts, pages, and other data. This package is ideal for developers looking to leverage existing WordPress content within a Django framework.
Source repository
Open the original repository on GitHub.