zhtelecode
is a Python package that converts between
Chinese Telegraph Codes
and Unicode Chinese characters (both simplified and traditional).
Convert from Unicode to telegraph codes:
>>> zhtelecode.to_telecode("中文信息")
['0022', '2429', '0207', '1873']
>>> zhtelecode.to_telecode("萧爱国")
['5618', '1947', '0948']
>>> zhtelecode.to_telecode("蕭愛國")
['5618', '1947', '0948']
Convert from telegraph codes back to Unicode:
>>> telecode = ["0022", "2429", "0207", "1873"]
>>> zhtelecode.to_unicode(telecode)
'中文信息'
>>> telecode = ["5618", "1947", "0948"]
>>> zhtelecode.to_unicode(telecode, encoding="mainland")
'萧爱国'
>>> zhtelecode.to_unicode(telecode, encoding="taiwan")
'蕭愛國'
The codebooks are derived from the Unicode consortium's Unihan database (last updated 2022-08-03 17:20).
Also see Unicode terms of use.