Skip to main content

Unicode normalization forms (NFC, NFKC, NFD, NFKD). A library independent from the Python core Unicode database.

Project description

pyunormalize

A pure Python implementation of the Unicode normalization algorithm independent from the Python core Unicode database. This package supports version 15.1 of the Unicode standard (released in September 2023). It has been thoroughly tested against the Unicode test file.

For the formal specification of the Unicode normalization algorithm, see Section 3.11, Normalization Forms, in the Unicode core specification.

Installation

The easiest method to install is using pip:

pip install pyunormalize

UCD version

To get the version of the Unicode character database currently used:

>>> from pyunormalize import UCD_VERSION
>>> UCD_VERSION
'15.1.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:

Licenses

The code is available under the MIT license.

Usage of Unicode data files is governed by the UNICODE TERMS OF USE. Further specifications of rights and restrictions pertaining to the use of the Unicode data files and software can be found in the Unicode Data Files and Software License, a copy of which is included as UNICODE-LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyunormalize-15.1.0.tar.gz (515.5 kB view details)

Uploaded Source

File details

Details for the file pyunormalize-15.1.0.tar.gz.

File metadata

  • Download URL: pyunormalize-15.1.0.tar.gz
  • Upload date:
  • Size: 515.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for pyunormalize-15.1.0.tar.gz
Algorithm Hash digest
SHA256 cf4a87451a0f1cb76911aa97f432f4579e1f564a2f0c84ce488c73a73901b6c1
MD5 31aaa8cbca6e409dec59b07d4ea24419
BLAKE2b-256 dc5bddc89263363422c0d52fdc0a4d88a126621d5cb60359cd45679d3c0447fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page