Unidecode is a Python library that provides ASCII transliterations of Unicode text. It converts non-ASCII Unicode characters into their closest ASCII approximations, which is useful for tasks like generating URL slugs or integrating with legacy systems. The current version is 1.4.0, with releases occurring as improvements to transliteration tables are made, rather than on a fixed schedule.
pip install unidecodeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the `unidecode` function for basic transliteration and a common use case like generating URL slugs.
If using `unidecode()` to generate persistent identifiers like URL slugs, either lock your `unidecode` dependency to a specific version or generate the slug once and store it in your database, rather than re-generating on the fly.
For language-specific or more sophisticated transliterations (especially for Japanese, Chinese, Korean), consider using libraries designed for those specific languages or implement pre-processing rules before using `unidecode()`.
Ensure your Python environment is built with 'wide' Unicode support (typically `sys.maxunicode > 0xffff`). This is usually the default for Python 3.7+ builds but can vary by system configuration.
Always ensure your input is a properly decoded Unicode string before passing it to `unidecode()`. If reading from a file, open it in text mode with the correct encoding (e.g., `open('file.txt', 'r', encoding='utf-8')`).Use `unidecode` primarily for internal system identifiers, search indexing, or compatibility with ASCII-only systems, not as a user-facing display mechanism. Always consider the context and potential user perception of the transliterated text.
pip install unidecode
import unidecode
result = unidecode.unidecode("Héllø Wörld")
# Alternatively, import the function directly:
# from unidecode import unidecode
# result = unidecode("Héllø Wörld")from unidecode import unidecode
text = unidecode("München")value = 123 text = unidecode(str(value)) # Ensure the input is a string