Welcome to chinese_to_english_punctuation Documentation
chinese_to_english_punctuation rewrites Chinese full-width punctuation into its English half-width equivalent, and fixes the spacing around it. Documents written by Chinese speakers about technical topics almost always end up mixing the two: the narrative uses ,。:;?!()【】《》“” while the technical terms stay in English. That mix reads poorly in Markdown and reStructuredText, and it breaks tooling that expects ASCII punctuation. This library converts , to ,, 。 to ., () to (), 【】 and [] to [], 《》 and 〈〉 to <> and so on, inserts the single space that belongs between a Chinese character and an adjacent Latin word or number, and leaves everything else alone.
The conversion is line-oriented and deliberately conservative about structure. Leading indentation is preserved verbatim, so nested list continuations survive untouched. Code-like blocks are recognized and handled in a format-preserving mode that only swaps the marks (plus one space after a comma, period and the like when it runs straight into text) and leaves the rest of the whitespace alone: Markdown fenced code (including Mermaid diagrams), $$ math, HTML blocks and YAML front matter, and reStructuredText .. code-block-style directives (also inside list-table cells) and :: literal blocks. reStructuredText grid and simple tables rely on column alignment and are left exactly as they are. Inline code spans are treated the same way as code blocks, and Markdown link targets and bare URLs are left alone. Pass skip_code=True (--skip_code on the command line) to leave code blocks and inline code completely untouched instead. Runs of two or three identical marks (。。。, ???, !!!) are treated as a single unit rather than being split apart. Spaces that would otherwise be introduced just inside paired Markdown markers such as **bold** are cleaned up afterwards.
The public Python API is a single function, process, which takes text and returns text. The same behavior is available from the command line through c2ep, which offers c2ep text for reading from --text or stdin and writing to stdout, and c2ep file for rewriting a UTF-8 file in place. Files that are not valid UTF-8 are rejected rather than guessed at, and --dry_run reports what would change without touching anything.
Usage:
from chinese_to_english_punctuation.api import process
process("这是Python代码,它使用Flask框架。")
# '这是 Python 代码, 它使用 Flask 框架.'
$ c2ep text --text "这是Python代码,它使用Flask框架。"
这是 Python 代码, 它使用 Flask 框架.
$ c2ep file --path ./README.md --dry_run
./README.md: 12 line(s) would change (dry run, nothing written)
$ c2ep file --path ./README.md
./README.md: 12 line(s) changed
Install
chinese_to_english_punctuation is released on PyPI, so all you need is to:
$ pip install chinese-to-english-punctuation
To upgrade to latest version:
$ pip install --upgrade chinese-to-english-punctuation
Metadata
Release files for chinese_to_english_punctuation 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chinese_to_english_punctuation-0.1.3.tar.gz | 31.6 kB | Without provenance | Details for chinese_to_english_punctuation-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chinese_to_english_punctuation-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for chinese_to_english_punctuation-0.1.3-py3-none-any.whl |
Total release size: 54.6 kB
Release files / chinese_to_english_punctuation-0.1.3.tar.gz
| Download URL | chinese_to_english_punctuation-0.1.3.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a0714b9d016e9247ac848a17e2446ec44d726708fcc00ed453a2f37b9b671f3
|
|
BLAKE2b-256 checksum How to use checksums |
11fa4d288215a257bd3deedb08d45e3a41fdae98baacd51e27d0a66d0506eca2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / chinese_to_english_punctuation-0.1.3-py3-none-any.whl
| Download URL | chinese_to_english_punctuation-0.1.3-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cec74d414e0f41bb9ca4c04414f2004181d7360052372228281c48f37ff58637
|
|
BLAKE2b-256 checksum How to use checksums |
6ad1a2fb41fbfa0702f6d83fb0d512cad628220540b08d97a602994bfa8a8f1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for chinese_to_english_punctuation 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.