Skip to main content

slugify-multilang (Python)

A faithful, dependency-free Python port of the C# Slugify.MultiLang library — a multi-language, URL-safe slug generator with extended locale support and sensible handling of CJK, Arabic, and other non-Latin scripts.

Targets Python 3.10+. Standard library only (re + unicodedata).

Install

pip install slugify-multilang

Or from this folder:

cd python
pip install .

Usage

from slugify_multilang import slugify, SlugifySlugOptions, extend

slugify("Director Fu: Your alt account got exposed again!")
# -> "director-fu-your-alt-account-got-exposed-again"

slugify("Café au lait & cròissant")
# -> "cafe-au-lait-and-croissant"

slugify("傅总:你的马甲 又又又掉了!")
# -> "傅总-你的马甲-又又又掉了"

Replacement-only overload

Mirrors the C# string Slugify(this string, string replacement = "-") overload — pass a string instead of an options object:

slugify("hello world", "_")          # -> "hello_world"

Options

SlugifySlugOptions maps 1:1 to the C# SlugifySlugOptions (PascalCase → snake_case):

Field Type Default Meaning
replacement str "-" Word-joining character.
remove re.Pattern | None None Per-character strip regex (default built-in when None).
lower bool True Lowercase the result.
strict bool True Strip anything that isn't a letter, number, or whitespace.
trim bool True Trim surrounding whitespace.
locale str | None None Per-language override map.
from slugify_multilang import slugify, SlugifySlugOptions

slugify("Müdür Fu", SlugifySlugOptions(locale="de"))   # -> "mueduer-fu"
slugify("Hello World", SlugifySlugOptions(lower=False)) # -> "Hello-World"

Locale overrides exist for: bg, de, es, fr, pt, uk, vi, da, nb, it, nl, sv.

Extending the character map

Mirrors the C# Extend method — registers custom mappings globally at runtime:

from slugify_multilang import extend, slugify

extend({"☂": "umbrella", "₿": "btc"})
slugify("☂ ₿")   # -> "umbrella-btc"

How it works

Same five-step pipeline as the C# original:

  1. NFC normalize (unicodedata.normalize("NFC", ...)).
  2. Per-character translation — locale override → global charmap → passthrough.
  3. Remove pass — strip non-URL-friendly characters.
  4. Strict pass (optional) — keep only Unicode letters, numbers, whitespace.
  5. Collapse + lowercase — trim, collapse whitespace runs into replacement, lowercase.

Fidelity

This port is verified against the C# implementation:

  • All 583 global charmap entries are byte-for-byte identical.
  • All 12 locale override maps are identical.
  • The 23-language demo (python demo.py) produces output identical to the C# demo.

One documented nuance

.NET's regex \w includes Unicode combining marks (\p{Mn}); Python's re \w does not. This only affects the intermediate remove pass, and only when strict=False. With the default strict=True, combining marks are stripped by the strict pass in both implementations, so output is identical.

Demo

python demo.py

Publishing to PyPI

Automated via publish.sh (bash) or publish.ps1 (PowerShell), both mirroring the NuGet workflow in ../publish.ps1. Requires uv; publish.ps1 additionally needs pwsh (on macOS: brew install powershell).

Credentials come from your ~/.pypirc ([pypi] section) — read automatically by twine, so no token is passed on the command line:

./publish.sh                 # bash — uploads to PyPI using ~/.pypirc
./publish.sh -r testpypi     # dry-run against TestPyPI (needs a [testpypi] section)

pwsh ./publish.ps1                    # PowerShell equivalent
pwsh ./publish.ps1 -Repository testpypi

The script: reads the current version → checks __init__.py is in sync → runs the test suite → uv build → uvx twine check → uvx twine upload to pypi.org → auto-increments the patch version for next time.

twine also honours the TWINE_USERNAME / TWINE_PASSWORD env vars if you prefer not to use ~/.pypirc. uv publish is not used because it does not read ~/.pypirc.

Version-number rule

Same convention as the NuGet package: semver MAJOR.MINOR.PATCH, with the version stored in pyproject.toml being the one published now. After a successful publish the patch component is bumped automatically (e.g. 1.0.2 → 1.0.3). pyproject.toml is the single source of truth and the script keeps slugify_multilang/__init__.py's __version__ in lockstep (it refuses to publish if the two disagree). Bump MINOR/MAJOR by hand for feature/breaking releases. The Python and C# packages share the same version line (1.0.2).

Git repository URL rule

The [project.urls] Homepage and Repository point at the same repository as the C# .csproj (RepositoryUrl / PackageProjectUrl):

https://github.com/balck3py/slugify-multilag

Keep these identical to the C# project so both packages resolve to one source repo.

Metadata

Release files for slugify-multilang 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slugify-multilang 1.0.2
File Size Uploaded Provenance Actions
slugify_multilang-1.0.2.tar.gz 25.5 kB Without provenance Details for slugify_multilang-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for slugify-multilang 1.0.2
File Interpreter ABI Platform Actions
slugify_multilang-1.0.2-py3-none-any.whl Python 3 none any Details for slugify_multilang-1.0.2-py3-none-any.whl

Total release size: 37.1 kB

Release files / slugify_multilang-1.0.2.tar.gz

Download URL slugify_multilang-1.0.2.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1cfbc1e44d01a1f9d8fcceb33781bf8fd61a8e383c5fea1e380fac6ac721ac8b
BLAKE2b-256 checksum
How to use checksums
bde23e10747bc22dffb015ed2f06d1eef6304d424c8bd2758f5969fe3a5e7f59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / slugify_multilang-1.0.2-py3-none-any.whl

Download URL slugify_multilang-1.0.2-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47f51dd2581391e31e19ecfd4a498a77ca5380b69481224f92b4338f028ad925
BLAKE2b-256 checksum
How to use checksums
42eb4a33a6bb70d3d67bb8dd95625c9cb706a247bdf72d13876b24472cc9c2a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for slugify-multilang 1.0.2

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.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page