Metadata-Version: 2.4
Name: pywlf
Version: 0.0.15
Summary: Common utils for python3.
Project-URL: Homepage, https://github.com/waisaa/tools-python3-wlf
Author-email: waisaa <waisaa@qq.com>
License: MIT Licence
License-File: LICENSE
Keywords: wlfai,wlfconst,wlfcore,wlfdate,wlfemail,wlffile,wlfimg,wlflog,wlfres
Requires-Python: >=3.12
Requires-Dist: chardet
Requires-Dist: httpx>=0.28.1
Requires-Dist: openpyxl
Requires-Dist: pillow
Requires-Dist: pydantic
Requires-Dist: python-dateutil
Description-Content-Type: text/markdown

<div align="center">

# pywlf

*Common utils for python3.*

[![](https://img.shields.io/badge/pypi-latest-9cf.svg)](https://pypi.org/project/pywlf/) [![](https://img.shields.io/badge/blog-@waisaa-blue.svg)](https://blog.csdn.net/qq_42761569?type=blog) [![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/waisaa/tools-python3-wlf/tree/main/LICENSE)

</div>

pywlf 提供一系列命令式工具函数，涵盖日志、文件、日期、图片、邮件等常见开发场景。

## Utils

| 模块 | 说明 |
|:---------:|:---------:|
| log | 彩色控制台日志（log_info / log_warn / log_error / log_exception） |
| file | 文件目录操作：编码检测与转换、json/xlsx 读写、md5、目录管理等 |
| img | 图片处理：png/jpg/gif 等格式转 webp（支持动图、透明通道） |
| date | 日期时间操作：时间戳互转、日期平移、日/月/年范围计算等 |
| core | 通用方法：uid 生成、数值分段、耗时统计装饰器等 |
| const | 常量枚举：系统类型、日期格式等 |
| email | 邮件发送（EmailSender，支持附件） |
| res | API 统一返回体（ApiResponse / Result，基于 pydantic 泛型） |
| ai | 大模型调用：流式多轮对话(ai_chat)、图片理解(ai_image)，统一走 OpenAI 兼容协议 |

## Installation

```bash
pip install pywlf
# 或使用 uv
uv add pywlf
```

## Quickuse

```python
# 彩色日志
from pywlf.log import log_info, log_warn
log_info('this is a test!')


# 图片转 webp（转换成功后删除源文件）
from pywlf.img import to_webp
to_webp('D:/pics/logo.png')        # 单文件
to_webp('D:/pics', quality=90)     # 递归处理整个目录（含子目录）


# 统一返回体
from pywlf.res import Result
return Result.success({'id': 1})


# 大模型调用（以小米 MiMo 为例，多模态统一走 chat/completions）
from pywlf.ai import OpenAICompatClient, ChatSession
client = OpenAICompatClient(base_url='https://api.xiaomimimo.com/v1', api_key='xxx', model='mimo-v2.5')
# 图片理解
print(client.ai_image('D:/pics/a.png', '图里是什么'))            
# 流式多轮对话
session = ChatSession(client, system='你是助手', max_turns=20, auto_date=True)
session.chat('介绍下你自己')
```

## Development

本项目使用 [uv](https://docs.astral.sh/uv/) 管理依赖与打包：

```bash
uv sync          # 安装依赖（自动创建 .venv）
uv run mt.py     # 在项目环境中运行脚本
bash upload.sh   # 一键发布 PyPI：版本号+1 → uv build → uv publish
```

更多常用命令见 [wlf.sh](wlf.sh)（命令速查手册）。
