Skip to main content

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 作为测试框架。以下是运行测试的常用命令:

  1. 安装测试依赖(使用 uv):
uv sync --extra test

或者使用 pip:

pip install -e ".[test]"
  1. 运行所有测试:
pytest
  1. 运行测试并生成覆盖率报告:
pytest --cov=ghkit --cov-report=html
  1. 运行特定测试文件:
pytest tests/test_log.py
  1. 运行特定测试函数:
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 文件。

Metadata

Release files for ghkit 0.0.6

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

Source distribution (sdist)

Source distribution for ghkit 0.0.6
File Size Uploaded Provenance Actions
ghkit-0.0.6.tar.gz 23.7 kB With provenance Details for ghkit-0.0.6.tar.gz

Built distribution (wheel)

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

Total release size: 52.3 kB

Release files / ghkit-0.0.6.tar.gz

Download URL ghkit-0.0.6.tar.gz
Size 23.7 kB
Tags Source
SHA-256 checksum
How to use checksums
154e11c36fdf285ac6bb0f4393c97fcea0c4a5028a2b6dedc693ff3374cd7828
BLAKE2b-256 checksum
How to use checksums
ba85321598b5695517908966673a035ef63c58c30aee3bbd49dca657cd1a638e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2025.

Transparency log

Release files / ghkit-0.0.6-py3-none-any.whl

Download URL ghkit-0.0.6-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0263167f9c8777c30c3932cc80deb98c4924edd1ce91df7780d4137b0a81f5d
BLAKE2b-256 checksum
How to use checksums
de8f25f16330fc3ff07fa8b27ec1ea3e9c54d7a3cb42dfd0ca90b32f5019789c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2025.

Transparency log

Security for ghkit 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ghkit-0.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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