Skip to main content

A lightweight converter between hankaku(half-width) and zenkaku(full-width) characters

Project description

A lightweight converter between hankaku(half-width) and zenkaku(full-width) characters.


$ pip install Cython
$ pip install mojimoji


Zenkaku to Hankaku

>>> import mojimoji
>>> print mojimoji.zen_to_han(u'アイウabc012')
>>> print mojimoji.zen_to_han(u'アイウabc012', kana=False)
>>> print mojimoji.zen_to_han(u'アイウabc012', digit=False)
>>> print mojimoji.zen_to_han(u'アイウabc012', ascii=False)

Hankaku to Zenkaku

>>> import mojimoji
>>> print mojimoji.han_to_zen(u'アイウabc012')
>>> print mojimoji.han_to_zen(u'アイウabc012', kana=False)
>>> print mojimoji.han_to_zen(u'アイウabc012', digit=False)
>>> print mojimoji.han_to_zen(u'アイウabc012', ascii=False)


Library versions


In [19]: s = u'ABCDEFG012345' * 10

In [20]: %time for n in range(1000000): mojimoji.zen_to_han(s)
CPU times: user 2.86 s, sys: 0.10 s, total: 2.97 s
Wall time: 2.88 s

In [21]: %time for n in range(1000000): unicodedata.normalize('NFKC', s)
CPU times: user 5.43 s, sys: 0.12 s, total: 5.55 s
Wall time: 5.44 s

In [22]: %time for n in range(1000000): zenhan.z2h(s)
CPU times: user 69.18 s, sys: 0.11 s, total: 69.29 s
Wall time: 69.48 s

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mojimoji, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size mojimoji-0.0.1.tar.gz (33.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page