Unicode normalization forms (NFC, NFKC, NFD, NFKD). A library independent of the Python core Unicode database.
Project description
pyunormalize
A pure Python implementation of the Unicode normalization algorithm independent of Python’s core Unicode database. This package conforms to version 16.0 of the Unicode standard, released in September 2024, and has been rigorously tested for accuracy using the official Unicode test file.
Installation and updates
To install the package, run:
pip install pyunormalize
To upgrade to the latest version, run:
pip install pyunormalize --upgrade
Unicode character database (UCD) version
To retrieve the version of the Unicode character database in use:
>>> from pyunormalize import UCD_VERSION
>>> UCD_VERSION
'16.0.0'
Example usage
>>> from pyunormalize import NFC, NFD, NFKC, NFKD
>>> s = "élève" # "\u00E9\u006C\u00E8\u0076\u0065"
>>> nfc = NFC(s)
>>> nfd = NFD(s)
>>> nfc == s
True
>>> nfd == nfc
False
>>> " ".join([f"{ord(x):04X}" for x in nfc])
'00E9 006C 00E8 0076 0065'
>>> " ".join([f"{ord(x):04X}" for x in nfd])
'0065 0301 006C 0065 0300 0076 0065'
>>>
>>> s = "⑴ ffi ²"
>>> NFC(s), NFKC(s), NFD(s), NFKD(s)
('⑴ ffi ²', '(1) ffi 2', '⑴ ffi ²', '(1) ffi 2')
>>> from pyunormalize import normalize
>>> normalize("NFKD", "⑴ ffi ²")
'(1) ffi 2'
>>> forms = ["NFC", "NFD", "NFKC", "NFKD"]
>>> [normalize(f, "\u017F\u0307\u0323") for f in forms]
['ẛ̣', 'ẛ̣', 'ṩ', 'ṩ']
Related resources
This implementation is based on the following resources:
- Section 3.11, “Normalization Forms,” in the Unicode core specification, version 16.0.0
- Unicode Standard Annex #15: Unicode Normalization Forms, revision 56
Licenses
The code is licensed under the MIT license.
Usage of Unicode data files is subject to the UNICODE TERMS OF USE. Additional rights and restrictions regarding Unicode data files and software are outlined in the Unicode Data Files and Software License, a copy of which is included as UNICODE-LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyunormalize-16.0.0.tar.gz
.
File metadata
- Download URL: pyunormalize-16.0.0.tar.gz
- Upload date:
- Size: 50.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e1dfbb4a118154ae26f70710426a52a364b926c9191f764601f5a8cb12761f7 |
|
MD5 | 5936760e58090bb7a54366ccf31be79f |
|
BLAKE2b-256 | b308568036c725dac746ecb267bb749ef930fb7907454fe69fce83c8557287fb |
File details
Details for the file pyunormalize-16.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyunormalize-16.0.0-py3-none-any.whl
- Upload date:
- Size: 49.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c647d95e5d1e2ea9a2f448d1d95d8518348df24eab5c3fd32d2b5c3300a49152 |
|
MD5 | a7a9fa8837a611d03529dbec4254fb32 |
|
BLAKE2b-256 | 39f99d86e56f716e0651194a5ad58be9c146fcaf1de6901ac6f3cd3affeeb74e |