Skip to main content

BaiBao (百宝)

方便好用的 Python 常用功能库。把日常开发中反复用到的能力(日志、包管理、数据库、邮件、OCR)封装成简洁的 API,开箱即用。

PyPI


优势

  • 统一抽象,随时替换 — LLM、OCR、模板引擎均采用策略模式设计,共享同一抽象接口,运行时自由切换后端实现
  • 零配置依赖管理 — import_module() 首次导入时自动检测并安装缺失的包;pip 操作内置清华、阿里云等多镜像自动 fallback
  • 数据库双模支持 — 连接池模式(高并发/线程安全)与单连接模式(轻量级)自由切换,MySQL / PostgreSQL 驱动自动安装
  • 可扩展 CLI 框架 — 基于注册机制的命令行系统,支持命令缩写、帮助命令、线程安全,轻松添加自定义命令
  • 配置即代码 — 所有配置类均为 dataclass,支持从 JSON 一键加载,自动校验必填字段,拒绝运行时 TypeError
  • 邮件收发一体 — 支持纯文本、HTML 和附件,自动判断 SSL / STARTTLS 加密方式,抄送/密送/群发一应俱全

开始使用

安装

# 安装 baibao(使用清华镜像源加速)
pip install baibao -i https://pypi.tuna.tsinghua.edu.cn/simple/

OCR 引擎(可选)

baibao.ai.ocr 默认用 EasyOCR,也可切 PaddleOCR。PaddleOCR 封装会按已装版本自动选择 PaddleOcrV2(2.x API)或 PaddleOcrV3(3.x API),无需钉版本。两者依赖较重,按需装其一:

# EasyOCR(默认,多语言)—— baibao 命令默认引擎
python -m pip install easyocr opencv-python numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

# PaddleOCR(中文精度更高)—— 2.x / 3.x 均可,baibao 自动适配
python -m pip install paddlepaddle paddleocr opencv-python numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

PaddleOCR 在新版 Python(3.13)/ Windows 上有几个坑(torch 的 c10.dll、paddlepaddle 的 mkldnn PIR bug、3.0.0 与 PP-OCRv6 不兼容等),其中 mkldnn 的坑 baibao 已内置绕过。详见 AI 模块文档 — PaddleOCR 版本与已知坑。


模块概览

分类 模块 功能 文档
AI baibao.ai LLM 对话(OpenAI 兼容)、OCR 文字识别(EasyOCR/PaddleOCR) 文档
数据 baibao.data 货币查询、元数据定义(Field/Style) 文档
渲染 baibao.render HTML 报告片段(表格/图表/指标卡片)、模板引擎(Jinja2) 文档
数据库 baibao.db MySQL/PostgreSQL 连接池与查询 文档
消息 baibao.message 邮件发送(文本/HTML/附件) 文档
命令行 baibao.cli CLI 命令行工具(包管理、项目清理) 文档

开发指南

本地安装

# 开发模式(修改源码立刻生效,无需重新安装)
python -m pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple/

# 基础安装
python -m pip install . -i https://pypi.tuna.tsinghua.edu.cn/simple/

开发依赖

# 安装开发依赖(代码检查、测试等)
python -m pip install ".[dev]"

# 安装全部依赖
python -m pip install ".[all]"

代码质量

# 代码风格检查
python -m ruff check src/

# 类型检查
python -m mypy src/

# 运行测试
python -m pytest tests/

打包上传

# 清理 __pycache__ 缓存
python -m baibao py_clean .

# 构建源码包和 wheel 包
python -m build

# 构建结果
ls dist/

# 检查元数据
python -m twine check dist/*

# 上传到正式 PyPI
python -m twine upload dist/*

许可证

GPL-3.0-or-later


Metadata

Release files for baibao 0.0.4

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

Source distribution (sdist)

Source distribution for baibao 0.0.4
File Size Uploaded
baibao-0.0.4.tar.gz 83.8 kB Details

Built distribution (wheel)

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

Total release size: 189.5 kB

Release files / baibao-0.0.4.tar.gz

Download URL baibao-0.0.4.tar.gz
Size 83.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d3be7188c87df5a920cee09523181e5e2f15d732d90f5681c499e74313cb51c3
BLAKE2b-256 checksum
How to use checksums
04e428387de1b0a37b8ffd834c23db1a471b01b29f8667ccd6f0099b46cf28fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / baibao-0.0.4-py3-none-any.whl

Download URL baibao-0.0.4-py3-none-any.whl
Size 105.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44f6c97c065952916ad880eb5fa35ee3d41a5321e65f742ca935ddcf75f1bb89
BLAKE2b-256 checksum
How to use checksums
583a29ffe913c6bdbeba1f333fed8af19d0e226eec95d396fff6289a49663064
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release history Release notifications | RSS feed

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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