Skip to main content

A library for Unicode normalization (NFC, NFD, NFKC, NFKD) independent of Python's core Unicode database.

Project description

pyunormalize

A pure-Python implementation of the Unicode normalization algorithm. This package conforms strictly to version 17.0 of the Unicode Standard, released in September 2025, by using its own dedicated data derived from the Unicode character database (UCD) corresponding to that version. This approach ensures total independence from the Unicode version built into the host Python environment.

All normalization functions (NFC, NFD, NFKC, and NFKD) have been thoroughly tested against the official Unicode test file for accuracy.

Python support policy

This package requires Python 3.8 or newer.

In version 17.0.0 of pyunormalize, support for Python 3.6 and 3.7 was dropped. These interpreters are past end-of-life and cannot be used reliably with modern Python packaging and installation tools.

Installation and updates

To install the package, run:

pip install pyunormalize

To upgrade to the latest version, run:

pip install pyunormalize --upgrade

Changelog

Check out the latest updates and changes here.

Unicode character database (UCD) version

Retrieve the version of the Unicode character database in use:

>>> from pyunormalize import UCD_VERSION
>>> print(UCD_VERSION)
17.0.0

Usage examples

Base normalization forms

This section demonstrates the use of the NFC, NFD, NFKC, and NFKD functions for specific normalization tasks.

from pyunormalize import NFC, NFD, NFKC, NFKD

# Example string with accented characters
text = "élève"  # "\u00E9\u006C\u00E8\u0076\u0065"

# Normalize to different forms
nfc = NFC(text)
nfd = NFD(text)

# Comparisons
print(nfc == text)  # True  (NFC preserves the original composed form)
print(nfd == nfc)   # False (NFD decomposes accented characters)

# Display Unicode code points in hexadecimal
print("NFC: " + " ".join([f"{ord(c):04X}" for c in nfc]))
print("NFD: " + " ".join([f"{ord(c):04X}" for c in nfd]))
# Output:
# NFC: 00E9 006C 00E8 0076 0065
# NFD: 0065 0301 006C 0065 0300 0076 0065

Using the generic normalize function

The normalize function can be used to apply any normalization form programmatically.

from pyunormalize import normalize

text = "désaffiliât"
print("Input\t" + " ".join([f"{ord(c):04X}" for c in text]))

# Apply each of the four forms
forms = ["NFC", "NFD", "NFKC", "NFKD"]
for form in forms:
    normalized_text = normalize(form, text)
    hex_repr = " ".join([f"{ord(c):04X}" for c in normalized_text])
    print(f"{form}\t{hex_repr}")

# Output:
# Input   0064 00E9 0073 0061 FB03 006C 0069 00E2 0074
# NFC     0064 00E9 0073 0061 FB03 006C 0069 00E2 0074
# NFD     0064 0065 0301 0073 0061 FB03 006C 0069 0061 0302 0074
# NFKC    0064 00E9 0073 0061 0066 0066 0069 006C 0069 00E2 0074
# NFKD    0064 0065 0301 0073 0061 0066 0066 0069 006C 0069 0061 0302 0074

Related resources

This implementation is based on the following resources:

Licenses

The code is available under the terms of 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-17.0.0.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyunormalize-17.0.0-py3-none-any.whl (51.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyunormalize-17.0.0.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pyunormalize-17.0.0.tar.gz
Algorithm Hash digest
SHA256 0949a3e56817e287febcaf1b0cc4b5adf0bb107628d379335938040947eec792
MD5 d3cb78bb5a74951c6caa20d69534d89f
BLAKE2b-256 25abb912c484cfb96ba4834efe050bbf10c9e157bd8189eb859aefba8712b136

See more details on using hashes here.

File details

Details for the file pyunormalize-17.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyunormalize-17.0.0-py3-none-any.whl
  • Upload date:
  • Size: 51.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pyunormalize-17.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0d93b076f938db2b26d319d04f2b58505d1cd7a80b5b72badbe7d1aa4d2a31c
MD5 7131782b63af1d6124f73f41a56613a4
BLAKE2b-256 928061512483dc509e3ae8a42fb143479d1e406ce1d91f8f08d538a3dde39c6d

See more details on using hashes here.

Supported by

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