Registry / serialization / opencc-python-reimplemented

opencc-python-reimplemented

JSON →
library0.1.7pypypi✓ verified 22d ago

OpenCC-python-reimplemented is a pure Python implementation of the Open Chinese Convert (OpenCC) library. It facilitates conversions between Traditional and Simplified Chinese, supporting character-level and phrase-level conversion, as well as handling character variants and regional idioms among Mainland China, Taiwan, and Hong Kong. The current version is 0.1.7, released in February 2023, indicating an infrequent release cadence.

pip install opencc-python-reimplemented
INSTALL
IMPORT
SIG · OPENCC-PYTHON-REIM
O
opencc-python-reimplemented
serializationpythonv0.1.7
Install
1.7s avg
Import
10ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.008s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.006s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenCC
from opencc import OpenCC
import opencc
While 'import opencc' might work in some contexts, directly importing 'OpenCC' from the 'opencc' package is the standard and recommended way to access the main class for conversion.

This quickstart demonstrates how to initialize the OpenCC converter with a specific conversion configuration (e.g., Simplified to Traditional Chinese) and perform text conversion. It also shows an example of Traditional to Simplified Chinese conversion.

from opencc import OpenCC cc = OpenCC('s2t') # Initialize converter: Simplified Chinese to Traditional Chinese to_convert = '你好,世界!开放中文转换。' converted_text = cc.convert(to_convert) print(f"Original: {to_convert}") print(f"Converted (s2t): {converted_text}") # Example with another conversion mode (Traditional Chinese to Simplified Chinese) cc_t2s = OpenCC('t2s') to_convert_t = '你好,世界!開放中文轉換。' converted_text_s = cc_t2s.convert(to_convert_t) print(f"Original: {to_convert_t}") print(f"Converted (t2s): {converted_text_s}")
opencc --version
Debug
Known issues
gotchaValid config strings: s2t (Simplified→Traditional), t2s (Traditional→Simplified), s2tw (Simplified→Taiwan), s2hk (Simplified→HK), tw2s (Taiwan→Simplified), hk2s (HK→Simplified), s2twp (Simplified→Taiwan+phrases), tw2sp (Taiwan→Simplified+phrases). Passing anything else raises ValueError.
fix
OpenCC('s2t')  # use the short code, not the full description
gotchaMultiple opencc packages exist: opencc, opencc-py, opencc-python, opencc-python-reimplemented. Only opencc-python-reimplemented is pure Python — others require C++ bindings and may segfault.
fix
pip install opencc-python-reimplemented
deprecatedDevelopment status is Alpha (3 - Alpha). API may change without strict semver.
fix
Pin to a specific version in production
affects: All versions up to 0.1.7
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'opencc'
opencc-python-reimplemented not installed
fix
pip install opencc-python-reimplemented
ImportError: cannot import name 'OpenCC' from 'opencc'
Direct module import instead of class import
fix
from opencc import OpenCC
AttributeError: module 'opencc' has no attribute 'convert'
convert() is a method on an OpenCC instance, not a module function
fix
cc = OpenCC('s2t'); cc.convert('text')
TypeError: __init__() missing 1 required positional argument: 'config'
OpenCC requires a config string on init
fix
OpenCC('s2t')
ValueError: Invalid configuration: 'simplified_to_traditional'
Config must be the short code, not a descriptive name
fix
Use short codes: s2t, t2s, s2tw, s2hk, tw2s, hk2s, s2twp, tw2sp
Upgrade
Version history
0.1.7latest on PyPI · released Feb 11, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
110 hits · last 30 days
node
104
OpenAI (training)
1
Resources
opencc-python-reimplemented — pip install opencc-python-reimplemented · libregistry