Skip to main content

Bitool - Rust + Python 混合架构工具集

Project description

Bitool

基于 Maturin 的 Rust + Python 混合架构工具集,将性能瓶颈和共性部分使用 Rust 实现,接口和逻辑部分使用 Python 实现。

特性

  • 高性能:核心计算和 I/O 操作使用 Rust 实现(文件操作、文本处理、PDF 处理、加密等)
  • 易用性:Python 提供简洁的 API 接口和 CLI 工具
  • 可扩展:命令模式 + 技能注册表,支持功能扩展
  • 跨平台:支持 Windows、Linux、macOS
  • 双模式:CLI 和 GUI 双模式,满足不同使用场景

安装

pip install bitool

安装 GUI 应用需额外安装可选依赖:pip install bitool[app]

应用一览

Bitool 内置 16 个独立应用,覆盖文件处理、文档工具、多媒体、LLM 等领域:

应用 命令 说明 模式
数字闹钟 alarmclk 桌面数字闹钟,支持贪睡延时 GUI
Word 文档比较 docdiff 比较两个 Word 文档差异,生成修订版 CLI
文件扫描器 filescanw 多格式文件内容扫描(PDF/DOCX/XLSX/PPTX 等) GUI
图像转 ICO img2ico / img2icow 将图像转换为多尺寸 ICO 图标 CLI/GUI
图像转 PDF img2pdfw 将目录中的图像合并为单个 PDF GUI
LLM 聊天客户端 llmcliw 本地大语言模型图形界面聊天客户端 GUI
GGUF 模型量化 llmqntw 将 LLM 模型量化转换为 GGUF 格式 GUI
LLM 推理服务器 llmsvrw 本地 LLM 模型推理 HTTP 服务 GUI
LSC 曲线优化 lscopt / lscoptw 最小二乘曲线拟合优化工具 CLI/GUI
PDF 加密解密 pdfcrypt 批量 PDF 加密/解密(128 位加密) CLI
PDF 拆分 pdfsplit 按份数/页数/页码范围拆分 PDF CLI
通用答题系统 quizbasew 多题型答题系统,支持自适应学习 GUI
在线答题训练 quiztrainer 基于 Web 的答题训练平台(Flask) Web
视频格式转换 videoconv / videoconvw 基于 FFmpeg 的视频格式转换 CLI/GUI
ZIP 加密 zipenc 批量加密为密码保护 ZIP(AES256) CLI
RimWorld Mod 管理 rimmodw RimWorld 游戏 Mod 启用/禁用/排序管理 GUI

Skills 工具集

Bitool 提供 20+ 个 CLI 技能工具,覆盖开发工作流的各个环节:

环境配置

命令 说明
envpy 一键配置 pip/UV/Conda 国内镜像源(清华/阿里云)
envrs 一键配置 Rustup/Cargo 国内镜像源并安装 Rust

构建与打包

命令 说明
pymake 替代 Makefile 的构建工具,支持 Python+Rust 双包构建、测试、发布
pypack Python 项目完整打包工具(嵌入式 Python + 依赖 + 加载器)
pyembedinstall 下载安装嵌入式 Python
pylibpack 项目依赖库下载与打包
pysourcepack 源代码打包
pyloadergen C 语言加载器生成与编译
pyarchive 多格式归档(zip/tar/7z)

版本与 Git

命令 说明
bumpversion 语义化版本号自动递增(patch/minor/major),支持 Git 标签和提交
gitt Git 仓库常用操作封装(init/add/commit/push/pull/clean)

包管理

命令 说明
pipt pip 操作封装,支持在线/离线模式和通配符卸载

文件处理

命令 说明
img2pdf 多图片合并为 PDF(CLI 版)
pdf2img PDF 逐页转换为图片
filedate 移除文件日期前缀,替换为实际创建/修改时间
filelevel 文件等级后缀重命名(公开/内部/机密/绝密)

系统工具

命令 说明
which (wch) 跨平台命令路径查找,支持模糊匹配
taskk 跨平台进程查找与终止,支持模糊匹配
cls 跨平台控制台清屏
sshcopyid SSH 公钥自动部署到远程服务器

开发

快速开始(推荐)

# 安装开发环境(自动构建 Rust + Python 双包)
pymake ia

# 验证安装
pymake t

常用命令

# 构建所有包(Rust + Python)
pymake ba

# 代码格式化与检查
pymake lint

# 运行测试
pymake t

# 清理所有构建产物
pymake ca

# 查看完整帮助
pymake help

手动构建(可选)

# 构建 Rust 核心模块
cd bitool-core && maturin develop

# 构建 Python 主包
cd .. && pip install -e .

# 构建发布包
cd bitool-core && maturin build -r
cd .. && python -m build

项目结构

bitool/
├── bitool-core/                # Rust 核心模块(PyO3 + Maturin)
│   ├── src/
│   │   ├── core/               #   Rust 核心功能
│   │   │   ├── cmd_exec.rs     #     命令执行
│   │   │   ├── config.rs       #     配置管理
│   │   │   ├── crypto.rs       #     加密功能(AES/SHA2)
│   │   │   ├── file_ops.rs     #     文件操作
│   │   │   ├── pdf_ops.rs      #     PDF 处理
│   │   │   ├── profiler.rs     #     性能分析
│   │   │   └── text_proc.rs    #     文本处理(正则/搜索)
│   │   ├── plugins/            #   插件系统
│   │   └── python/             #   PyO3 Python 绑定
│   ├── Cargo.toml
│   └── pyproject.toml
├── src/
│   └── bitool/                 # Python 主包(src layout)
│       ├── apps/               #   独立应用程序(16 个)
│       ├── cmd/                #   命令系统(命令模式)
│       ├── core/               #   核心基础设施
│       │   ├── config.py       #     JSON 配置管理
│       │   ├── database.py     #     数据库连接池
│       │   ├── env.py          #     环境变量管理
│       │   ├── logger.py       #     日志系统
│       │   ├── registry.py     #     注册表模式
│       │   ├── statemachine.py #     状态机
│       │   └── url.py          #     URL 工具
│       ├── gui/                #   GUI 基础设施(PySide)
│       ├── skills/             #   CLI 技能工具集(20+ 个)
│       ├── utils/              #   通用工具(执行器/文件/分析器)
│       ├── consts.py           #   平台/架构常量
│       └── types.py            #   通用类型定义
├── tests/                      # 测试代码
├── pyproject.toml              # Python 包配置
└── README.md

架构设计

Bitool 采用分层架构和 Rust+Python 混合设计:

┌─────────────────────────────────────────┐
│           Skills(技能层)               │  面向用户的 CLI 工具
│     BaseSkill / MultiCommandSkill       │  编排多个 Command
├─────────────────────────────────────────┤
│           Cmd(命令层)                  │  原子操作单元
│     BaseCommand + 条件守卫 + 依赖管理     │  Command Pattern
├─────────────────────────────────────────┤
│           Core(核心层)                 │  基础设施服务
│  配置 / 数据库 / 日志 / 注册表 / 状态机    │
├─────────────────────────────────────────┤
│  Python Utils  │  Rust Core (PyO3)      │  工具层
│  执行器/文件    │  文件/文本/PDF/加密/分析  │  性能关键路径
└─────────────────────────────────────────┘

核心设计模式:

  • 命令模式BaseCommand 封装原子操作,支持条件守卫(allow/forbid)和依赖管理
  • 模板方法模式BaseSkill.run() 定义固定执行流程,子类通过 add_argumentscreate_scheduler 定制行为
  • 注册表模式Registry / SkillRegistry 管理可扩展组件
  • 混合架构:Rust 处理计算密集型任务(文件 I/O、文本处理、PDF、加密),Python 负责编排和用户交互

Python API 示例

from bitool import CommandScheduler, Constants, profile

# 获取平台信息
print(Constants.IS_WINDOWS)  # True/False
print(Constants.ARCH)        # 'amd64' / 'arm64'

# 使用性能分析装饰器
@profile
def heavy_task():
    ...

# 使用命令调度器编排操作
from bitool.cmd import (
    CommandScheduler, ReadFileCommand, WriteFileCommand,
    MergePdfsCommand, RunCommand
)
scheduler = CommandScheduler()
scheduler.add(ReadFileCommand(path="input.txt"))
scheduler.add(RunCommand(cmd="python process.py"))
scheduler.run()

Rust 核心 API

import bitool_core

# 文件操作
file_ops = bitool_core.PyFileOps()
files = file_ops.scan_directory("/path/to/dir")

# 文本处理
processor = bitool_core.PyTextProcessor()
result = processor.regex_search(pattern, text)

# PDF 操作
pdf_ops = bitool_core.PyPdfOps()
pdf_ops.merge_pdfs(["a.pdf", "b.pdf"], "merged.pdf")

# 性能分析
profiler = bitool_core.PyPerformanceProfiler()
profiler.start("task_name")
# ... 执行任务 ...
record = profiler.stop("task_name")
print(record.elapsed_ms)

许可证

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-0.1.12.tar.gz (933.9 kB view details)

Uploaded Source

Built Distribution

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

bitool-0.1.12-py3-none-any.whl (928.4 kB view details)

Uploaded Python 3

File details

Details for the file bitool-0.1.12.tar.gz.

File metadata

  • Download URL: bitool-0.1.12.tar.gz
  • Upload date:
  • Size: 933.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.11 HTTPX/0.28.1

File hashes

Hashes for bitool-0.1.12.tar.gz
Algorithm Hash digest
SHA256 f16c2def8c86aa2c624ae5404335829e57bcbd7960941f5bebbcb8834b15bfb6
MD5 327a7574db397d570e0892e3c76647a8
BLAKE2b-256 c2e522401b5298d9fdd8b92e43a9183511d696cac10663b1f9bc115177dd0fe9

See more details on using hashes here.

File details

Details for the file bitool-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: bitool-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 928.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.12.11 HTTPX/0.28.1

File hashes

Hashes for bitool-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 f09292939391f185927aae284e645f0df7777df92896e4aec97430ef72339f7a
MD5 edc72526126d576a21c1da9d793a59b7
BLAKE2b-256 3875030fac0e890e5f9af2341dd10d7f1829f146198c35240ff005ae45db307a

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