Skip to main content

txtkit

轻量中文文本处理小工具,纯标准库实现,无第三方依赖。

功能

函数 说明
count_chars(text) 统计汉字 / 字母 / 数字 / 空白 / 其他字符数量
word_freq(text, top=5, min_len=1) 统计词频,按次数降序
clean(text, lower, remove_punct, squeeze_space) 清洗文本:转小写、去标点、压缩空白
dedup_lines(text, keep_blank=False) 按行去重,保留首次出现顺序
text_width(text) 按显示宽度计算长度(全角算 2)
truncate(text, width=20, suffix="…") 按显示宽度截断并加省略符

安装

pip install txtkit

从源码安装:

pip install .

使用

from txtkit import count_chars, word_freq, clean, truncate

# 字符统计
print(count_chars("Python 很好用!2026"))
# {'total': 15, 'hanzi': 3, 'letters': 6, 'digits': 4, 'spaces': 1, 'others': 1}

# 词频
print(word_freq("我爱 Python 我爱 编程", top=2))
# [('我爱', 2), ('python', 1)]

# 清洗
print(clean("  你 好 \t 世界  ! ", remove_punct=True))
# 你 好 世界

# 按显示宽度截断(列对齐时常需要)
print(truncate("中华人民共和国万岁", 10))
# 中华人民…

自测

python tests/test_txttool.py

许可证

MIT License,详见 LICENSE。

Metadata

Release files for txtkit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for txtkit 0.1.0
File Size Uploaded Provenance Actions
txtkit-0.1.0.tar.gz 6.1 kB Without provenance Details for txtkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for txtkit 0.1.0
File Interpreter ABI Platform Actions
txtkit-0.1.0-py3-none-any.whl Python 3 none any Details for txtkit-0.1.0-py3-none-any.whl

Total release size: 12.3 kB

Release files / txtkit-0.1.0.tar.gz

Download URL txtkit-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fe3538be56379f3a1ec84ce816932240d2559e902de8f889d640b6b5f4d7dede
BLAKE2b-256 checksum
How to use checksums
1a0c07b57c7c85772377c7fedeaf6aa7e6430c4dca34fc089416dbb84a244e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / txtkit-0.1.0-py3-none-any.whl

Download URL txtkit-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67265b676e58e31c8b2dd242ff0336ddfb3e3c8d4e82fe780c7b555f58df351a
BLAKE2b-256 checksum
How to use checksums
b64e91f94261076efe8a15ec28045cd143cf11220f6b4b7cb4da79e1f5373de4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for txtkit 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page