Skip to main content

py-pinyin-split

A Python library for splitting Hanyu Pinyin words into syllables. Built on NLTK's tokenizer interface, it handles standard syllables defined in the Pinyin Table and supports tone marks.

Based originally on pinyinsplit by @tomlee.

PyPI: https://pypi.org/project/py-pinyin-split/

Installation

Requires Python 3.8 or newer.

pip install py-pinyin-split

Usage

Instantiate a tokenizer and split away.

The tokenizer can handle standard Hanyu Pinyin with whitespaces and punctuation. However, invalid pinyin syllables will raise a ValueError

The tokenizer uses some basic heuristics to determine the most likely split - number of syllables, presence of vowels, and syllable frequency data.

from py_pinyin_split import PinyinTokenizer

tokenizer = PinyinTokenizer()

# Basic splitting
tokenizer.tokenize("nǐhǎo")  # ['nǐ', 'hǎo']
tokenizer.tokenize("Běijīng")  # ['Běi', 'jīng']

# Handles whitespace and punctuation
tokenizer.tokenize("Nǐ hǎo ma?")  # ['Nǐ', 'hǎo', 'ma', '?']
tokenizer.tokenize("Wǒ hěn hǎo!")  # ['Wǒ', 'hěn', 'hǎo', '!']

# Handles ambiguous splits using heuristics
tokenizer.tokenize("kěnéng") == ["kě", "néng"]
tokenizer.tokenize("rènào") == ["rè", "nào"]
tokenizer.tokenize("xīan") == ["xī", "an"]
tokenizer.tokenize("xián") == ["xián"]
tokenizer.tokenize("wǎn'ān") == ["wǎn", "'", "ān"]

# Tone marks or punctuation help resolve ambiguity
tokenizer.tokenize("xīān")  # ['xī', 'ān']
tokenizer.tokenize("xián")  # ['xián']
tokenizer.tokenize("Xī'ān")  # ["Xī", "'", "ān"]

# Raises ValueError for invalid pinyin
tokenizer.tokenize("hello")  # ValueError

# Optional support for non-standard syllables
tokenizer = PinyinTokenizer(include_nonstandard=True)
tokenizer.tokenize("duang")  # ['duang']

Development

Use a current version of uv to install the locked development environment. The default development interpreter is Python 3.14; CI covers Python 3.8 through 3.14, plus macOS and Windows on Python 3.14. The lockfile selects newer dependencies where supported and retains compatible versions for older Python interpreters.

uv sync --locked
uv run --locked pytest
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked mypy src
uv build --no-sources

To update dependencies, run uv lock --upgrade and commit uv.lock along with any changes to pyproject.toml. Dependabot also checks Python dependencies and GitHub Actions weekly. Dependency resolution keeps a three-day delay before accepting new package releases.

Releases

Every push and pull request runs code checks and tests against the built wheel. Publishing only proceeds once these checks pass:

  • Default-branch pushes publish to TestPyPI, skipping versions already uploaded.
  • Tags matching the version in src/py_pinyin_split/__about__.py (with an optional v prefix) publish to PyPI and create a GitHub release with the distributions and Sigstore signatures.

Publishing uses the existing pypi and testpypi GitHub environments and PyPI trusted publishers configured for .github/workflows/publish.yml.

Metadata

Release files for py-pinyin-split 5.1.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 py-pinyin-split 5.1.0
File Size Uploaded
py_pinyin_split-5.1.0.tar.gz 111.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-pinyin-split 5.1.0
File Interpreter ABI Platform
py_pinyin_split-5.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 122.2 kB

Release files / py_pinyin_split-5.1.0.tar.gz

Download URL py_pinyin_split-5.1.0.tar.gz
Size 111.6 kB
Tags Source
SHA-256 checksum
How to use checksums
58b06061a8ccf38ceee4b3abf5ce5ec47cb4e572d8a2cbd4e80b138aa50a7806
BLAKE2b-256 checksum
How to use checksums
51065d274bb4ea80437f750a39279c8a65036699c38a43228b11547de7858357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 5, 2026.

Transparency log

Release files / py_pinyin_split-5.1.0-py3-none-any.whl

Download URL py_pinyin_split-5.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4021e5ce8aaccfbc695877fe3f120b9067b3184ac6425c4f3694569ad5da9b08
BLAKE2b-256 checksum
How to use checksums
ae285089e3e95236f19818f898c016ec0f9a8e4577624416c92dc047b2fdf922
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 5, 2026.

Transparency log

Release history Release notifications | RSS feed

6.0.0

2 release files

This release

5.1.0 This release

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.0.2

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

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