philiprehberger-slug
URL slug generation with transliteration and uniqueness.
Installation
pip install philiprehberger-slug
Usage
from philiprehberger_slug import slugify
slugify("Hello World!") # "hello-world"
slugify("Ünïcödé Têxt") # "unicode-text"
slugify("Straße nach München") # "strasse-nach-munchen"
Options
from philiprehberger_slug import slugify
slugify("Hello World", separator="_") # "hello_world"
slugify("Hello World", max_length=8) # "hello"
slugify("Hello World", lowercase=False) # "Hello-World"
Reserved Slug Blocking
from philiprehberger_slug import slugify, ReservedSlugError
try:
slugify("Admin", reserved=["admin", "api", "about"])
except ReservedSlugError as e:
print(e) # "Slug 'admin' is reserved. Reserved slugs: ['admin', 'api', 'about']"
Custom Transliteration
from philiprehberger_slug import slugify
slugify("Ölkörper", transliterate={"ö": "oe", "ü": "ue"}) # "oelkoerper"
Slug from Parts
from philiprehberger_slug import slug_from_parts
slug_from_parts("2026", "03", "my post title") # "2026-03-my-post-title"
slug_from_parts("Blog", "Straße & Weg") # "blog-strasse-and-weg"
Unique Slugs
from philiprehberger_slug import unique_slugify
existing = {"hello-world", "hello-world-2"}
unique_slugify("Hello World", existing) # "hello-world-3"
Validate a slug
from philiprehberger_slug import is_valid_slug
is_valid_slug("hello-world") # True
is_valid_slug("Hello World") # False
is_valid_slug("--bad--") # False
is_valid_slug("hello_world", separator="_") # True
Strip HTML
from philiprehberger_slug import strip_html
strip_html("<p>Hello <b>World</b></p>") # "Hello World"
Bulk Slugify
from philiprehberger_slug import slugify_bulk
titles = ["Hello World", "Über München", "C++ & Friends"]
slugify_bulk(titles)
# ["hello-world", "uber-munchen", "c-and-friends"]
# Cap length per slug
slugify_bulk(["Long article title here"], max_length=10)
# ["long"]
API
| Function / Class | Description |
|---|---|
slugify(text, separator, max_length, lowercase, reserved, transliterate) |
Generate a URL-safe slug from text |
slugify_bulk(texts, separator, max_length, lowercase, reserved, transliterate) |
Slugify a batch of strings with the same settings |
slug_from_parts(*parts, separator) |
Join multiple strings into a single slug |
unique_slugify(text, existing, separator, max_length) |
Generate a unique slug with numeric suffix |
is_valid_slug(text, separator) |
Return True if text is already in canonical slug form |
strip_html(text) |
Remove HTML tags from text |
ReservedSlugError |
Raised when a slug matches a reserved word |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-slug 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_slug-0.4.0.tar.gz | 181.2 kB | Without provenance | Details for philiprehberger_slug-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_slug-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_slug-0.4.0-py3-none-any.whl |
Total release size: 187.4 kB
Release files / philiprehberger_slug-0.4.0.tar.gz
| Download URL | philiprehberger_slug-0.4.0.tar.gz |
|---|---|
| Size | 181.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1db8a2f0aea6d32272fdc2edd6fab5bf47d21c0b8e2c96b557d90df5d21955b5
|
|
BLAKE2b-256 checksum How to use checksums |
721ad3be1e6c63a3218298cb10ce41017c94fe6655abc316a07d487ebed2af67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_slug-0.4.0-py3-none-any.whl
| Download URL | philiprehberger_slug-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8bb1db88c08c0249899be130b925b37bc6e0d72b77479b893e7ed85386c0deb
|
|
BLAKE2b-256 checksum How to use checksums |
922a78c1f57cd7d9d12cc8a534acbbc7949a79179fdb84559476b9a1c68e2c75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-slug 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.