Zhon is a Python library that provides constants commonly used in Chinese text processing, such as CJK characters, Chinese punctuation marks, and patterns for Pinyin and Zhuyin. The library is currently active, with version 2.1.1 released in November 2024, and generally follows an infrequent release cadence.
pip install zhonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `zhon.hanzi.characters` to find CJK characters in a string and `zhon.pinyin.word` to extract Pinyin words, leveraging Python's `re` module.
Be aware of the scope of Han ideographs. For language-specific filtering, additional logic or libraries may be required.
Upgrade your Python environment to 3.9 or newer. If compatibility with older Python is strictly necessary, consider pinning to an older Zhon version (e.g., `<2.0.0`), though these versions may be unmaintained.
Update regex pattern formatting to use f-strings or `.format()`: `re.findall(f'[{zhon.hanzi.characters}]', text)` or `re.findall('[{}]'.format(zhon.hanzi.characters), text)`.Ensure your Python environment is version 3.9 or newer. Use `python --version` to check. If needed, create a new virtual environment with a compatible Python version.
Constants are organized into thematic submodules. Correctly import and access them, for example: `import zhon.hanzi` then `zhon.hanzi.characters`.