Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Translate chinese chars to pinyin based on Mandarin.dat

Project description

Translate chinese chars to pinyin based on Mandarin.dat


$ pip install pinyin


>>> import pinyin
>>> print pinyin.get('你 好')

>>> print pinyin.get('你好', format="strip", delimiter=" ")
ni hao

>>> print pinyin.get('你好', format="numerical")

>>> print pinyin.get_initial('你好')
n h


format must be one of: numerical/diacritical/strip

Prototype Chinese->English

>>> import pinyin.cedict
>>> pinyin.cedict.translate_word('你')
['you (informal, as opposed to courteous 您[nin2])']
>>> pinyin.cedict.translate_word('你好')
['Hello!', 'Hi!', 'How are you?']
>>> list(pinyin.cedict.all_phrase_translations('你好'))
[['你', ['you (informal, as opposed to courteous 您[nin2])']], ['你好', ['Hello!', 'Hi!', 'How are you?']], ['好', ['to be fond of', 'to have a tendency to', 'to be prone to']]]

Note that this is a prototype, and only functions from Python 3.


pinyin is free software, under an MIT-style license. See LICENSE for details.

The data file for translations is the CC-BY-SA 3.0.

The translations are from the CC-CE-DICT project (, by Denisowski, Peterson, Brelsford, and others.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pinyin, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size pinyin-0.4.0.tar.gz (3.6 MB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page