Skip to main content

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_length trims back to a word boundary instead of cutting mid-word.
  • Zero dependencies. No python-slugify, no unidecode.

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

Metadata

Release files for larzslug 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for larzslug 0.1.0
File Size Uploaded
larzslug-0.1.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for larzslug 0.1.0
File Interpreter ABI Platform
larzslug-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / larzslug-0.1.0.tar.gz

Download URL larzslug-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
775a6116f15c290deb7c20be6ca234d32d2f967e4550741fbf52d6779feb686b
BLAKE2b-256 checksum
How to use checksums
76103428ef04b0238e15aebf34e964c5e8907325e3b42381230d9824e901905b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzslug-0.1.0-py3-none-any.whl

Download URL larzslug-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a342cbdd2ec4100e22b29548e1d5db4f54714fa19aa7868b9b06c9fcb0f987f
BLAKE2b-256 checksum
How to use checksums
dfe86485fd1551acb84679ce76ddaac7e27d910f9b8be108a3730411b80b6d1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page