AnyASCII

raw JSON →
0.3.3 verified Thu Apr 23 auth: no python install: verified

anyascii is a Python library that provides fast and accurate Unicode to ASCII transliteration. It converts any Unicode string into an ASCII representation, making it suitable for filenames, URLs, or other contexts where only ASCII characters are permitted. The current version is 0.3.3, and it maintains a relatively stable release cadence with updates for data improvements or internal packaging.

pip install anyascii
error ModuleNotFoundError: No module named 'anyascii'
cause The 'anyascii' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install anyascii'.
error ImportError: cannot import name 'anyascii' from 'anyascii'
cause Incorrect import statement; 'anyascii' is a function within the 'anyascii' module.
fix
Use the correct import statement: 'from anyascii import anyascii'.
error TypeError: 'module' object is not callable
cause Attempting to call the module directly instead of the function within it.
fix
Call the function explicitly: 'from anyascii import anyascii; anyascii("string")'.
error AttributeError: module 'anyascii' has no attribute 'anyascii'
cause This error occurs when the user has imported the specific 'anyascii' function using `from anyascii import anyascii` but then incorrectly tries to access it again as an attribute of the module (e.g., `anyascii.anyascii('text')`).
fix
After from anyascii import anyascii, call the function directly: anyascii('text')
error NameError: name 'anyascii' is not defined
cause This usually happens when the user has imported the module as `import anyascii` but then tries to call the function directly as `anyascii('text')` instead of `anyascii.anyascii('text')`.
fix
If import anyascii is used, call the function as anyascii.anyascii('text'). Alternatively, use from anyascii import anyascii and then call anyascii('text').
breaking Python 2 support was dropped in version 0.2.0. If your project requires Python 2 compatibility, you must pin the `anyascii` version to `<0.2` (e.g., `anyascii==0.1.7`).
fix Upgrade to Python 3 or restrict `anyascii` version to `<0.2` in `requirements.txt`.
gotcha Transliteration is an inherently lossy process. While `anyascii` provides a robust ASCII representation, it may not perfectly preserve all semantic or linguistic nuances of the original Unicode string. Users should be aware that the output is a best-effort ASCII approximation.
fix Understand that the output is an ASCII approximation and not a round-trip conversion. For critical applications, review the transliterated output.
gotcha `anyascii` focuses purely on Unicode to ASCII transliteration. It does not perform other text normalization tasks such as lowercasing, stripping extra whitespace, or handling character compositions beyond what's necessary for direct ASCII mapping. For broader text cleaning, combine it with other libraries.
fix If additional text normalization is required, use `anyascii` in conjunction with other string manipulation techniques or libraries (e.g., `str.lower()`, `str.strip()`, `unicodedata.normalize`).
runtime status import time mem disk
3.10-alpine 0.04s 1.9MB 20.4M
3.10-slim 0.02s 1.9MB 21M
3.11-alpine 0.06s 2.0MB 22.2M
3.11-slim 0.04s 2.0MB 23M
3.12-alpine 0.07s 2.7MB 14.1M
3.12-slim 0.09s 2.7MB 15M
3.13-alpine 0.07s 2.6MB 13.7M
3.13-slim 0.07s 2.4MB 14M
3.9-alpine 0.04s 2.1MB 19.8M
3.9-slim 0.04s 2.1MB 20M

Demonstrates the basic usage of the `anyascii` function to transliterate various Unicode strings into their ASCII equivalents.

from anyascii import anyascii

# Example 1: Basic transliteration
text1 = '你好,世界'
result1 = anyascii(text1)
print(f"'{text1}' -> '{result1}'")

# Example 2: European characters
text2 = 'Hello, world! Pýthön æøåß®©'
result2 = anyascii(text2)
print(f"'{text2}' -> '{result2}'")

# Example 3: Mixed script
text3 = 'Ελληνικά, Русский, 日本語'
result3 = anyascii(text3)
print(f"'{text3}' -> '{result3}'")