Everyday Utilities

python-slugify

Turns Cafe Deja Vu Grand Opening into cafe-deja-vu-grand-opening for a clean web address.

Install it: pip install python-slugify

What does it do?

python-slugify converts messy, human-written text, like an article title or product name full of spaces, punctuation, and accented letters, into a clean, URL-safe string of lowercase words joined by hyphens, called a slug. It correctly handles unicode and accented characters from many languages, turning something like cafe with an accent into plain cafe rather than garbling it, which many simpler slugify functions get wrong. Every time you notice a blog or product page URL reading like a phrase instead of a jumble of random characters, something doing this exact transformation is almost certainly behind it. It’s a tiny, single-purpose tool, but a genuinely necessary one for any website wanting clean, readable web addresses.

See it in action

This turns a messy title full of spaces, accents, and punctuation into a clean, web-friendly address like ‘cafe-deja-vu-grand-opening’.

from slugify import slugify

title = "Café Déjà Vu — Grand Opening!"
print(slugify(title))

Why would a non-developer care?

Clean, readable URLs are better for search visibility and look more trustworthy to a human clicking a link, compared to a URL full of percent-encoded symbols and random IDs. Any website with articles, products, or user profiles needs some version of this transformation happening constantly behind the scenes.

Real-world examples

Content management systems and e-commerce platforms generate slugs like this every time someone publishes a blog post or lists a new product, which is exactly why URLs across the web so consistently look like readable phrases rather than gibberish. Django’s popular web framework includes a similar built-in slugify utility, reflecting how universal this need is across web development.

Who uses it

Web developers building content sites, blogs, or e-commerce platforms that need clean, readable URLs generated automatically from titles.

How it compares to alternatives

Django ships its own built-in slugify function, but python-slugify is often preferred as a standalone tool because of its more thorough unicode transliteration, correctly converting accented and non-Latin characters that simpler implementations sometimes botch.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries