Skip to main content

URL slug generation with transliteration and uniqueness

Project description

philiprehberger-slug

Tests PyPI version License

URL slug generation with transliteration and uniqueness.

Installation

pip install philiprehberger-slug

Usage

Basic Slugification

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

slugify("Hello World", separator="_")    # "hello_world"
slugify("Hello World", max_length=8)     # "hello"
slugify("Hello World", lowercase=False)  # "Hello-World"

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

  • slugify(text, separator="-", max_length=0, lowercase=True) — Generate a URL-safe slug
  • unique_slugify(text, existing, separator="-", max_length=0) — Generate a unique slug with numeric suffix
  • strip_html(text) — Remove HTML tags from text

Development

pip install -e .
python -m pytest tests/ -v

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.1.4.tar.gz (4.3 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.1.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_slug-0.1.4.tar.gz
  • Upload date:
  • Size: 4.3 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.1.4.tar.gz
Algorithm Hash digest
SHA256 75ca6b31099139b8b1032af8d1ad327803c9051fd350a23f374e453dcb7d5632
MD5 51e0c92551b540b86297e0d4e76fb8e6
BLAKE2b-256 05b6e462e3cc01822338eb463174c7f12dd21fc3d083e7788a483d5335b7d3f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_slug-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cc26b97cc389b4cb2c1dc66438b8cb897165f7f6a32b3ed40e73dc6933732031
MD5 d2b27bd196b819ff17a9794ceeea7beb
BLAKE2b-256 d14973f3be1a851142801a5ffb73af7c666bf7fbbf69d96ae76e833babae0fcd

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