skillfed

xpinyin

Translate Chinese hanzi to pinyin (拼音) by Python, 汉字转拼音

xpinyin v0.7.7 73.6K downloads/30d#14,955 on PyPI831
Permissive license MIT AGING released

What it is and what it does

xpinyin is a Python library that translates Chinese characters into pinyin (the standard romanization system for Mandarin). It provides methods to extract the full phonetic spelling of characters, their initial consonants, and tone information in multiple formats—tone marks, tone numbers, or unmarked. The library also supports generating all possible pinyin combinations for characters with multiple readings, which is useful for disambiguation in mixed-reading contexts.

The package has no external dependencies and installs cleanly on modern Python versions. It's designed for developers building Chinese text processing pipelines, search systems, or applications that need to work with phonetic representations of Chinese text. The API is straightforward: instantiate a Pinyin object and call methods like get_pinyin(), get_initial(), or get_initials() with optional parameters to control output format.

Use it for:

  • Building search indexes that allow users to find Chinese text by typing pinyin instead of characters
  • Generating phonetic guides or furigana-style annotations for Chinese text in educational applications
  • Implementing text-to-speech systems that need to convert hanzi to romanized pronunciation
  • Sorting or organizing Chinese text alphabetically by pinyin for catalogs or directories
  • Disambiguating characters with multiple pronunciations in natural language processing pipelines

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts Chinese characters (hanzi) to their phonetic romanization (pinyin), with support for tone marks, initial consonants, and multiple character readings.

Yes, if you need reliable Chinese-to-pinyin conversion. The package is stable, dependency-free, and covers the core use cases well. The aging maintenance status (438 days since last release) is not a blocker—the code is mature and the repository remains active—but monitor it if you depend on ongoing feature development or rapid bug fixes.

Install

xpinyin on PyPI

pip

pip install xpinyin

uv

uv add xpinyin

poetry

poetry add xpinyin

Installing xpinyin

Before you install

Low friction installation with no runtime dependencies. Maintenance is aging—last release was 438 days ago—but the repository remains active with recent commits and the package has been stable since its 2011 inception.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and commercial projects.

Quickstart

pip install xpinyin

from xpinyin import Pinyin
p = Pinyin()
p.get_pinyin("上海")
# Returns: 'shang-hai'
p.get_pinyin("上海", tone_marks='marks')
# Returns: 'shàng-hǎi'

Verify before relying

  • Whether the package handles simplified vs. traditional Chinese character variants consistently
  • Performance characteristics when processing large documents or streams of text
  • Completeness of the pinyin database for rare or archaic characters

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 438 days since the last release
Last repo commit
First released
Downloads 73,649/month — #14,955 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: xpinyin-0.7.7-py3-none-any.whl

Keywords: pinyin

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.0Programming Language :: Python :: 3.1Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.2Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

chinese hanzi to pinyin conversionpinyin romanization librarychinese character phonetictone marks and initialschinese text processinghanzi romanizationpinyin with tone numbers
chinese-nlpromanizationtext-processing

More Python Modules packages