Skip to main content

nbsplitter

The Python implementation of nbsplitter, a tool for manipulating Japanese graphemes (i.e. the smallest unit of written text that preserves pronunciation).

Usage

Splitting graphemes

>>> from nbsplitter import split_graphemes
>>> graphemes = split_graphemes("東大和市")
>>> print(graphemes.surface())
['東', '大和', '市']
>>> print(graphemes.reading_form())
['ヒガシ', 'ヤマト', 'シ']

Generating furigana

>>> from nbsplitter import generate_furigana, split_graphemes
>>> japanese = "私は学生です。"
>>> graphemes = split_graphemes(japanese)
>>> furigana = generate_furigana(japanese, graphemes)
>>> print(furigana)
'<ruby>私<rp>(</rp><rt>わたくし</rt><rp>)</rp></ruby>は<ruby>学<rp>(</rp><rt>がく</rt><rp>)</rp></ruby><ruby>生<rp>(</rp><rt>せい</rt><rp>)</rp></ruby>です。'

Rendered: 私(わたくし)は学(がく)生(せい)です。

Known Limitations

Inability to differentiate between unvoiced-to-voiced consonant changes and some inherently voiced readings

Consider the output below:

graphemes = split_graphemes("富士", split_voiced=False)
print(graphemes.reading_form())
# Output: ['フジ']  <-- WRONG: should be ['フ', 'ジ']

This occurs because the intended reading ジ chosen for the kanji 士 isn't present in the algorithm's kanji dictionary, so the kanji is treated as dependent on the character immediately prior and the entire string is interpreted as a single grapheme.

Along with the ability to exert granular control over splitting by type of voicing, this may be fixed in a future update.

Certain strings bearing non-kana readings

Sometimes, the tokenizer underlying the splitter algorithm yields a token reading that isn't written in katakana like expected. For instance,

graphemes = split_graphemes("送品")
print(graphemes.reading_form())
# Output: ['送品']  <-- WRONG: should be ['ソウ', 'ヒン']

This may be fixed in a future update.

API Reference

Grapheme

A single grapheme.

Represents the smallest unit of written text that maintains its intended pronunciation. Can either be a single character or a multi-character compound with a distinct pronunciation.

Grapheme.reading_form()

The reading form of this grapheme (in katakana).

Grapheme.surface()

The original Japanese form of this grapheme.

GraphemeList

A list of graphemes.

GraphemeList.reading_form()

A list containing every grapheme's reading form (in katakana).

GraphemeList.surface()

A list containing every grapheme's original Japanese form.

generate_furigana()

Generates HTML-flavored furigana for kanji in some text.

Args:

  • japanese: The text to generate furigana for.
  • graphemes: The list of graphemes that corresponds with japanese.
  • format: The format the output furigana should be in.

Returns:

  • A string containing japanese with HTML furigana ruby insertions when appropriate.

split_graphemes()

Splits Japanese text into graphemes.

Args:

  • japanese: The text to be split.
  • split_voiced: If True the voiced counterparts of voiceless kanji readings will be treated as standalone readings, most notably in instances of rendaku (see https://en.wikipedia.org/wiki/Rendaku).
  • split_sokuon: If True the sokuon (see https://en.wikipedia.org/wiki/Sokuon) and phonetically indivisble units of text ending with a sokuon will be treated as independent graphemes.
  • split_hatsuon: If True the hatsuon (see https://en.wikipedia.org/wiki/Japanese_phonology#Moraic_nasal) and phonetically indivisble units of text ending with a hatsuon will be treated as independent graphemes.
  • split_modifiers: If True kana modifier characters, namely yoon (see https://en.wikipedia.org/wiki/Y%C5%8Don), choon (see https://en.wikipedia.org/wiki/Ch%C5%8Donpu), and small vowels will be treated as independent graphemes.
  • split_long: If True kana used to lengthen vowel sounds that are normally pronounced as that same vowel sound will be treated as independent graphemes.
  • split_offglides: If True offglide kana solely used to lengthen vowel sounds (the "i" in "ei" or the "u" in "ou") will be treated as independent graphemes.
  • split_clipped: If True the clipped versions of on'yomi readings whose last mora can be clipped to a sokuon will be treated as standalone readings (see https://en.wikipedia.org/wiki/Japanese_phonology#Sino-Japanese_gemination). Note that split_sokuon must be True for this behavior to be active.
  • split_rendaku: DEPRECATED: This parameter is no longer used and will be removed in version 2.0.0; use split_voiced instead for similar functionality. NOT RECOMMENDED: Use only if intending on verifying graphemes later on. This option may interpret compounds whose latter parts happen to be the voiced equivalents of unvoiced counterparts as examples of rendaku when they should not be considered as such. If True latter parts of a multi-kanji compound affected by rendaku (see https://en.wikipedia.org/wiki/Rendaku) are treated as separate graphemes.

Returns:

  • A GraphemeList representing the split text.

Raises:

  • ValueError: If split_sokuon is False and split_clipped is not None.

Acknowledgements

This package relies on KANJIDIC dictionary files. These files are property of the Electronic Dictionary Research and Development Group (EDRDG) and are used in accordance with the Group's license.

Metadata

Release files for nbsplitter 1.2.0

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

Source distribution (sdist)

Source distribution for nbsplitter 1.2.0
File Size Uploaded Provenance Actions
nbsplitter-1.2.0.tar.gz 1.5 MB With provenance Details for nbsplitter-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nbsplitter 1.2.0
File Interpreter ABI Platform Actions
nbsplitter-1.2.0-py3-none-any.whl Python 3 none any Details for nbsplitter-1.2.0-py3-none-any.whl

Total release size: 3.1 MB

Release files / nbsplitter-1.2.0.tar.gz

Download URL nbsplitter-1.2.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
67e1c361f13e49c4af91f12bbcef8507040e7ef7bd7a7377853fde7523fdba54
BLAKE2b-256 checksum
How to use checksums
11da3db783a7d1b76a26c6809061618524c71ab0fe71b41cf9747764542b1239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / nbsplitter-1.2.0-py3-none-any.whl

Download URL nbsplitter-1.2.0-py3-none-any.whl
Size 1.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4650431c0a3347b7fd85afc537820f07cf2583cc8136063aca690356636429e8
BLAKE2b-256 checksum
How to use checksums
6856af515a2c134119c8d03008169bdb15d6c5d80151d153d3c1bc0704d4ede7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for nbsplitter 1.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nbsplitter-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

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.

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