Skip to main content

Modern, zero-dependency URL slug generator with built-in Unicode transliteration

Project description

slugsmith

CI PyPI Python

Modern, zero-dependency Python library for generating URL-friendly slugs from Unicode text.

A drop-in replacement for python-slugify with built-in transliteration, no external dependencies, and full type annotations.

Installation

pip install slugsmith

Quick Start

from slugsmith import slugify

slugify("Hello World")          # "hello-world"
slugify("café latte")           # "cafe-latte"
slugify("Ελληνικά")             # "ellinika"
slugify("Привет мир")           # "privet-mir"
slugify("北京")                  # "bei-jing"

Features

  • Zero dependencies — built-in Unicode→ASCII transliteration; no text-unidecode or Unidecode required
  • Drop-in replacement for python-slugify — same slugify() signature
  • Language-aware — language-specific mappings for German, Turkish, Polish, Czech, Finnish, Swedish
  • Type-safe — full type annotations, PEP 561 compliant, passes mypy strict
  • MIT licensed — no GPL dependency concerns

API Reference

slugify(text, **options) -> str

Generate a URL-friendly slug from text.

Parameter Type Default Description
text str (required) Input string to slugify
separator str "-" Character(s) between words
lowercase bool True Convert to lowercase
max_length int 0 Max slug length (0 = unlimited)
word_boundary bool False Truncate at word boundary when max_length is set
save_order bool False Accepted for python-slugify compatibility (word order is always preserved)
stopwords Iterable[str] () Words to remove from the slug
regex_pattern str | None None Custom regex pattern for allowed characters
replacements Sequence[Sequence[str]] | None None Sequence of (old, new) pairs applied before transliteration; accepts lists of tuples or lists of lists
allow_unicode bool False Keep Unicode characters in the slug
lang str | None None Language code for language-specific transliteration

Returns an empty string if text is empty.

Examples

Separator and case

slugify("Hello World", separator="_")           # "hello_world"
slugify("Hello World", lowercase=False)         # "Hello-World"
slugify("Hello World", separator="")            # "helloworld"

Length limiting

slugify("the quick brown fox", max_length=15)               # "the-quick-brow"
slugify("the quick brown fox", max_length=15, word_boundary=True)  # "the-quick"

Stopwords

slugify("the quick brown fox", stopwords=("the",))   # "quick-brown-fox"

Replacements

slugify("C++ is great", replacements=[("++", "pp")])  # "cpp-is-great"
slugify("$100 deal", replacements=[("$", "dollar")])   # "dollar100-deal"

Unicode passthrough

slugify("café au lait", allow_unicode=True)   # "café-au-lait"
slugify("北京 city", allow_unicode=True)       # "北京-city"

Language-specific transliteration

slugify("Ü-bung", lang="de")    # "ue-bung"   (German: ü→ue, ö→oe, ä→ae)
slugify("çalış", lang="tr")     # "calis"     (Turkish: ç→c, ş→s)
slugify("łódź", lang="pl")      # "lodz"      (Polish: ł→l, ó→o, ź→z)
slugify("říjen", lang="cs")     # "rijen"     (Czech: ř→r, í→i)

Supported language codes: de (German), tr (Turkish), pl (Polish), cs (Czech), fi (Finnish), sv (Swedish).

Script coverage

slugsmith's built-in transliteration covers a wide range of Unicode scripts without any external dependencies:

Script Coverage Example
Latin Extended Full diacritics (NFKD + explicit map) cafécafe
Cyrillic Russian + Ukrainian ПриветPrivet, їжакyizhak
Greek Modern Greek alphabet ΕλληνικάEllinika
Arabic Basic alphabet (28 letters) مرحباmrhba
Hebrew Basic alphabet (22 letters + finals) שלוםshalom
Symbols Common currency and typographic symbols €100euro100, tm

Characters not covered by the table are decomposed via NFKD normalisation; if decomposition yields ASCII, that is used. Remaining non-ASCII characters are silently dropped (same behaviour as text-unidecode).

Custom regex

# Allow only alphanumeric and hyphens (strip underscores too)
slugify("hello_world foo", regex_pattern=r"[^a-z0-9-]")  # "helloworld-foo"

Migration from python-slugify

slugsmith is a drop-in replacement:

# Before
from slugify import slugify

# After
from slugsmith import slugify

The slugify() signature is identical. No other code changes are needed.

Behavioural differences:

Feature python-slugify slugsmith
Transliteration text-unidecode (external dep) Built-in table (zero deps)
License MIT MIT (no GPL risk)
Python support 3.7+ 3.9+
Type annotations Partial Full (mypy strict)
Language-specific Not built-in lang= parameter

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

slugsmith-0.1.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

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

slugsmith-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file slugsmith-0.1.0.tar.gz.

File metadata

  • Download URL: slugsmith-0.1.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for slugsmith-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a1ae1f74e090855edc825950d5fde6712036b6ad368d17529fd90ba68901b2b1
MD5 2b9eccc24af8f044db0a18adf29f7142
BLAKE2b-256 b9b2724dc24630678faf0bfc95762d1971a33f34b3167da1addd04d01255a2de

See more details on using hashes here.

File details

Details for the file slugsmith-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: slugsmith-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for slugsmith-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a66fa18a78a721f362e2c2d986c0328ebba8c4ab6631368c4efb4a03315fa1ac
MD5 3ba0023a44d5403fb2ff36e8a1cfcb3c
BLAKE2b-256 a2a08a64c48b690949d1823aae0da3cc92da43c9100550313b0e958a7596a86e

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