Skip to main content

grapheme-kit

Grapheme-aware evaluation metrics and text processing utilities for any language.

PyPI Python License: MIT

Live Demo · Documentation


Why grapheme-kit?

Unicode text is complex: a single visible character (grapheme cluster) often spans multiple code points. Naive string operations get lengths, distances, and evaluation metrics wrong when combining marks, diacritics, or conjuncts are present.

grapheme-kit operates at the grapheme-cluster level, ensuring all measurements reflect human-perceived text structure, not raw byte or code point counts.

from grapheme_kit import Graphemizer

# Burmese
g = Graphemizer("ကျွန်ုပ်")
len("ကျွန်ုပ်")     # 8 code points (naive)
len(g)           # 3 grapheme clusters (correct)

# Bengali
g = Graphemizer("নমস্কার")
len("নমস্কার")    # 5 code points (naive)
len(g)           # 7 grapheme clusters (correct)

Installation

pip install grapheme-kit
# development
git clone https://github.com/vmenan/grapheme-kit.git
cd grapheme-kit
uv sync

Features

Segmentation

Split text from any script into correct grapheme clusters:

from grapheme_kit import Graphemizer

# Hindi
g = Graphemizer("किताब")
g.graphemes   # ['कि', 'ता', 'ब']
len(g)        # 3

# Burmese
g = Graphemizer("ကျွန်ုပ်")
g.graphemes   # ['ကျွ', 'န်ု', 'ပ်']
len(g)        # 3

String Distance

Grapheme-aware implementations of popular distance and similarity algorithms:

from grapheme_kit import levenshtein
from grapheme_kit.distance import jaro_winkler, damerau_levenshtein

# Hebrew
levenshtein("שָׁלוֹם", "שָׁלוֹב")          # 1 (only one cluster differs)

# Arabic 
levenshtein("مُعَلِّمٌ", "مُعَلِّمُ")          # 1 (diacritic-level edit, one grapheme)

# Hindi
levenshtein("किताब", "कताब")          # 1 (one grapheme cluster removed)

# Latin/English
levenshtein("kitten", "sitting")       # 3
jaro_winkler("martha", "marhta")       # 0.9611

Evaluation Metrics

Compute machine translation or text generation metrics based on grapheme clusters rather than character code points:

from grapheme_kit.metric import GraphemeCHRF, CER, charbleu

# chrF
GraphemeCHRF().sentence_score("நல்ல", ["நல்ல மாணவன்"]).score  # 37.1051

# Character Error Rate (CER)
CER("كِتَابٌ", "كِتَابَ")  # 0.25

# CharBLEU
charbleu("the quick brown fox", "the quick red fox")  # 0.7086

Decompose / Compose

Phonetic decomposition and composition (currently supported for select Indic scripts like Tamil and Sinhala):

from grapheme_kit import decompose, compose

decompose("කා")                   # 'ක්ආ'
compose("ක්ආ")                    # 'කා'
compose(decompose("வணக்கம்")) == "வணக்கம்"  # True

Command Line

The package exposes a grapheme-kit executable with a short alias gkit:

gkit graphemize "مَرْحَبًا" --count
gkit graphemize "किताब" --count
gkit distance "שָׁלוֹם" "שָׁלוֹב" --level both
gkit evaluate "நல்ல மாணவன்" "நல்ல" --metric chrf
gkit decompose "ලංකාව" --round-trip

Use gkit --help or gkit <command> --help for the full list of commands and options.


Documentation

Full documentation, guides, and API reference: grapheme-kit-docs.pages.dev

Try it interactively in the live demo.


Contributing

Issues and pull requests are welcome. Please open an issue first for major changes.

License

MIT © grapheme-kit contributors. See LICENSE for details.

Metadata

Release files for grapheme-kit 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grapheme-kit 0.1.1
File Size Uploaded Provenance
grapheme_kit-0.1.1.tar.gz 17.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for grapheme-kit 0.1.1
File Interpreter ABI Platform
grapheme_kit-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 39.4 kB

Release files / grapheme_kit-0.1.1.tar.gz

Download URL grapheme_kit-0.1.1.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20fd1f96b4a8ccb76467a91bbe3959650969ba4b92908e6cb5d4147aa798cb1e
BLAKE2b-256 checksum
How to use checksums
6a95348bbf2462e59252e920ff34bf52e950b6a3f5d075c5d0993b15e4b6b69b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / grapheme_kit-0.1.1-py3-none-any.whl

Download URL grapheme_kit-0.1.1-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
217b6d496335290d73293e967981d3591cf46d0a87191763c7120b37e86af2c5
BLAKE2b-256 checksum
How to use checksums
704b8f8f7613b2d597af941b974cb3ab2dea3e48a5bd7d9177492562e5206661
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for grapheme-kit 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page