Python Slugify

8.0.4 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →