Skip to main content

URL slug generation with transliteration and uniqueness.

Project description

philiprehberger-slug

Tests PyPI version Last updated

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"

Strip HTML

from philiprehberger_slug import strip_html

strip_html("<p>Hello <b>World</b></p>")  # "Hello World"

API

Function / Class Description
slugify(text, separator, max_length, lowercase, reserved, transliterate) Generate a URL-safe slug from text
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
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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

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

Source Distribution

philiprehberger_slug-0.2.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_slug-0.2.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_slug-0.2.1.tar.gz.

File metadata

  • Download URL: philiprehberger_slug-0.2.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for philiprehberger_slug-0.2.1.tar.gz
Algorithm Hash digest
SHA256 eefe613c87ee4d300746651013c7eaa5848f6ebe375e41bbe419edc02399f116
MD5 80f10490a3627e6ee9492fe7d17e5501
BLAKE2b-256 6ced667c469e9a0e537e44dda87fd0eddbcd3c4fd8d4c018608d1e4b6724b6db

See more details on using hashes here.

File details

Details for the file philiprehberger_slug-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_slug-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d767ef41f2ef0a6edbb2d8f3a2f093d692459c1da3efeb1293ff7c7e22ac0ed
MD5 8918c4eb9377d8ca3315e190770368ee
BLAKE2b-256 d064f16963846faa06169cbbc896411a29a26461ceeb9d5997b05a0ab04592b3

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