Skip to main content

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 Distributions

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

Built Distribution

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

bitool_core-0.1.15-cp38-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

File details

Details for the file bitool_core-0.1.15-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: bitool_core-0.1.15-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: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for bitool_core-0.1.15-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 af1bab92cbcebc380253bd2722adb7efb61c414354f80fb6421e1ccae307b78e
MD5 4400d10fa31aae58e13091a7b34198aa
BLAKE2b-256 6522337674437620a53126d6880acf47791380af1e632e774598b7c4e5c85fc2

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