python-pinyin (pypinyin) converts Chinese characters to phonetic pinyin for notation, sorting, and search. It handles heteronyms and multiple romanization styles.
Overview
pypinyin turns hanzi strings into tone-marked or style-specific pinyin representations in Python. It can match phrases intelligently, expose lazy pinyin without tone, and support Bopomofo, Wade-Giles, and other style enums.
The package supports Python 2.7 through 3.15 per project metadata, installs via pip or uv, and ships a console helper for quick transliteration. Options cover neutral tone marking, ü versus v, and tone sandhi rules.
Documentation on Read the Docs explains customization for unrecognized characters, dictionaries for improved accuracy, and integration patterns. It derives from earlier hotoo/pinyin ideas and remains MIT licensed.
Consumers embed it in search engines, input method tooling, education apps, and data pipelines that need consistent romanization.
Key features
- Phrase-aware pinyin mapping
- Heteronym support
- Multiple romanization styles
- Tone and lazy pinyin modes
- Traditional and variant handling
- CLI transliteration command
- pip and uv install
- Configurable unknown-character policy
Use cases
- Hanzi sorting and indexing
- Name or address romanization
- Language learning tooling
- Search normalization pipelines