larzslug
Slugify text into clean, URL/filename-safe slugs. Pure Python, zero deps.
Turn any title into a-clean-url-safe-slug, correctly handling accented and
non-ASCII characters, with a helper to guarantee uniqueness against slugs you've
already used.
from larzslug import slugify, unique_slug
slugify("Héllo, World! (2026)") # 'hello-world-2026'
slugify("Straße") # 'strasse'
slugify("Café & Bar", separator="_") # 'cafe_and_bar'
unique_slug("My Post", {"my-post", "my-post-2"}) # 'my-post-3'
Why
- Real transliteration.
Héllo→hello,Straße→strasse,Øystein→oystein— via Unicode decomposition plus a map for letters that don't decompose (ß, æ, ø, þ, …). Not just "drop non-ASCII". - Uniqueness built in.
unique_slug(text, existing)appends-2,-3, … so you never collide — exactly what you need for permalinks and filenames. - Word-safe truncation.
max_lengthtrims back to a word boundary instead of cutting mid-word. - Zero dependencies. No
python-slugify, nounidecode.
Install
pip install larzslug
Usage
from larzslug import slugify, unique_slug, transliterate
slugify("Top 10 Tips 2026") # 'top-10-tips-2026'
slugify("Hello World", separator="_") # 'hello_world'
slugify("Keep Case", lowercase=False) # 'Keep-Case'
slugify("very long title ...", max_length=30) # word-safe cut
transliterate("naïve café") # 'naive cafe'
unique_slug("My Post", existing_slugs) # collision-free
Tests
python -m unittest discover -s tests -v # 17 tests
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter — pairs with larzmark.
License
MIT © larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larzslug-0.1.0.tar.gz.
File metadata
- Download URL: larzslug-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
775a6116f15c290deb7c20be6ca234d32d2f967e4550741fbf52d6779feb686b
|
|
| MD5 |
88cae10af1c6582997acf02c14c47880
|
|
| BLAKE2b-256 |
76103428ef04b0238e15aebf34e964c5e8907325e3b42381230d9824e901905b
|
File details
Details for the file larzslug-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzslug-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a342cbdd2ec4100e22b29548e1d5db4f54714fa19aa7868b9b06c9fcb0f987f
|
|
| MD5 |
3c2b80dc8fac47ee1e22c57cbc297fe3
|
|
| BLAKE2b-256 |
dfe86485fd1551acb84679ce76ddaac7e27d910f9b8be108a3730411b80b6d1a
|