Bitool-Core - Rust core for Bitool
Project description
Bitool-core
Bitool 的 Rust 核心模块,通过 PyO3 + Maturin 将高性能 Rust 实现暴露为 Python 可调用的扩展模块。
定位
Bitool 采用 Rust + Python 混合架构,bitool-core 负责处理性能关键路径上的计算密集型任务:
| 模块 | 功能 | 关键依赖 |
|---|---|---|
file_ops |
文件扫描、目录遍历、文件操作 | walkdir, rayon |
text_proc |
正则搜索、文本处理 | regex, rayon |
pdf_ops |
PDF 合并、拆分、压缩、页面转图片 | lopdf, pdfium-render, image |
crypto |
AES 加密/解密、SHA2 哈希 | aes, sha2 |
cmd_exec |
外部命令执行 | tokio |
profiler |
高精度性能分析 | chrono |
config |
全局配置管理 | serde, serde_json, dirs |
安装
作为 Bitool 的一部分安装
pip install bitool
开发模式安装
cd bitool-core
maturin develop
构建发布包
cd bitool-core
maturin build -r
Python API
安装后通过 import bitool_core 即可使用所有 Rust 实现的功能:
配置管理
import bitool_core
# 全局配置
config = bitool_core.PyBitoolConfig()
config.get("key", "default_value")
# 工作区配置
ws_config = bitool_core.PyWorkspaceConfig()
ws_config.workspace_path = "/path/to/project"
文件操作
import bitool_core
ops = bitool_core.PyFileOps()
# 扫描目录
files = ops.scan_directory("/path/to/dir")
# 文件读写
content = ops.read_file("input.txt")
ops.write_file("output.txt", content)
# 文件复制/移动/删除
ops.copy_file("src.txt", "dst.txt")
ops.move_file("old.txt", "new.txt")
ops.delete_file("temp.txt")
文本处理
import bitool_core
processor = bitool_core.PyTextProcessor()
# 正则搜索
results = processor.regex_search(r"\d{4}-\d{2}-\d{2}", text)
# 文本替换
new_text = processor.regex_replace(pattern, replacement, text)
# 批量处理(利用 rayon 并行加速)
results = processor.batch_search(patterns, texts)
PDF 操作
import bitool_core
pdf = bitool_core.PyPdfOps()
# 合并 PDF
pdf.merge_pdfs(["part1.pdf", "part2.pdf"], "merged.pdf")
# 拆分 PDF
pdf.split_pdf("input.pdf", "output_dir", pages_per_split=10)
# 压缩 PDF
pdf.compress_pdf("large.pdf", "small.pdf")
# PDF 转图片
images = pdf.to_images("document.pdf", dpi=150, format="png")
加密功能
import bitool_core
# AES 加密/解密
encrypted = bitool_core.encrypt(data, key)
decrypted = bitool_core.decrypt(encrypted, key)
# SHA2 哈希
hash_value = bitool_core.sha256(data)
命令执行
import bitool_core
executor = bitool_core.PyCommandExecutor()
# 执行外部命令
result = executor.run("git status")
print(result.stdout)
print(result.return_code)
# 异步执行(基于 tokio)
result = executor.run_async("long_running_command")
性能分析
import bitool_core
profiler = bitool_core.PyPerformanceProfiler()
# 计时
profiler.start("task_name")
# ... 执行任务 ...
record = profiler.stop("task_name")
print(f"耗时: {record.elapsed_ms:.2f} ms")
# 获取所有记录
all_records = profiler.records
项目结构
bitool-core/
├── src/
│ ├── lib.rs # 库入口,注册所有 PyO3 模块
│ ├── core/ # Rust 核心实现
│ │ ├── mod.rs # 模块聚合
│ │ ├── cmd_exec.rs # 外部命令执行(tokio 异步)
│ │ ├── config.rs # 配置管理(serde 序列化)
│ │ ├── crypto.rs # 加密功能(AES-256 / SHA2)
│ │ ├── file_ops.rs # 文件操作(rayon 并行)
│ │ ├── pdf_ops.rs # PDF 处理(lopdf / pdfium-render)
│ │ ├── profiler.rs # 高精度性能分析
│ │ └── text_proc.rs # 文本处理(regex / rayon)
│ ├── plugins/ # 插件系统
│ │ ├── mod.rs # 插件框架
│ │ ├── loader.rs # 动态插件加载
│ │ └── registry.rs # 插件注册表
│ └── python/ # PyO3 Python 绑定
│ ├── mod.rs # 绑定聚合
│ ├── py_cmd_exec.rs # 命令执行器绑定
│ ├── py_config.rs # 配置管理绑定
│ ├── py_file_ops.rs # 文件操作绑定
│ ├── py_pdf_ops.rs # PDF 操作绑定
│ ├── py_profiler.rs # 性能分析器绑定
│ └── py_text_proc.rs # 文本处理器绑定
├── .cargo/
│ └── libs/ # 链接库
├── Cargo.toml # Rust 依赖配置
└── pyproject.toml # Maturin 构建配置
技术栈
| 组件 | 技术 | 用途 |
|---|---|---|
| Python 绑定 | PyO3 0.28 | Rust ↔ Python FFI |
| 构建工具 | Maturin | Rust Python 包构建 |
| 并行计算 | Rayon | 数据并行处理 |
| 异步运行时 | Tokio | 异步命令执行 |
| 正则引擎 | regex | 高性能正则匹配 |
| 序列化 | serde + serde_json | JSON 配置序列化 |
| 加密 | aes + sha2 | AES-256 加密 / SHA2 哈希 |
| PDF 处理 | lopdf + pdfium-render | PDF 读写与渲染 |
| 图像处理 | image | 图像编解码 |
| 目录遍历 | walkdir | 递归目录扫描 |
许可证
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bitool_core-0.1.9.tar.gz
(915.9 kB
view details)
Built Distribution
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 bitool_core-0.1.9.tar.gz.
File metadata
- Download URL: bitool_core-0.1.9.tar.gz
- Upload date:
- Size: 915.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd6a7b4dbe73562feda2b18ddb348bfaedc162ee863c0015c0b50f3be2d13d81
|
|
| MD5 |
29ce2653ca0091a0e2ad13a4c38e9259
|
|
| BLAKE2b-256 |
8609ec75de01ecb1e5be32ca960eabf8f3c1d620167d7846d6802f7bceaff3f3
|
File details
Details for the file bitool_core-0.1.9-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: bitool_core-0.1.9-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39c8b915dd68ce15f7bbd19ffabcacea95ca43fabfb36a7af76b88c2016b774a
|
|
| MD5 |
5021ac74d3649257d754562202149b1f
|
|
| BLAKE2b-256 |
3574baba50ec7b1f484d1c1b74b4e37085853324bcfdd52a1ef09bea3e19aebf
|