Skip to main content

Python 常用工具类库 - 提供日志、HTTP请求、文件操作、数据库、JWT认证等功能

Project description

PyPI version Python versions License Build Status

PyraUtils 是一个功能丰富的 Python 工具类库,提供了日志、HTTP请求、文件操作、数据库、JWT认证、企业微信API等常用功能的封装。

特性

  • 📝 日志模块 - 基于 loguru 和 logging 的统一日志处理

  • 🌐 HTTP请求 - 封装 httpx 和 requests,支持重试、超时、代理

  • 🔐 JWT认证 - JWT 令牌生成、验证、装饰器认证

  • 📁 文件操作 - 文件压缩解压、下载、同步

  • 🗄️ 数据库 - SQLAlchemy 和 SQLite3 封装

  • 📧 邮件发送 - SMTP 邮件发送封装

  • 🔒 密码处理 - 密码哈希、验证、强度测试

  • 📱 企业微信 - 企业微信 API 封装

  • 🔑 签名生成 - HMAC、Hash 签名生成

  • 🌍 网络工具 - IP地址、MAC地址、SSL证书处理

安装

使用 pip 安装:

pip install PyraUtils

或使用 pipenv:

pipenv install PyraUtils

快速开始

日志模块

from PyraUtils.log import LoguruHandler

# 创建日志处理器
logger = LoguruHandler()
log = logger.get_logger("myapp", "app.log")

log.info("这是一条信息日志")
log.warning("这是一条警告日志")
log.error("这是一条错误日志")

HTTP 请求

from PyraUtils.http import RequestUtils

# GET 请求
response = RequestUtils.get("https://api.example.com/data")
print(response.json())

# POST 请求
response = RequestUtils.post(
    "https://api.example.com/submit",
    json={"key": "value"}
)

JWT 认证

from PyraUtils.http import JWT

# 创建 JWT 实例
jwt = JWT(secret_key="your-secret-key")

# 生成令牌
token = jwt.jwt_encode({"user_id": 123, "username": "test"})

# 验证令牌
is_valid, result = jwt.jwt_decode(token)

文件操作

from PyraUtils.common import FileUtils, ZipFilesUtils

# 获取文件列表
files = FileUtils.get_listfile_01("./directory")

# 压缩文件
ZipFilesUtils.compress_file("source.txt", "archive.gz", "gz")

# 解压文件
ZipFilesUtils.extract_file("archive.gz", "./extract_dir")

数据库操作

from PyraUtils.db import SQLiteUtils

# 创建数据库连接
db = SQLiteUtils("database.db")

# 执行查询
results = db.execute_query("SELECT * FROM users WHERE id = ?", (1,))

企业微信

from PyraUtils.service.work_wechat import CorpApi

# 初始化 API
api = CorpApi(corpid="your_corp_id", corpsecret="your_secret")

# 获取用户信息
user_info = api.get_user("user_id")

模块列表

  • PyraUtils.log - 日志处理 (Loguru/Logging)

  • PyraUtils.http - HTTP请求、JWT认证、OAuth2

  • PyraUtils.common - 文件操作、下载、压缩、时间处理、字符串

  • PyraUtils.db - 数据库操作 (SQLAlchemy/SQLite)

  • PyraUtils.network - 网络工具 (IP/MAC/SSL)

  • PyraUtils.password - 密码处理、哈希验证

  • PyraUtils.service - 第三方服务集成 (企业微信)

  • PyraUtils.signature - 签名生成 (HMAC/Hash)

开发环境

克隆仓库并安装开发依赖:

git clone https://github.com/yourusername/PyraUtils.git
cd PyraUtils
pip install -e ".[dev]"

运行测试:

pytest

代码检查:

flake8 PyraUtils tests
black --check PyraUtils tests
isort --check-only PyraUtils tests

文档构建

安装文档依赖:

pip install -e ".[doc]"

构建文档:

cd docs
make html

贡献指南

欢迎贡献代码!请查看 CONTRIBUTING.rst 了解详情。

许可证

本项目采用 MIT 许可证,详见 LICENSE 文件。

更新日志

详见 ChangeLog.md

联系方式

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

pyrautils-0.9.36.tar.gz (103.1 kB view details)

Uploaded Source

Built Distribution

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

pyrautils-0.9.36-py2.py3-none-any.whl (87.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyrautils-0.9.36.tar.gz.

File metadata

  • Download URL: pyrautils-0.9.36.tar.gz
  • Upload date:
  • Size: 103.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pyrautils-0.9.36.tar.gz
Algorithm Hash digest
SHA256 058c4812a900f9e54ad32b2d6b430d3016268f0ae8e79b624838036793a9b920
MD5 c44c78e176431df8b9e5d525ac837e1d
BLAKE2b-256 5e8b319cf42692ddf936b8d9b28d881611601f222b09d5b0803fe42b50873319

See more details on using hashes here.

File details

Details for the file pyrautils-0.9.36-py2.py3-none-any.whl.

File metadata

  • Download URL: pyrautils-0.9.36-py2.py3-none-any.whl
  • Upload date:
  • Size: 87.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for pyrautils-0.9.36-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9a2a02b7a43dc51b58275bd45e2718306c51a50b1e77fef0340e25044ab7cf58
MD5 d360a83787715fdc28c88a5283f2236f
BLAKE2b-256 bebf96c3a3e170f44530748b894f5d99028578a892c47e69c0dd8227e66887d3

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