Registry / auth-security / confusable-homoglyphs

confusable-homoglyphs

JSON →
library3.3.1pypypi✓ verified 23d ago

Confusable Homoglyphs (version 3.3.1) is a Python library designed to detect and prevent homograph attacks by identifying visually similar Unicode characters (homoglyphs). It provides functionality to check for mixed-script strings and characters that might be confused with others from a preferred set of Unicode blocks. The library is actively maintained with regular updates to its underlying Unicode data and Python compatibility, aiming to safeguard against visual deception in text.

pip install confusable-homoglyphs
INSTALL
IMPORT
SIG · CONFUSABLE-HOMOGLY
C
confusable-homoglyphs
auth-securitypythonv3.3.1
Install
1.5s avg
Import
145ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.3.1 · 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.150s · 18.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.140s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

confusables
from confusable_homoglyphs import confusables

This quickstart demonstrates how to use `is_dangerous` to detect strings with mixed scripts and characters that could be confused with a preferred alias (e.g., 'latin'), and `is_confusable` to find all confusable characters within a string.

from confusable_homoglyphs import confusables # Check if a string contains mixed scripts and dangerous confusable characters text_dangerous = "ΑlaskaJazz" # First char is Greek Alpha text_safe = "AlaskaJazz" # All Latin is_dangerous_result = confusables.is_dangerous(text_dangerous, preferred_aliases=['latin']) print(f"Is '{text_dangerous}' dangerous? {is_dangerous_result}") is_dangerous_result_safe = confusables.is_dangerous(text_safe, preferred_aliases=['latin']) print(f"Is '{text_safe}' dangerous? {is_dangerous_result_safe}") # Check for specific confusable characters within a string text_confusable = "microsоft" is_confusable_result = confusables.is_confusable(text_confusable, greedy=True, preferred_aliases=['latin']) print(f"Is '{text_confusable}' confusable? {is_confusable_result}") text_not_confusable = "microsoft" is_confusable_result_safe = confusables.is_confusable(text_not_confusable, greedy=True, preferred_aliases=['latin']) print(f"Is '{text_not_confusable}' confusable? {is_confusable_result_safe}")
Debug
Known issues
breakingVersion 3.3.0 dropped support for Python 2 and Python versions older than 3.7. Ensure your environment uses Python 3.7 or newer for compatibility.
fix
Upgrade Python to version 3.7 or later.
affects: >=3.3.0
breakingThe `confusables.is_dangerous()` function's return value changed in version 3.3.0. It now strictly returns a boolean (True/False) as documented, whereas previously it might have returned `False` or a list of confusable characters.
fix
Adjust code to expect a boolean return value from `is_dangerous()`.
affects: >=3.3.0
gotchaThe underlying Unicode data files (categories.json and confusables.json) are now distributed with the package. While they are automatically recreated if deleted, users can optionally update them via a CLI tool, whose dependencies are installed with `pip install confusable_homoglyphs[cli]`. This ensures the data is always up-to-date with the latest Unicode Consortium releases.
fix
Consider using the `cli` bundle to manually update data files for the latest Unicode definitions, though the distributed data is kept current by maintainers.
affects: <3.3.0 (data handling changed in 3.3.0)
gotchaInstantiating `Categories` or `Confusables` objects can be a computationally intensive operation due to the loading and parsing of large Unicode data files. It is recommended to create these objects once and reuse them across multiple calls to improve performance.
fix
Initialize `confusables` object once, e.g., `from confusable_homoglyphs import confusables` at the module level or within an application's startup, and reuse its functions.
affects: All
gotchaThere are other Python libraries, such as `homoglyphs` (sometimes referred to as `homoglyphs_fork`), that offer similar but distinct functionality. Ensure you are importing from `confusable_homoglyphs` to use this specific library's API and features.
fix
Verify import statements (e.g., `from confusable_homoglyphs import confusables`) to confirm you are using the intended library.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'confusable_homoglyphs'
The 'confusable-homoglyphs' library is not installed in your Python environment.
fix
pip install confusable-homoglyphs
from homoglyphs import Confusable
Developers sometimes confuse 'confusable-homoglyphs' with other similarly named libraries like 'homoglyphs', leading to incorrect import statements and subsequent runtime errors.
fix
from confusable_homoglyphs import confusables
TypeError: object of type 'bool' has no len() (when using is_dangerous())
In 'confusable-homoglyphs' version 3.3.0 and later, the 'is_dangerous()' function's return value changed from potentially a list of confusable characters to strictly a boolean. Code expecting a list will fail.
fix
Adjust your code to expect a boolean return value from `is_dangerous()`. If you need a list of confusable characters, use `confusables.is_confusable(string, greedy=True)` instead.
confusable-homoglyphs Python version error
'confusable-homoglyphs' version 3.3.0 and newer dropped support for Python 2 and Python versions older than 3.7.
fix
Upgrade your Python environment to version 3.7 or later.
Upgrade
Version history
3.3.1latest on PyPI · released Jan 30, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
confusable-homoglyphs — pip install confusable-homoglyphs · libregistry