Skip to main content

best-effort representations using smaller coded character sets (ASCII, ISO 8859, etc.). The translation tables used by the codecs are from the transtab collection by Markus Kuhn.

Three types of transliterating codecs are provided:

“long”, using as many characters as needed to make a natural

replacement. For example, u00e4 LATIN SMALL LETTER A WITH DIAERESIS ä will be replaced with ae.

“short”, using the minimum number of characters to make a replacement. For example, u00e4 LATIN SMALL LETTER A WITH DIAERESIS ä will be replaced with a.

“one”, only performing single character replacements. Characters that can not be transliterated with a single character are passed through unchanged. For example, u2639 WHITE FROWNING FACE ☹ will be passed through unchanged.

Using the codecs is simple:

>>> import translitcodec
>>> import codecs
>>> codecs.encode('fácil € ☺', 'translit/long')
'facil EUR :-)'
>>> codecs.encode('fácil € ☺', 'translit/short')
'facil E :-)'

The codecs return Unicode by default. To receive a bytestring back, either chain the output of encode() to another codec, or append the name of the desired byte encoding to the codec name:

>>> codecs.encode('fácil € ☺', 'translit/one').encode('ascii', 'replace')
'facil E ?'
>>> 'fácil € ☺'.encode('translit/one/ascii', 'replace')
'facil E ?'

The package also supplies a ‘transliterate’ codec, an alias for ‘translit/long’.

Another way to use the library is to use an error handle. Error handles are available:

  • ‘strict/translit/long’, ‘strict/translit/short’, ‘strict/translit/one’ - similar to ‘strict’

  • ‘ignore/translit/long’, ‘ignore/translit/short’, ‘ignore/translit/one’ - similar to ‘ignore’

  • ‘replace/translit/long’, ‘replace/translit/short’, ‘replace/translit/one’ - similar to ‘replace’

These error handles above, work similarly to Python’s built-in ones. The difference is that transliteration is attempted first.

>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'replace/translit/long').decode('ISO-8859-2')
'Zażółć gęślą jaźń EUR :-)?!@#'
>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'replace/translit/short').decode('ISO-8859-2')
'Zażółć gęślą jaźń E :-)?!@#'
>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'replace/translit/one').decode('ISO-8859-2')
'Zażółć gęślą jaźń E ??!@#'
>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'ignore/translit/long').decode('ISO-8859-2')
'Zażółć gęślą jaźń EUR :-)!@#'
>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'ignore/translit/short').decode('ISO-8859-2')
'Zażółć gęślą jaźń E :-)!@#'
>>> codecs.encode('Zażółć gęślą jaźń € ☺另!@#', 'ISO-8859-2', 'ignore/translit/one').decode('ISO-8859-2')
'Zażółć gęślą jaźń E !@#'

translitcodec Changes

0.7.0

Released on May 8, 2021

  • Added support for error handles

  • Fixed conversion of the German eszett char

0.6.0

Released on December 13, 2020

  • Add support for Python 3.9

0.5.2

Released on January 19, 2020

  • Install package with setuptools

0.5.1

Released on January 19, 2020

  • Add python_requires to prevent installation with Python 2 packages

0.5

Released on January 18, 2020

  • Complete coverage of the Vietnamese alphabet

  • Removed Python 2 support

0.4

Released on May 11, 2015

  • Added Python 3 compatibility

0.3

Released on February 14, 2011

  • Fixes to the transtab table rebuilding tool.

  • Added translitcodec.__version__

0.2

Released on January 27, 2011

  • Resolves issue of “TypeError: character mapping must return integer, None or unicode” when a blank value (eg: N{ZERO WIDTH SPACE} u200B) was encoded. Unicode blanks are now returned.

  • Characters in the ASCII range are no longer included in the translation tables.

0.1

Released on December 28, 2008

  • Initial packaged release.

Metadata

Release files for translitcodec 0.7.0

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

Source distribution (sdist)

Source distribution for translitcodec 0.7.0
File Size Uploaded Provenance Actions
translitcodec-0.7.0.tar.gz 52.4 kB Without provenance Details for translitcodec-0.7.0.tar.gz

Release files / translitcodec-0.7.0.tar.gz

Download URL translitcodec-0.7.0.tar.gz
Size 52.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3be7975c630ec0f1dd5b3712160c991a9776132985aed2588cba083ba00fa3c8
BLAKE2b-256 checksum
How to use checksums
f128c0dbcc80648da7639b1dd3df95e8cc84c40407093d84a28234950dc740c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

Security for translitcodec 0.7.0

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.

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