Metadata-Version: 2.4
Name: mzy_py
Version: 0.3.0
Summary: This is a simple open-source Python toolkit. It is currently in the testing phase and only implements simplified handling of a few specific pandas commands, as well as the ability to set up a basic Flask server with one click.
Author-email: MaZiYan <2011283064@qq.com>
License: MIT
Project-URL: Homepage, https://github.com/MaZiYan/mzy_py
Project-URL: Repository, https://github.com/MaZiYan/mzy_py
Project-URL: Issues, https://github.com/MaZiYan/mzy_py/issues
Keywords: mzy,du_csv,du_excel,dayin,lianjie,plus_mzy,minus_mzy
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25
Requires-Dist: numpy>=1.21
Requires-Dist: pandas<3,>=1.3
Requires-Dist: matplotlib<4,>=3.5
Requires-Dist: seaborn<0.14,>=0.11
Requires-Dist: scipy>=1.7
Requires-Dist: scikit-learn<2,>=1.0
Requires-Dist: jieba<2,>=0.42
Requires-Dist: beautifulsoup4>=4.9
Requires-Dist: flask<4,>=2.0
Requires-Dist: qrcode<8,>=7.0
Requires-Dist: Pillow<11,>=8.0
Dynamic: license-file

# mzy_py

简易 Python 工具包 | 一键化常见操作

[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/)
[![Version](https://img.shields.io/badge/version-0.3.0-green.svg)](https://github.com/MaZiYan/mzy_py)
[![License](https://img.shields.io/badge/license-MIT-orange.svg)](LICENSE)

## 简介

这是一个简单的开源 Python 工具包。目前处于测试阶段，已实现数据处理、网络请求、数据可视化、机器学习简化调用等功能，一行代码搞定常见操作。

## 安装

```bash
pip install mzy-py
```

或者从源码安装：

```bash
git clone https://github.com/MaZiYan/mzy_py.git
cd mzy_py
pip install -e .
```

## 快速开始

```python
from mzy_py import *

# 查看所有函数文档
show_docs()

# 数据处理
df = du_csv("data.csv")
df = du_excel("data.xlsx")
data = du_json("config.json")
to_json({"name": "mzy"}, "output.json")

# 数据可视化
quick_plot(df, kind="line", title="示例图表")

# 机器学习
X_train, X_test, y_train, y_test = train_test_split(X, y)
pred = knn(X_train, y_train, X_test, k=5)

# 网络相关
download_file("https://example.com/file.zip")
run_html_server(html_file="index.html")
serve_folder(folder="./public")

# 其他工具
QRcodegen_txt("https://github.com")
compress_img("input.jpg", "output.jpg", quality=60)
```

---

## 功能详解

### 📊 数据处理

| 函数 | 说明 |
|------|------|
| `du_csv(filepath)` | 读取 CSV 文件，返回 DataFrame |
| `du_excel(filepath)` | 读取 Excel 文件，返回 DataFrame |
| `du_json(filepath)` | 读取 JSON 文件，返回 dict 或 list |
| `to_json(data, filepath)` | 将数据写入 JSON 文件 |
| `lianjie(a, b)` | 按列拼接两个 DataFrame |

**示例：**

```python
from mzy_py import du_csv, du_excel, du_json, to_json

# 读取 CSV
df = du_csv("data.csv")
print(df.head())

# 读取 Excel
df = du_excel("data.xlsx")

# 读取 JSON
data = du_json("config.json")
print(data)

# 写入 JSON
to_json({"name": "mzy", "version": "0.3.0"}, "output.json")
```

---

### 🌐 网络相关

| 函数 | 说明 |
|------|------|
| `download_file(url, save_path, show_progress)` | 下载文件（支持进度条） |
| `run_html_server(html_file, port, host, ...)` | 启动 HTML 文件服务器 |
| `serve_folder(folder, port, host, ...)` | 启动文件夹托管服务器 |

**示例：**

```python
from mzy_py import download_file, run_html_server, serve_folder

# 下载文件（自动显示进度条）
path = download_file("https://example.com/file.zip")

# 下载到指定目录
path = download_file("https://example.com/file.zip", "C:/Downloads/")

# 下载到指定文件
path = download_file("url", "D:/files/custom_name.zip")

# 启动 HTML 服务器
run_html_server(html_file="index.html", port=8080)

# 允许局域网访问
run_html_server(html_file="index.html", host="0.0.0.0", port=5000)

# 托管整个文件夹
serve_folder(folder="./public", port=8080)
```

**run_html_server / serve_folder 参数：**

| 参数 | 默认值 | 说明 |
|------|--------|------|
| `html_file` / `folder` | `"index.html"` / `"."` | 文件或文件夹路径 |
| `port` | `5000` | 端口号 |
| `host` | `"127.0.0.1"` | 监听地址（`"0.0.0.0"` 允许局域网访问） |
| `auto_open_browser` | `True` | 启动后自动打开浏览器 |
| `quit_keys` | `"q"` | 按键退出（输入 q 回车退出） |
| `log_level` | `0` | 日志级别（0=静默, 1=简洁, 2=详细） |

---

### 📊 数据可视化

| 函数 | 说明 |
|------|------|
| `quick_plot(data, kind, title, ...)` | 一键生成图表 |
| `save_plot(fig, save_path, dpi)` | 保存图表到文件 |

**支持的图表类型：** `line`, `bar`, `scatter`, `hist`, `box`, `pie`, `area`

**示例：**

```python
from mzy_py import quick_plot, save_plot
import pandas as pd

# 折线图
df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [10, 20, 15, 25]})
quick_plot(df, kind="line", title="折线图示例")

# 柱状图
quick_plot([10, 20, 30, 40], kind="bar", title="柱状图")

# 散点图
quick_plot(df, kind="scatter", title="散点图")

# 保存图表
fig = quick_plot([1, 2, 3], kind="line")
save_plot(fig, "output.png", dpi=200)
```

**quick_plot 参数：**

| 参数 | 说明 |
|------|------|
| `data` | 绘图数据（DataFrame, Series, list, dict） |
| `kind` | 图表类型：`line`, `bar`, `scatter`, `hist`, `box`, `pie`, `area` |
| `title` | 图表标题 |
| `xlabel` / `ylabel` | X/Y 轴标签 |
| `figsize` | 图形尺寸，默认 `(10, 6)` |
| `save_path` | 保存路径（如指定则保存图片） |
| `show` | 是否显示图表，默认 `True` |

---

### 🤖 机器学习

| 函数 | 说明 |
|------|------|
| `train_test_split(X, y, test_size, random_state)` | 数据集分割 |
| `knn(X_train, y_train, X_test, k)` | K近邻分类 |
| `linear_regression(X_train, y_train, X_test)` | 线性回归 |
| `kmeans(X, n_clusters)` | K-Means 聚类 |
| `accuracy_score(y_true, y_pred)` | 计算准确率 |

**示例：**

```python
from mzy_py import train_test_split, knn, linear_regression, kmeans, accuracy_score

# 数据分割
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# K近邻分类
pred = knn(X_train, y_train, X_test, k=5)
acc = accuracy_score(y_test, pred)
print(f"准确率: {acc:.2%}")

# 线性回归
pred = linear_regression(X_train, y_train, X_test)

# K-Means 聚类
labels = kmeans(data, n_clusters=3)
```

---

### 🖼️ 图片处理

| 函数 | 说明 |
|------|------|
| `QRcodegen_txt(text, save_path)` | 生成二维码图片 |
| `compress_img(tar_src, res_dst, quality)` | JPEG 图片压缩 |

**示例：**

```python
from mzy_py import QRcodegen_txt, compress_img

# 生成二维码
QRcodegen_txt("https://github.com/MaZiYan")

# 压缩图片
compress_img("input.jpg", "output.jpg", quality=60)
```

---

### 🔧 常用工具

| 函数 | 说明 |
|------|------|
| `dayin(content)` | 打印内容（简化 print） |
| `plus_mzy(a, b)` | 两个数相加 |
| `minus_mzy(a, b)` | 两个数相减 |
| `print_info()` | 打印包信息 |
| `show_docs()` | 在浏览器中显示精美文档 |

**示例：**

```python
from mzy_py import dayin, plus_mzy, minus_mzy, print_info, show_docs

# 打印
dayin("Hello World!")

# 数学运算
result = plus_mzy(1, 2)    # 返回 3
result = minus_mzy(5, 3)    # 返回 2

# 打印包信息
print_info()

# 在浏览器中显示文档
show_docs()
```

---

## 版本更新

### v0.3.0 (最新)

- ✅ 重构 `run_html_server` 函数，修复 Ctrl+C 无法正常关闭的问题
- ✅ 新增 `auto_open_browser` 参数，启动后自动打开浏览器
- ✅ 新增 `quit_keys` 参数，支持按键退出
- ✅ 新增 `log_level` 参数，控制日志输出级别
- ✅ 新增命令行支持：`python -m mzy_py.server`
- ✅ 改进启动信息显示，更清晰展示服务器地址
- ✅ 新增 `du_json()` 和 `to_json()`，简化 JSON 文件读写
- ✅ 新增 `download_file()`，支持下载文件（带进度条）
- ✅ 新增 `serve_folder()`，托管整个文件夹
- ✅ 新增 `quick_plot()`，一键生成图表（支持 line/bar/scatter/hist/box/pie）
- ✅ 新增 `save_plot()`，保存图表到文件
- ✅ 新增机器学习简化函数：`train_test_split`, `knn`, `linear_regression`, `kmeans`, `accuracy_score`
- ✅ 新增 `show_docs()`，在浏览器中显示所有函数的精美文档

### v0.2.9

- 放开 numpy 版本限制，兼容 numpy 1.x 和 2.x
- 支持 Python 3.13

---

## 项目信息

- 作者：马子延 (MaZiYan)
- 邮箱：2011283064@qq.com
- GitHub：https://github.com/MaZiYan/mzy_py
- 许可证：MIT

---

## 贡献

欢迎提交 Issue 和 Pull Request！
