# pykit-tools
[![PyPI - Version](https://img.shields.io/pypi/v/pykit-tools)](https://github.com/SkylerHu/pykit-tools)
[![GitHub Actions Workflow Status](https://github.com/SkylerHu/pykit-tools/actions/workflows/pre-commit.yml/badge.svg?branch=master)](https://github.com/SkylerHu/pykit-tools)
[![GitHub Actions Workflow Status](https://github.com/SkylerHu/pykit-tools/actions/workflows/test-py3.yml/badge.svg?branch=master)](https://github.com/SkylerHu/pykit-tools)
[![Coveralls](https://img.shields.io/coverallsCoverage/github/SkylerHu/pykit-tools?branch=master)](https://github.com/SkylerHu/pykit-tools)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/pykit-tools)](https://github.com/SkylerHu/pykit-tools)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pykit-tools)](https://github.com/SkylerHu/pykit-tools)
[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pykit-tools)](https://github.com/SkylerHu/pykit-tools)
[![GitHub License](https://img.shields.io/github/license/SkylerHu/pykit-tools)](https://github.com/SkylerHu/pykit-tools)
[![Read the Docs](https://img.shields.io/readthedocs/pykit-tools)](https://pykit-tools.readthedocs.io)
Some methods and decorators commonly used in Python development are encapsulated into lib for easy access and use by other projects.
Python开发经常用的一些方法和装饰器,封装成lib方便其他项目接入使用。
## 1. 安装
pip install pykit-tools
可查看版本变更记录 [ChangeLog](https://github.com/SkylerHu/pykit-tools/blob/master/docs/CHANGELOG-1.x.md)
## 2. 介绍
各函数具体使用说明可以 [readthedocs](https://pykit-tools.readthedocs.io) 或者直接查看源码注释。
### 2.1 装饰器decorator
- `handle_exception` 用于捕获函数异常,并在出现异常的时候返回默认值
- `time_record` 函数耗时统计
- `method_deco_cache` 方法缓存结果, 只能缓存json序列化的数据类型
### 2.2 日志log相关
- `MultiProcessTimedRotatingFileHandler` 多进程使用的LoggerHandler
- `LoggerFormatAdapter` 日志按照字典字段格式化输出
### 2.3 设计模式
- `Singleton` 单例类
### 2.4 其他工具集
- `cmd.exec_command` 执行shell命令
- `str_tool.compute_md5` 根据输入的参数计算出唯一值(将参数值拼接后最后计算md5)
- `str_tool.base64url_encode` 和 `str_tool.base64url_decode` URL安全的Base64编码
## 3. 配置
### 3.1 运行配置
可以通过指定环境变量`PY_SETTINGS_MODULE`加载配置文件:
export PY_SETTINGS_MODULE=${your_project.settings_file.py}
支持的配置项有:
| 配置项 | 类型 | 说明 | 默认值 |
| - | - | - | - |
| DEBUG | bool | 是否debug开发模式 | False |
| APP_CACHE_REDIS | dict | 用于缓存的redis配置,eg: `{'host': '127.0.0.1', 'port': 6379, 'db': 0, 'socket_timeout': 10}` | None |
### 3.2 日志配置
提供以下几种loggers:
- `pykit_tools` 用于消息的父日志记录器,一般用以下细分的logger
- `pykit_tools.cmd` 用于记录`cmd.exec_command`执行的命令行
- `pykit_tools.error` 用于处理错误时输出,例如`handle_exception`中有用到
Raw data
{
"_id": null,
"home_page": "https://github.com/SkylerHu/pykit-tools.git",
"name": "pykit-tools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "python, tools, utils, py-tools, pykit-tools, py-toolkit, py-utils",
"author": "SkylerHu",
"author_email": "skylerhu@qq.com",
"download_url": "https://files.pythonhosted.org/packages/c7/6f/139f49905007b89bce12af7e4d2af3aa962b0c937af27420874c0bbae173/pykit_tools-1.0.1.tar.gz",
"platform": "any",
"description": "# pykit-tools\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pykit-tools)](https://github.com/SkylerHu/pykit-tools)\n[![GitHub Actions Workflow Status](https://github.com/SkylerHu/pykit-tools/actions/workflows/pre-commit.yml/badge.svg?branch=master)](https://github.com/SkylerHu/pykit-tools)\n[![GitHub Actions Workflow Status](https://github.com/SkylerHu/pykit-tools/actions/workflows/test-py3.yml/badge.svg?branch=master)](https://github.com/SkylerHu/pykit-tools)\n[![Coveralls](https://img.shields.io/coverallsCoverage/github/SkylerHu/pykit-tools?branch=master)](https://github.com/SkylerHu/pykit-tools)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/pykit-tools)](https://github.com/SkylerHu/pykit-tools)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pykit-tools)](https://github.com/SkylerHu/pykit-tools)\n[![PyPI - Implementation](https://img.shields.io/pypi/implementation/pykit-tools)](https://github.com/SkylerHu/pykit-tools)\n[![GitHub License](https://img.shields.io/github/license/SkylerHu/pykit-tools)](https://github.com/SkylerHu/pykit-tools)\n[![Read the Docs](https://img.shields.io/readthedocs/pykit-tools)](https://pykit-tools.readthedocs.io)\n\n\nSome methods and decorators commonly used in Python development are encapsulated into lib for easy access and use by other projects.\n\nPython\u5f00\u53d1\u7ecf\u5e38\u7528\u7684\u4e00\u4e9b\u65b9\u6cd5\u548c\u88c5\u9970\u5668\uff0c\u5c01\u88c5\u6210lib\u65b9\u4fbf\u5176\u4ed6\u9879\u76ee\u63a5\u5165\u4f7f\u7528\u3002\n\n## 1. \u5b89\u88c5\n\n\tpip install pykit-tools\n\n\u53ef\u67e5\u770b\u7248\u672c\u53d8\u66f4\u8bb0\u5f55 [ChangeLog](https://github.com/SkylerHu/pykit-tools/blob/master/docs/CHANGELOG-1.x.md)\n\n## 2. \u4ecb\u7ecd\n\u5404\u51fd\u6570\u5177\u4f53\u4f7f\u7528\u8bf4\u660e\u53ef\u4ee5 [readthedocs](https://pykit-tools.readthedocs.io) \u6216\u8005\u76f4\u63a5\u67e5\u770b\u6e90\u7801\u6ce8\u91ca\u3002\n\n### 2.1 \u88c5\u9970\u5668decorator\n- `handle_exception` \u7528\u4e8e\u6355\u83b7\u51fd\u6570\u5f02\u5e38\uff0c\u5e76\u5728\u51fa\u73b0\u5f02\u5e38\u7684\u65f6\u5019\u8fd4\u56de\u9ed8\u8ba4\u503c\n- `time_record` \u51fd\u6570\u8017\u65f6\u7edf\u8ba1\n- `method_deco_cache` \u65b9\u6cd5\u7f13\u5b58\u7ed3\u679c, \u53ea\u80fd\u7f13\u5b58json\u5e8f\u5217\u5316\u7684\u6570\u636e\u7c7b\u578b\n\n### 2.2 \u65e5\u5fd7log\u76f8\u5173\n- `MultiProcessTimedRotatingFileHandler` \u591a\u8fdb\u7a0b\u4f7f\u7528\u7684LoggerHandler\n- `LoggerFormatAdapter` \u65e5\u5fd7\u6309\u7167\u5b57\u5178\u5b57\u6bb5\u683c\u5f0f\u5316\u8f93\u51fa\n\n### 2.3 \u8bbe\u8ba1\u6a21\u5f0f\n- `Singleton` \u5355\u4f8b\u7c7b\n\n### 2.4 \u5176\u4ed6\u5de5\u5177\u96c6\n- `cmd.exec_command` \u6267\u884cshell\u547d\u4ee4\n- `str_tool.compute_md5` \u6839\u636e\u8f93\u5165\u7684\u53c2\u6570\u8ba1\u7b97\u51fa\u552f\u4e00\u503c\uff08\u5c06\u53c2\u6570\u503c\u62fc\u63a5\u540e\u6700\u540e\u8ba1\u7b97md5\uff09\n- `str_tool.base64url_encode` \u548c `str_tool.base64url_decode` URL\u5b89\u5168\u7684Base64\u7f16\u7801\n\n## 3. \u914d\u7f6e\n\n### 3.1 \u8fd0\u884c\u914d\u7f6e\n\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u73af\u5883\u53d8\u91cf`PY_SETTINGS_MODULE`\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\uff1a\n\n export PY_SETTINGS_MODULE=${your_project.settings_file.py}\n\n\u652f\u6301\u7684\u914d\u7f6e\u9879\u6709\uff1a\n\n| \u914d\u7f6e\u9879 | \u7c7b\u578b | \u8bf4\u660e | \u9ed8\u8ba4\u503c |\n| - | - | - | - |\n| DEBUG | bool | \u662f\u5426debug\u5f00\u53d1\u6a21\u5f0f | False |\n| APP_CACHE_REDIS | dict | \u7528\u4e8e\u7f13\u5b58\u7684redis\u914d\u7f6e\uff0ceg: `{'host': '127.0.0.1', 'port': 6379, 'db': 0, 'socket_timeout': 10}` | None |\n\n\n### 3.2 \u65e5\u5fd7\u914d\u7f6e\n\u63d0\u4f9b\u4ee5\u4e0b\u51e0\u79cdloggers\uff1a\n- `pykit_tools` \u7528\u4e8e\u6d88\u606f\u7684\u7236\u65e5\u5fd7\u8bb0\u5f55\u5668\uff0c\u4e00\u822c\u7528\u4ee5\u4e0b\u7ec6\u5206\u7684logger\n- `pykit_tools.cmd` \u7528\u4e8e\u8bb0\u5f55`cmd.exec_command`\u6267\u884c\u7684\u547d\u4ee4\u884c\n- `pykit_tools.error` \u7528\u4e8e\u5904\u7406\u9519\u8bef\u65f6\u8f93\u51fa\uff0c\u4f8b\u5982`handle_exception`\u4e2d\u6709\u7528\u5230\n",
"bugtrack_url": null,
"license": "MIT Licence",
"summary": "python tools",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/SkylerHu/pykit-tools.git"
},
"split_keywords": [
"python",
" tools",
" utils",
" py-tools",
" pykit-tools",
" py-toolkit",
" py-utils"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "977d3a92cb90657f36de8f59152449648de670b1701ef8af6a775a577312ae58",
"md5": "815ea63ba374fae7a2ba4bbd1e0ae71c",
"sha256": "febbf32d55a416433201bf3c265b12bd5175304ebf1c3476cc42fcef36bfd169"
},
"downloads": -1,
"filename": "pykit_tools-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "815ea63ba374fae7a2ba4bbd1e0ae71c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16824,
"upload_time": "2024-06-23T14:24:37",
"upload_time_iso_8601": "2024-06-23T14:24:37.298961Z",
"url": "https://files.pythonhosted.org/packages/97/7d/3a92cb90657f36de8f59152449648de670b1701ef8af6a775a577312ae58/pykit_tools-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c76f139f49905007b89bce12af7e4d2af3aa962b0c937af27420874c0bbae173",
"md5": "9cad22bd3249b0caebc81e17507a5cc3",
"sha256": "82b234b829cf2f91509ec1352a5b4149efd19df21c15099365aad0ec0ad44b12"
},
"downloads": -1,
"filename": "pykit_tools-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "9cad22bd3249b0caebc81e17507a5cc3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 20234,
"upload_time": "2024-06-23T14:24:39",
"upload_time_iso_8601": "2024-06-23T14:24:39.309085Z",
"url": "https://files.pythonhosted.org/packages/c7/6f/139f49905007b89bce12af7e4d2af3aa962b0c937af27420874c0bbae173/pykit_tools-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-23 14:24:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SkylerHu",
"github_project": "pykit-tools",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "pykit-tools"
}