Python 常用工具类库 - 提供日志、HTTP请求、文件操作、数据库、JWT认证等功能
Project description
PyraUtils
|PyPI version| |Python versions| |License| |Build Status|
.. |PyPI version| image:: https://img.shields.io/pypi/v/PyraUtils.svg :target: https://pypi.org/project/PyraUtils/ .. |Python versions| image:: https://img.shields.io/pypi/pyversions/PyraUtils.svg :target: https://pypi.org/project/PyraUtils/ .. |License| image:: https://img.shields.io/pypi/l/PyraUtils.svg :target: https://github.com/yourusername/PyraUtils/blob/main/LICENSE .. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/yourusername/PyraUtils/ci.yml?branch=main :target: https://github.com/yourusername/PyraUtils/actions
PyraUtils 是一个功能丰富的 Python 工具类库,提供了日志、HTTP请求、文件操作、数据库、JWT认证、企业微信API等常用功能的封装。
特性
- 📝 日志模块 - 基于 loguru 和 logging 的统一日志处理,支持日志级别管理、上下文日志、日志文件轮转
- 🌐 HTTP请求 - 封装 httpx 和 requests,支持重试、超时、代理、会话管理、文件下载
- 🔐 JWT认证 - JWT 令牌生成、验证、装饰器认证
- 📁 文件操作 - 文件压缩解压、下载、同步、哈希计算、大小格式化、类型检测
- 📝 字符串处理 - 邮箱验证、URL验证、手机号验证、敏感信息掩码、命名转换
- 🗄️ 数据库 - SQLAlchemy 和 SQLite3 封装
- 📧 邮件发送 - SMTP 邮件发送封装
- 🔒 密码处理 - 密码哈希、验证、强度测试、规则验证、密码重置令牌
- 📱 企业微信 - 企业微信 API 封装
- 🔑 签名生成 - HMAC、Hash 签名生成
- 🌍 网络工具 - IP地址、MAC地址、SSL证书处理
- ☁️ 云服务 - 支持阿里云、腾讯云、AWS、Azure 云服务,使用官方SDK,支持EC2、RDS、OSS、S3等服务
安装
核心安装
使用 pip 安装核心功能(不含云服务SDK)::
pip install PyraUtils
或使用 pipenv::
pipenv install PyraUtils
云服务SDK安装
根据需要选择安装相应的云服务SDK:
-
安装所有云服务SDK::
pip install PyraUtils[cloud]
-
仅安装阿里云SDK::
pip install PyraUtils[aliyun]
-
仅安装腾讯云SDK::
pip install PyraUtils[tencent]
-
仅安装AWS SDK::
pip install PyraUtils[aws]
-
仅安装Azure SDK::
pip install PyraUtils[azure]
快速开始
PyraUtils 提供了丰富的模块和功能,以下是一些核心模块的快速使用示例:
日志模块
.. code-block:: python
from PyraUtils.log import LoguruHandler
# 创建日志处理器
logger = LoguruHandler()
log = logger.get_logger("myapp", "app.log")
log.info("这是一条信息日志")
log.warning("这是一条警告日志")
log.error("这是一条错误日志")
HTTP 请求
.. code-block:: python
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"}
)
云服务
.. code-block:: python
from PyraUtils.service.cloud.adapter import create_client
# 创建阿里云客户端
aliyun_client = create_client(
'aliyun',
region='cn-beijing',
access_key='your-access-key',
secret_key='your-secret-key'
)
# 创建腾讯云客户端
tencent_client = create_client(
'tencent',
region='ap-beijing',
access_key='your-access-key',
secret_key='your-secret-key'
)
# 创建AWS客户端
aws_client = create_client(
'aws',
region='us-east-1',
access_key='your-access-key',
secret_key='your-secret-key'
)
# 创建Azure客户端
azure_client = create_client(
'azure',
tenant_id='your-tenant-id',
client_id='your-client-id',
client_secret='your-client-secret',
subscription_id='your-subscription-id'
)
详细文档
完整的模块文档请参考 PyraUtils 文档 <https://pyrautils.readthedocs.io/>_,包括:
- 核心模块:日志、HTTP请求、文件操作、字符串处理、密码处理、数据库操作
- 服务模块:企业微信、云服务(阿里云、腾讯云、AWS、Azure)
- API 参考:所有模块的详细API文档
开发环境
克隆仓库并安装开发依赖::
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_ 了解详情。
.. _CONTRIBUTING.rst: CONTRIBUTING.rst
许可证
本项目采用 MIT 许可证,详见 LICENSE_ 文件。
.. _LICENSE: LICENSE
更新日志
详见 ChangeLog.md_。
.. _ChangeLog.md: ChangeLog.md
联系方式
模块列表
PyraUtils.log- 日志处理 (Loguru/Logging)PyraUtils.http- HTTP请求、JWT认证、OAuth2PyraUtils.common- 文件操作、下载、压缩、时间处理、字符串PyraUtils.db- 数据库操作 (SQLAlchemy/SQLite)PyraUtils.network- 网络工具 (IP/MAC/SSL)PyraUtils.password- 密码处理、哈希验证PyraUtils.service- 第三方服务集成PyraUtils.service.work_wechat- 企业微信 APIPyraUtils.service.cloud- 云服务集成PyraUtils.service.cloud.aliyun- 阿里云服务 (ECS/RDS/OSS/DNS/SMS)PyraUtils.service.cloud.tencent- 腾讯云服务 (CVM/RDS/COS/DNS/SMS)PyraUtils.service.cloud.aws- AWS 服务 (EC2/S3)PyraUtils.service.cloud.azure- Azure 服务 (Compute/Storage)
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_ 了解详情。
.. _CONTRIBUTING.rst: CONTRIBUTING.rst
许可证
本项目采用 MIT 许可证,详见 LICENSE_ 文件。
.. _LICENSE: LICENSE
更新日志
详见 ChangeLog.md_。
.. _ChangeLog.md: ChangeLog.md
联系方式
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 pyrautils-0.9.37-py2.py3-none-any.whl.
File metadata
- Download URL: pyrautils-0.9.37-py2.py3-none-any.whl
- Upload date:
- Size: 161.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ba3258cd513ba755e67f8f507aa65c34294224e29e9b8351824bf6610e68a40
|
|
| MD5 |
45c1242b969d8281f25c79b070810481
|
|
| BLAKE2b-256 |
ebbeab78000e09acdfea6ce50003e4cd705fdbbad7e25e83a98931bd34725665
|