Grand Honor Kit - 一个 Python 项目通用工具包,提供缓存、数据库、日志、消息通知等功能
Project description
ghkit
ghkit 是 "Grand Honor Kit" 的缩写,是一个 Python 项目通用工具包,提供了一系列常用的开发工具和功能模块。
功能特性
- 缓存系统:支持 Memory 和 Redis 缓存
- 数据库客户端:支持 MySQL 和 Redis
- 日志系统:基于 loguru 的通用日志模块
- 枚举工具:支持描述属性的增强枚举
- 消息通知:
- 飞书机器人(支持文本、富文本、图片、卡片等消息)
- 钉钉机器人(支持纯文本消息)
- 邮件发送
- FastAPI 基础支持
安装
使用 pip(推荐)
pip install ghkit
使用 uv
# 安装 uv(如果还没有安装)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 安装 ghkit
uv pip install ghkit
开发安装
使用 uv 进行开发安装:
# 克隆项目
git clone <repository-url>
cd ghkit
# 安装项目及开发依赖
uv sync
# 或者只安装测试依赖
uv sync --extra test
# 或者安装所有可选依赖(包括 demo 依赖)
uv sync --all-extras
项目结构
├── demo # 示例代码
├── docs # 文档
├── ghkit # 主要代码目录
│ ├── cache # 缓存模块
│ ├── database # 数据库客户端
│ ├── enum # 枚举工具
│ ├── fastapi # FastAPI 基础支持
│ ├── log # 日志系统
│ └── messenger # 消息通知
├── tests # 单元测试
├── CHANGELOG.md # 版本更新日志
├── LICENSE # 开源协议
├── README.md # 项目说明
├── pyproject.toml # 项目配置和依赖管理
└── uv.lock # uv 依赖锁定文件
版本历史
详细版本更新记录请查看 CHANGELOG.md
开发指南
运行测试
项目使用 pytest 作为测试框架。以下是运行测试的常用命令:
- 安装测试依赖(使用 uv):
uv sync --extra test
或者使用 pip:
pip install -e ".[test]"
- 运行所有测试:
pytest
- 运行测试并生成覆盖率报告:
pytest --cov=ghkit --cov-report=html
- 运行特定测试文件:
pytest tests/test_log.py
- 运行特定测试函数:
pytest tests/test_log.py::test_logger_creation
测试覆盖率报告
运行 pytest --cov=ghkit --cov-report=html 后:
- 在项目根目录生成
htmlcov目录 - 打开
htmlcov/index.html查看详细覆盖率报告 - 报告包含:
- 总体覆盖率
- 每个文件的覆盖率
- 每个函数的覆盖率
- 未覆盖的代码行
实用的 pytest 参数
-v: 显示详细信息-s: 显示打印输出-k "test_name": 只运行包含特定名称的测试-x: 遇到第一个失败就停止--pdb: 在测试失败时进入调试器
示例代码
查看 demo 目录获取更多使用示例:
- 枚举模块示例:
demo/enum/demo.py - FastAPI 示例:
demo/fastapi/demo.py - 飞书机器人示例:
demo/messenger/feishu/demo.py
贡献指南
欢迎提交 Issue 和 Pull Request 来帮助改进这个项目。
许可证
本项目采用 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
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 ghkit-0.0.5.tar.gz.
File metadata
- Download URL: ghkit-0.0.5.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0a36520a527f3347672e42c3198b1fbe7c3376ea81b85eb39064599c1fd922c
|
|
| MD5 |
55d97eec14faf3218e49a82d93bed699
|
|
| BLAKE2b-256 |
06f7954354812d69953ffbf962f6c7dea078efdfabd9f0fe6c9fe4bbe7df9c5a
|
Provenance
The following attestation bundles were made for ghkit-0.0.5.tar.gz:
Publisher:
publish.yml on chenxingyuu/ghkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghkit-0.0.5.tar.gz -
Subject digest:
f0a36520a527f3347672e42c3198b1fbe7c3376ea81b85eb39064599c1fd922c - Sigstore transparency entry: 686182256
- Sigstore integration time:
-
Permalink:
chenxingyuu/ghkit@06ed22a495d01f1a98f8e77bc0c0cba5ec0c7686 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/chenxingyuu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06ed22a495d01f1a98f8e77bc0c0cba5ec0c7686 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ghkit-0.0.5-py3-none-any.whl.
File metadata
- Download URL: ghkit-0.0.5-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b751315c020293908e49593faf9415077570fce21eb2a71e9f6088259d4d7569
|
|
| MD5 |
a144b3186c136c04e5527082fb4d6b54
|
|
| BLAKE2b-256 |
04fae99de231145d1d5faf233f6fa6ec5793f848dfaf806ebff79df43dee13e5
|
Provenance
The following attestation bundles were made for ghkit-0.0.5-py3-none-any.whl:
Publisher:
publish.yml on chenxingyuu/ghkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ghkit-0.0.5-py3-none-any.whl -
Subject digest:
b751315c020293908e49593faf9415077570fce21eb2a71e9f6088259d4d7569 - Sigstore transparency entry: 686182257
- Sigstore integration time:
-
Permalink:
chenxingyuu/ghkit@06ed22a495d01f1a98f8e77bc0c0cba5ec0c7686 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/chenxingyuu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@06ed22a495d01f1a98f8e77bc0c0cba5ec0c7686 -
Trigger Event:
release
-
Statement type: