python tools
Project description
pykit-tools
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
2. 介绍
各函数具体使用说明可以 readthedocs 或者直接查看源码注释。
2.1 装饰器decorator
handle_exception用于捕获函数异常,并在出现异常的时候返回默认值time_record函数耗时统计method_deco_cache方法缓存结果, 只能缓存json序列化的数据类型
2.2 日志log相关
MultiProcessTimedRotatingFileHandler多进程使用的LoggerHandlerLoggerFormatAdapter日志按照字典字段格式化输出
2.3 设计模式
Singleton单例类
2.4 其他工具集
cmd.exec_command执行shell命令str_tool.compute_md5根据输入的参数计算出唯一值(将参数值拼接后最后计算md5)str_tool.base64url_encode和str_tool.base64url_decodeURL安全的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用于消息的父日志记录器,一般用以下细分的loggerpykit_tools.cmd用于记录cmd.exec_command执行的命令行pykit_tools.error用于处理错误时输出,例如handle_exception中有用到
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 Distribution
pykit_tools-1.1.0.tar.gz
(20.3 kB
view details)
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 pykit_tools-1.1.0.tar.gz.
File metadata
- Download URL: pykit_tools-1.1.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef423cf0e2cb0d574355f8e64e67479c297312318a2b1f4bf9137ecc068bfe7b
|
|
| MD5 |
12302929579a53a516762529f03fad29
|
|
| BLAKE2b-256 |
e497c27ca64331a0f827ec7a1616bf8d849436e7a8484ccde087b201d0525a1d
|
File details
Details for the file pykit_tools-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pykit_tools-1.1.0-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3a47035fdb5474986bd8ca5ad90eb07e31c5fe28ca9b0be3c8310f318f5d0ec
|
|
| MD5 |
c790069b3240c2ce72e2e84da10d0a9d
|
|
| BLAKE2b-256 |
ddddfcd41d1e7be9f2322ed9f77e3e29fa740b2cf6fe0c8e7eec6a0a81368850
|