Skip to main content

It often happens that you have text data in Unicode, but you need to represent it in ASCII. For example when integrating with legacy code that doesn’t support Unicode, or for ease of entry of non-Roman names on a US keyboard, or when constructing ASCII machine identifiers from human-readable Unicode strings that should still be somewhat intelligeble (a popular example of this is when making an URL slug from an article title).

In most of these examples you could represent Unicode characters as “???” or “\15BA\15A0\1610”, to mention two extreme cases. But that’s nearly useless to someone who actually wants to read what the text says.

What Unidecode provides is a middle road: function unidecode() takes Unicode data and tries to represent it in ASCII characters (i.e., the universally displayable characters between 0x00 and 0x7F), where the compromises taken when mapping between two character sets are chosen to be near what a human with a US keyboard would choose.

The quality of resulting ASCII representation varies. For languages of western origin it should be between perfect and good. On the other hand transliteration (i.e., conveying, in Roman letters, the pronunciation expressed by the text in some other writing system) of languages like Chinese, Japanese or Korean is a very complex issue and this library does not even attempt to address it. It draws the line at context-free character-by-character mapping. So a good rule of thumb is that the further the script you are transliterating is from Latin alphabet, the worse the transliteration will be.

Note that this module generally produces better results than simply stripping accents from characters (which can be done in Python with built-in functions). It is based on hand-tuned character mappings that for example also contain ASCII approximations for symbols and non-Latin alphabets.

This is a Python port of Text::Unidecode Perl module by Sean M. Burke <sburke@cpan.org>.

Module content

The module exports a single function that takes an Unicode object (Python 2.x) or string (Python 3.x) and returns a string (that can be encoded to ASCII bytes in Python 3.x):

>>> from unidecode import unidecode
>>> unidecode(u'ko\u017eu\u0161\u010dek')
'kozuscek'
>>> unidecode(u'30 \U0001d5c4\U0001d5c6/\U0001d5c1')
'30 km/h'
>>> unidecode(u"\u5317\u4EB0")
'Bei Jing '

Requirements

Nothing except Python itself.

You will need a Python build with “wide” Unicode characters in order for unidecode to work correctly with characters outside of Basic Multilingual Plane. Surrogate pair encoding of “narrow” builds is not supported.

Installation

You install Unidecode, as you would install any Python module, by running these commands:

python setup.py install
python setup.py test

Source

You can get the latest development version of Unidecode with:

git clone http://www.tablix.org/~avian/git/unidecode.git

Support

Questions, bug reports, useful code bits, and suggestions for Unidecode should be sent to tomaz.solc@tablix.org

Release files for Unidecode 0.04.13

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

Source distribution (sdist)

Source distribution for Unidecode 0.04.13
File Size Uploaded
Unidecode-0.04.13.tar.gz 200.1 kB Details

Release files / Unidecode-0.04.13.tar.gz

Download URL Unidecode-0.04.13.tar.gz
Size 200.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ca58bf0ce984a20ad3a5d7fdbb7e773d8d1e5fd1570951e47c1908eed8fe0442
BLAKE2b-256 checksum
How to use checksums
31860b3072be432028641901d463a9c634b34012a75750c80cad66bf84a33a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.4.0

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

1 release file

1.0.23

2 release files

0.04.19

1 release file

0.04.18

1 release file

0.04.17

1 release file

0.04.16

1 release file

0.04.14

1 release file

This release

0.04.13 This release

1 release file

0.04.12

1 release file

0.04.11

1 release file

0.04.9

1 release file

0.04.8

1 release file

0.04.7

1 release file

0.04.6

1 release file

0.04.1

3 release files

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