Skip to main content

python tools

Project description

pykit-tools

PyPI - Version GitHub Actions Workflow Status GitHub Actions Workflow Status Coveralls PyPI - Wheel PyPI - Python Version PyPI - Implementation GitHub License Read the Docs

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 多进程使用的LoggerHandler
  • LoggerFormatAdapter 日志按照字典字段格式化输出

2.3 设计模式

  • Singleton 单例类

2.4 其他工具集

  • cmd.exec_command 执行shell命令
  • str_tool.compute_md5 根据输入的参数计算出唯一值(将参数值拼接后最后计算md5)
  • str_tool.base64url_encodestr_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中有用到

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

pykit_tools-1.2.5.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

pykit_tools-1.2.5-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file pykit_tools-1.2.5.tar.gz.

File metadata

  • Download URL: pykit_tools-1.2.5.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for pykit_tools-1.2.5.tar.gz
Algorithm Hash digest
SHA256 fd359c204fd41080bb16b842eeba73ef97109822bb1262965418ea8a2c0d1bf5
MD5 69bc6501babf2efc5d99d2e48dcd8ad6
BLAKE2b-256 1b536de391cd92a25676edb0b7ba2ccca2af6bb88f14143a4fb6cb40d2de4024

See more details on using hashes here.

File details

Details for the file pykit_tools-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: pykit_tools-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for pykit_tools-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 19d76bd79836403cf00bf35f600418da3640130d0a109c2d8a2230cbec248a93
MD5 5b7f3eae566a90353c3ed02f8e495425
BLAKE2b-256 4b514744a3c3c7ef681f1ed7e3cb8f1f3143b4d164b43f3a2d6a75f1a36198f8

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