A Python extension module powered by Rust and PyO3, providing fast and accurate Chinese text conversion.
Project description
opencc_pyo3
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
- Rust source: src/lib.rs
- Python bindings: opencc_pyo3/init.py, opencc_pyo3/opencc_pyo3.pyi
- CLI: opencc_pyo3/main.py
License
Powered by Rust, PyO3, and OpenCC.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opencc_pyo3-0.6.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: opencc_pyo3-0.6.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b03f17db9129b1c878028e91f424143799be1f79475c22f3c41928156986c5b
|
|
| MD5 |
1ee2a84e6e4b4c8afc0a50a989ef157a
|
|
| BLAKE2b-256 |
198ae120e9d8925ad06f92f70e2a5887f9f7ebdc3ee5faf4ce833195910cfa21
|
File details
Details for the file opencc_pyo3-0.6.1-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: opencc_pyo3-0.6.1-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a347d04ac3ae7f554e35bae2b3228f3bb291270c8e6dd05fc38a06a8eb9a8f27
|
|
| MD5 |
56eae5f3da2481a9c02c63c74058606b
|
|
| BLAKE2b-256 |
e0dd19320f49fb7ffc42ec813124a9e6b85a8ca521aadcddf71f08174a109e91
|
File details
Details for the file opencc_pyo3-0.6.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: opencc_pyo3-0.6.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81eec36e0ff5ea038a7668cdda8623ef66309896ec5fd1b373f9e32ee32406da
|
|
| MD5 |
1fec148226dfe499b909ad5f024011c6
|
|
| BLAKE2b-256 |
c17fa8ed108b8e470417db505e707db2ac37cb8b98756963b98315c9b446a43c
|