Skip to main content

A Python extension module powered by Rust and PyO3, providing fast and accurate Chinese text conversion.

Project description

opencc_pyo3

PyPI version Build Status

opencc_pyo3 is a Python extension module powered by Rust and PyO3, providing fast and accurate conversion between different Chinese text variants using OpenCC algorithms.

Features

  • Convert between Simplified, Traditional, Hong Kong, Taiwan, and Japanese Kanji Chinese text.
  • Fast and memory-efficient, leveraging Rust's performance.
  • Easy-to-use Python API.
  • Supports punctuation conversion and automatic text code detection.

Supported Conversion Configurations

  • s2t, t2s, s2tw, tw2s, s2twp, tw2sp, s2hk, hk2s, t2tw, tw2t, t2twp, tw2tp, t2hk, hk2t, t2jp, jp2t

Installation

Build and install the Python wheel using maturin:

# In project root
maturin build --release
pip install ./target/wheels/opencc_pyo3-<version>-cp<pyver>-abi3-<platform>.whl

Or for development:

maturin develop -r

See build.txt for detailed build and install instructions.

Usage

Python

from opencc_pyo3 import OpenCC

text = "春眠不觉晓,处处闻啼鸟。"
opencc = OpenCC("s2t")
converted = opencc.convert(text, punctuation=True)
print(converted)

CLI

You can also use the CLI interface:

python -m opencc_pyo3 -i input.txt -o output.txt -c s2t --punct

API

Class: OpenCC

  • OpenCC(config: str = "s2t")
    • config: Conversion configuration (see above).
  • convert(input: str, punctuation: bool = False) -> str
    • Convert text with optional punctuation conversion.
  • zho_check(input: str) -> int
    • Detects the code of the input text.

Development

License

MIT


Powered by Rust, PyO3, and OpenCC.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

opencc_pyo3-0.6.1-cp38-abi3-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.8+Windows x86-64

opencc_pyo3-0.6.1-cp38-abi3-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

opencc_pyo3-0.6.1-cp38-abi3-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file opencc_pyo3-0.6.1-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for opencc_pyo3-0.6.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3b03f17db9129b1c878028e91f424143799be1f79475c22f3c41928156986c5b
MD5 1ee2a84e6e4b4c8afc0a50a989ef157a
BLAKE2b-256 198ae120e9d8925ad06f92f70e2a5887f9f7ebdc3ee5faf4ce833195910cfa21

See more details on using hashes here.

File details

Details for the file opencc_pyo3-0.6.1-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for opencc_pyo3-0.6.1-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a347d04ac3ae7f554e35bae2b3228f3bb291270c8e6dd05fc38a06a8eb9a8f27
MD5 56eae5f3da2481a9c02c63c74058606b
BLAKE2b-256 e0dd19320f49fb7ffc42ec813124a9e6b85a8ca521aadcddf71f08174a109e91

See more details on using hashes here.

File details

Details for the file opencc_pyo3-0.6.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc_pyo3-0.6.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 81eec36e0ff5ea038a7668cdda8623ef66309896ec5fd1b373f9e32ee32406da
MD5 1fec148226dfe499b909ad5f024011c6
BLAKE2b-256 c17fa8ed108b8e470417db505e707db2ac37cb8b98756963b98315c9b446a43c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page