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éllohello, Straßestrasse, Øysteinoystein — 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzslug-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzslug-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for larzslug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 775a6116f15c290deb7c20be6ca234d32d2f967e4550741fbf52d6779feb686b
MD5 88cae10af1c6582997acf02c14c47880
BLAKE2b-256 76103428ef04b0238e15aebf34e964c5e8907325e3b42381230d9824e901905b

See more details on using hashes here.

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

Hashes for larzslug-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a342cbdd2ec4100e22b29548e1d5db4f54714fa19aa7868b9b06c9fcb0f987f
MD5 3c2b80dc8fac47ee1e22c57cbc297fe3
BLAKE2b-256 dfe86485fd1551acb84679ce76ddaac7e27d910f9b8be108a3730411b80b6d1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page