Registry / hanzidentifier

hanzidentifier

JSON →
library1.3.0pypypi✓ verified 84d ago

Hanzi Identifier is a Python module designed to identify Chinese text as either Simplified or Traditional characters. It leverages the CC-CEDICT data for character identification. The current stable version is 1.3.0. The library has an irregular release cadence, with major and minor updates occurring every few years.

pip install hanzidentifier
INSTALL
IMPORT
SIG · HANZIDENTIFIER
H
hanzidentifier
pythonv1.3.0
Install
1.6s avg
Import
98ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.101s · 18.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.094s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

hanzidentifier
import hanzidentifier
identify
from hanzidentifier import identify
Often used directly, but can also be accessed via hanzidentifier.identify.
is_simplified
from hanzidentifier import is_simplified
is_traditional
from hanzidentifier import is_traditional
has_chinese
from hanzidentifier import has_chinese

This quickstart demonstrates the core functionality of `hanzidentifier` including checking for Chinese characters, identifying a string's type (Simplified, Traditional, Both, Mixed, Unknown), and using the helper functions `is_simplified` and `is_traditional`.

import hanzidentifier # Basic identification print(f"'你好!' identifies as: {hanzidentifier.identify('你好!')}") print(f"'你好!' is Simplified: {hanzidentifier.is_simplified('你好!')}") print(f"'你好!' is Traditional: {hanzidentifier.is_traditional('你好!')}") # Example with strictly Simplified Chinese print(f"'软件' identifies as: {hanzidentifier.identify('软件')}") print(f"'软件' is Simplified: {hanzidentifier.is_simplified('软件')}") # Example with strictly Traditional Chinese print(f"'軟體' identifies as: {hanzidentifier.identify('軟體')}") print(f"'軟體' is Traditional: {hanzidentifier.is_traditional('軟體')}") # Example with mixed characters print(f"'国家和國家' identifies as: {hanzidentifier.identify('国家和國家')}") # Example with no Chinese characters print(f"'Hello World' has Chinese: {hanzidentifier.has_chinese('Hello World')}") print(f"'Hello World' identifies as: {hanzidentifier.identify('Hello World')}")
Debug
Known issues
breakingVersion 1.0 (released 2014-04-12) introduced breaking changes, including renaming some constants. Code written for versions prior to 1.0 will likely fail.
fix
Refer to the CHANGES.rst file in the GitHub repository for detailed migration steps if upgrading from pre-1.0 versions. Re-evaluate constant names used in your code.
affects: <1.0
gotchaThe `identify()` function may return `hanzidentifier.BOTH` for strings containing characters that are valid in both Simplified and Traditional Chinese character sets. This means `is_simplified()` or `is_traditional()` might return `False` if the string isn't *exclusively* of that type, even if it contains characters compatible with it.
fix
Understand that `BOTH` signifies compatibility with both systems. If you need to confirm if a string *can* be interpreted as Simplified or Traditional, consider if `identify() in (hanzidentifier.SIMPLIFIED, hanzidentifier.BOTH, hanzidentifier.MIXED)` (for Simplified) or similar logic for Traditional, fits your use case.
affects: >=1.0
gotchahanzidentifier is designed to identify Chinese characters. While many Japanese Kanji and Korean Hanja share ideographs with Chinese, this library does not distinguish between these languages. It will identify shared characters as Chinese.
fix
If differentiating between Chinese, Japanese Kanji, and Korean Hanja is critical, combine `hanzidentifier` with other language detection libraries or specific CJK character set checkers.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'hanzidentifier'
The `hanzidentifier` library has not been installed in your current Python environment.
fix
Run `pip install hanzidentifier` in your terminal to install the package.
My code expects `hanzidentifier.is_simplified()` to return `True` for a simplified text, but it returns `False` even though the text looks simplified.
This often occurs when the string contains characters that are common to both Simplified and Traditional Chinese, leading `identify()` to return `hanzidentifier.BOTH`. `is_simplified()` strictly checks if *all* Chinese characters can be categorized as Simplified *or* are common to both, but if there's any character exclusively Traditional or if the string is just 'BOTH' without other exclusively simplified, it might not return True.
fix
Check the output of `hanzidentifier.identify()` first. If it returns `hanzidentifier.BOTH`, it means the characters are valid in both Simplified and Traditional contexts. Consider what your desired outcome is for such cases.
hanzidentifier.identify('Some English text with 你好') returns `hanzidentifier.UNKNOWN`, even though there are Chinese characters.
The `identify()` function returns `UNKNOWN` when it cannot determine the character system (Simplified, Traditional, Mixed, or Both) from the Chinese characters present. This might happen if the string primarily contains non-Chinese characters, or the Chinese characters found are too ambiguous in isolation.
fix
Use `hanzidentifier.has_chinese()` to confirm the presence of any Chinese characters. `identify()` focuses on categorizing the *type* of Chinese characters, not merely their existence. If a string has few identifiable Chinese characters amidst many non-Chinese, the identification might default to `UNKNOWN`.
Upgrade
Version history
1.3.0latest on PyPI · released Nov 20, 2024
Audit
Dependencies
zhonrequiredProvides the CC-CEDICT data used for character identification.
Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
hanzidentifier — pip install hanzidentifier · libregistry