# pytools **Repository Path**: jinhong_king/pytools ## Basic Information - **Project Name**: pytools - **Description**: 非常实用的工具包,集成了多种功能 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-21 - **Last Updated**: 2025-10-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # pytools.pyd/pytools.so # 是个非常实用的个人工具包,在项目中导入之后即可使用,导入方法:在项目根目录下新建目录PYTOOLS,将文件放进去,然后在项目文件中使用:from PYTOOLS import pytools # 也可以直接放到项目根目录下,然后直接使用:from . import pytools # 工具包的主要功能如下: """ 1、hash(plain_password:str) -> str: 使用scrypt算法对传入的字符串进行哈希运算,结果不可逆。适用于用户密码存储 verify(plain_password:str,hashed_password:str) -> bool: 传入密码明文和哈希之后的密文,可以进行验证。适用于登录验证 2、get_uuid() -> str: 得到本机电脑主板的uuid,计算机的全球唯一标识 3、get_log() -> logging.Logger: 用法:log = hugoking.get_log() 得到日志对象,后续直接用log.info('xxx') 4、sync_mysql()/async_mysql() 同步/异步数据库连接对象 同步:with sync_mysql() as (conn,cs): cs.execute() result = cs.fetchall() with块中只需要写sql逻辑即可,封装的类自动处理上下文,自动管理commit,rollback和close 异步:async with sync_mysql() as (conn,cs): await cs.execute() result = await cs.fetchall() with块中只需要写sql逻辑即可,封装的类自动处理上下文,自动管理commit,rollback和close(异步方法要加await) 5、get_ip() -> str,str: ip,location = get_ip() 调用后返回两个参数,第一个是ip,第二个是地理位置 (如:'36.33.4.54','中国-安徽省-合肥市-蜀山区-联通') 6、random_str(length:int | None = 32) -> str: 传入参数时,返回指定长度的随机字符串。不传参默认返回32位长度随机字符串 7、alert(message:str,title:str,alert_type: Literal["warning", "error"] = "warning") windows环境下弹窗提醒,分别传入三个参数:message,title,("warning/error")。实现两种模式的弹窗,同时print输出message,且文本颜色根据警报类型自动变成黄色或者红色 """ # 本工具包适用于python3.10+环境,需要pip install以下第三方包 # requests、urllib3、cryptography、pymysql、aiomysql、DBUtils